From 22e7cf17b2fcbf574846c41419a237923818b08a Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 21 Apr 2024 23:02:22 +0200 Subject: [PATCH] fix: remove account creation fee check --- lib/providers/substrate_sdk.dart | 1 - lib/widgets/payment_popup.dart | 53 +++++++++++++++++++++----------- pubspec.yaml | 2 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index f359a39..a6d8026 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -516,7 +516,6 @@ class SubstrateSdk with ChangeNotifier { const currencyParametersNames = { 'ss58': 'system.ss58Prefix.words', 'minCertForMembership': 'wot.minCertForMembership.words', - 'newAccountPrice': 'account.newAccountPrice.words', 'existentialDeposit': 'balances.existentialDeposit.words', 'certPeriod': 'cert.certPeriod.words', 'certMaxByIssuer': 'cert.maxByIssuer.words', diff --git a/lib/widgets/payment_popup.dart b/lib/widgets/payment_popup.dart index 20de58a..afd96e2 100644 --- a/lib/widgets/payment_popup.dart +++ b/lib/widgets/payment_popup.dart @@ -60,6 +60,40 @@ void paymentPopup(BuildContext context, String toAddress, String? username) { ); } + bool canValidatePayment() { + final payAmount = walletViewProvider.payAmount.text; + if (payAmount.isEmpty) { + return false; + } + final walletOptions = + Provider.of(context, listen: false); + final defaultWalletBalance = + walletOptions.balanceCache[defaultWallet.address] ?? 0; + + const existentialDeposit = 2; + final double payAmountValue = double.parse(payAmount); + final double toAddressBalance = walletOptions.balanceCache[toAddress] ?? 0; + + // Prevent sending more than the balance with existential deposit + if (payAmountValue / balanceRatio > + defaultWalletBalance - existentialDeposit) { + return false; + } + + // Prevent sending to self + if (toAddress == defaultWallet.address) { + return false; + } + + // Prevent sending to an empty wallet with less than 2 (existential deposit) + if (toAddressBalance == 0 && + payAmountValue < existentialDeposit / balanceRatio) { + return false; + } + + return true; + } + myWalletProvider.readAllWallets().then((value) => myWalletProvider.listWallets .sort((a, b) => a.derivation!.compareTo(b.derivation!))); @@ -74,27 +108,10 @@ void paymentPopup(BuildContext context, String toAddress, String? username) { context: context, builder: (BuildContext context) { final sub = Provider.of(homeContext, listen: false); - final walletOptions = - Provider.of(context, listen: false); return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { - if (walletViewProvider.payAmount.text != '' && - (double.parse(walletViewProvider.payAmount.text) + - 2 / balanceRatio) <= - (walletOptions.balanceCache[defaultWallet.address] ?? 0) && - toAddress != defaultWallet.address) { - if ((walletOptions.balanceCache[toAddress] == 0 || - walletOptions.balanceCache[toAddress] == null) && - double.parse(walletViewProvider.payAmount.text) < - 5 / balanceRatio) { - canValidate = false; - } else { - canValidate = true; - } - } else { - canValidate = false; - } + canValidate = canValidatePayment(); final bool isUdUnit = configBox.get('isUdUnit') ?? false; return Padding( padding: EdgeInsets.only( diff --git a/pubspec.yaml b/pubspec.yaml index 519e61f..64f4f40 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: Pay with G1. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 0.1.6+73 +version: 0.1.6+74 environment: sdk: ">=2.12.0 <3.0.0"