Skip to content

Commit

Permalink
Allow custom fee
Browse files Browse the repository at this point in the history
  • Loading branch information
hhanh00 committed Aug 5, 2023
1 parent d338584 commit 95aec7b
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 59 deletions.
7 changes: 7 additions & 0 deletions idl/data.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,10 @@ table TxReport {
fee:uint64;
privacy_level:uint8;
}

table Fee {
fee:uint64;
min_fee:uint64;
max_fee:uint64;
scheme:uint8;
}
1 change: 0 additions & 1 deletion lib/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class AccountList {
(a) => Account(coin.coin, a.id, a.name!, a.keyType, a.balance, 0))
.toList();
final id = WarpApi.getActiveAccountId(coin.coin);
print("active $id");
if (id != 0) {
accounts.firstWhere((a) => a.id == id).active = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ContactsState extends State<ContactsTab> {

_onCommit() async {
try {
final txPlan = WarpApi.commitUnsavedContacts(settings.anchorOffset);
final txPlan = WarpApi.commitUnsavedContacts(settings.anchorOffset, settings.feeRule);
Navigator.of(context).pushNamed('/txplan', arguments: txPlan);
} on String catch (msg) {
showSnackBar(msg, error: true);
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class MessageLookup extends MessageLookupByLibrary {
"error": m7,
"excludedNotes": MessageLookupByLibrary.simpleMessage("Excluded Notes"),
"expert": MessageLookupByLibrary.simpleMessage("Expert"),
"fee": MessageLookupByLibrary.simpleMessage("Fee"),
"fileSaved": MessageLookupByLibrary.simpleMessage("File saved"),
"fromPool": MessageLookupByLibrary.simpleMessage("From Pool"),
"fromto": MessageLookupByLibrary.simpleMessage("From/To"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class MessageLookup extends MessageLookupByLibrary {
"excludedNotes":
MessageLookupByLibrary.simpleMessage("Notas excluidas"),
"expert": MessageLookupByLibrary.simpleMessage("Modo Experto"),
"fee": MessageLookupByLibrary.simpleMessage("Fee"),
"fileSaved": MessageLookupByLibrary.simpleMessage("Archivo guardado"),
"fromPool": MessageLookupByLibrary.simpleMessage("Del Suministro"),
"fromto": MessageLookupByLibrary.simpleMessage("Rem/Dest."),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class MessageLookup extends MessageLookupByLibrary {
"error": m7,
"excludedNotes": MessageLookupByLibrary.simpleMessage("Billets exclus"),
"expert": MessageLookupByLibrary.simpleMessage("Expert"),
"fee": MessageLookupByLibrary.simpleMessage("Fee"),
"fileSaved": MessageLookupByLibrary.simpleMessage("File saved"),
"fromPool": MessageLookupByLibrary.simpleMessage("A partir du Fond"),
"fromto": MessageLookupByLibrary.simpleMessage("Env/Dest."),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 45 additions & 27 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,43 +364,61 @@ class HomeInnerState extends State<HomeInnerPage>
if (!WarpApi.isValidTransparentKey(k)) return s.invalidKey;
return null;
};
final formKey = GlobalKey<FormBuilderState>();
final confirmed = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text(s.sweep),
content: SingleChildScrollView(
child: FormBuilder(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
decoration: InputDecoration(labelText: s.transparentKey),
controller: keyController,
validator: checkKey,
mainAxisSize: MainAxisSize.min,
children: [
FormBuilderTextField(
name: 'key',
decoration:
InputDecoration(labelText: s.transparentKey),
controller: keyController,
validator: checkKey,
),
FormBuilderRadioGroup<int>(
orientation: OptionsOrientation.horizontal,
decoration: InputDecoration(labelText: s.toPool),
name: 'pool',
initialValue: 0,
onChanged: (v) {
pool = v ?? 0;
},
options: [
FormBuilderFieldOption(
child: Text('T'), value: 0),
FormBuilderFieldOption(
child: Text('S'), value: 1),
if (active.coinDef.supportsUA)
FormBuilderFieldOption(
child: Text('O'), value: 2),
]),
],
),
FormBuilderRadioGroup<int>(
orientation: OptionsOrientation.horizontal,
decoration: InputDecoration(labelText: s.toPool),
name: 'pool',
initialValue: 0,
onChanged: (v) {
pool = v ?? 0;
},
options: [
FormBuilderFieldOption(child: Text('T'), value: 0),
FormBuilderFieldOption(child: Text('S'), value: 1),
if (active.coinDef.supportsUA)
FormBuilderFieldOption(child: Text('O'), value: 2),
]),
],
)),
actions: confirmButtons(
context, () => Navigator.of(context).pop(true)))) ??
),
),
actions: confirmButtons(context, () async {
final form = formKey.currentState!;
if (form.validate()) {
try {
final txid = await WarpApi.sweepTransparent(syncStatus.latestHeight,
keyController.text, pool, settings.anchorOffset, settings.feeRule);
showSnackBar(s.txId(txid));
Navigator.of(context).pop(true);
} on String catch (msg) {
form.fields['key']!.invalidate(msg);
}
}
}))) ??
false;
if (confirmed) {
final txid = await WarpApi.sweepTransparent(syncStatus.latestHeight,
keyController.text, pool, settings.anchorOffset);
showSnackBar(s.txId(txid));
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,6 @@
"scanningAddresses": "Scanning addresses",
"blockExplorer": "Block Explorer",
"tapQrCodeForSaplingAddress": "Tap QR Code for Sapling Address",
"playSound": "Play Sound"
"playSound": "Play Sound",
"fee": "Fee"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,6 @@
"scanningAddresses": "Scanning addresses",
"blockExplorer": "Block Explorer",
"tapQrCodeForSaplingAddress": "Tap QR Code for Sapling Address",
"playSound": "Sonido"
"playSound": "Sonido",
"fee": "Fee"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,6 @@
"scanningAddresses": "Scanning addresses",
"blockExplorer": "Block Explorer",
"tapQrCodeForSaplingAddress": "Tap QR Code for Sapling Address",
"playSound": "Effets Sonores"
"playSound": "Effets Sonores",
"fee": "Fee"
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ Future<bool> authenticate(BuildContext context, String reason) async {
Future<void> shieldTAddr(BuildContext context) async {
try {
final txPlan = WarpApi.shieldTAddr(
active.coin, active.id, active.tbalance, settings.anchorOffset);
active.coin, active.id, active.tbalance, settings.anchorOffset, settings.feeRule);
Navigator.of(context).pushNamed('/txplan', arguments: txPlan);
} on String catch (msg) {
showSnackBar(msg, error: true);
Expand Down
3 changes: 2 additions & 1 deletion lib/pools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class PoolsState extends State<PoolsPage> {
includeFee,
_memoController.text,
stringToAmount(_maxAmountController.text),
settings.anchorOffset);
settings.anchorOffset,
settings.feeRule);
Navigator.of(context)
.pushReplacementNamed('/txplan', arguments: txPlan);
} on String catch (message) {
Expand Down
2 changes: 1 addition & 1 deletion lib/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ Future<void> send(BuildContext context, List<Recipient> recipients) async {
if (recipients.length == 1) active.setDraftRecipient(recipients[0]);
try {
final txPlan = await WarpApi.prepareTx(
active.coin, active.id, recipients, settings.anchorOffset);
active.coin, active.id, recipients, settings.anchorOffset, settings.feeRule);
Navigator.pushReplacementNamed(context, '/txplan', arguments: txPlan);
} on String catch (message) {
showSnackBar(message);
Expand Down
14 changes: 14 additions & 0 deletions lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsState extends State<SettingsPage>
with SingleTickerProviderStateMixin {
var _anchorController =
TextEditingController(text: "${settings.anchorOffset}");
var _feeController = TextEditingController(text: amountToString(settings.fee, MAX_PRECISION));
var _memoController = TextEditingController();
var _currency = settings.currency;
var _needAuth = false;
Expand Down Expand Up @@ -152,6 +153,15 @@ class SettingsState extends State<SettingsPage>
},
onSaved: _onProtectOpen)),
]),
if (!simpleMode)
FormBuilderTextField(
decoration: InputDecoration(
labelText: s.fee),
name: 'fee',
keyboardType: TextInputType.number,
controller: _feeController,
inputFormatters: [makeInputFormatter(false)],
onSaved: _onFee),
if (!simpleMode)
FormBuilderCheckbox(
name: 'use_millis',
Expand Down Expand Up @@ -441,6 +451,10 @@ class SettingsState extends State<SettingsPage>
settings.updateGetTx(v);
}

_onFee(v) {
settings.setFee(stringToAmount(v));
}

_onUseMillis(v) {
settings.setUseMillis(v);
}
Expand Down
17 changes: 17 additions & 0 deletions lib/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ abstract class _Settings with Store {
@observable
bool sound = true;

@observable
int fee = 1000;

String dbPasswd = "";

@action
Expand Down Expand Up @@ -229,6 +232,7 @@ abstract class _Settings with Store {
txView = ViewStyle.values[(prefs.getInt('tx_view') ?? 0)];
qrOffline = prefs.getBool('qr_offline') ?? true;
sound = prefs.getBool('sound') ?? true;
fee = prefs.getInt('fee') ?? 10000;

primaryColorValue = prefs.getInt('primary') ?? Colors.blue.value;
primaryVariantColorValue =
Expand Down Expand Up @@ -594,7 +598,20 @@ abstract class _Settings with Store {
prefs.setInt('min_privacy', v);
}

@action
Future<void> setFee(int v) async {
final prefs = await SharedPreferences.getInstance();
fee = v;
prefs.setInt('fee', v);
}

bool get isDeveloper => developerMode == 0;

FeeT get feeRule {
return FeeT(
fee: fee,
);
}
}

Future<double?> getFxRate(String coin, String fiat) async {
Expand Down
Loading

0 comments on commit 95aec7b

Please sign in to comment.