From 57cdc23436fd1aed8aa2be6054e9896093a7e6d6 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 11 Sep 2022 14:04:52 +0200 Subject: [PATCH] fix bad balance displayed --- assets/translations/en.json | 3 ++- assets/translations/es.json | 3 ++- assets/translations/fr.json | 3 ++- .../scenarios/migrate_cesium_identity.dart | 2 +- lib/providers/substrate_sdk.dart | 2 +- lib/providers/wallet_options.dart | 2 +- lib/screens/activity.dart | 2 +- lib/screens/myWallets/import_g1_v1.dart | 5 ++++- lib/screens/myWallets/migrate_identity.dart | 5 ++++- lib/screens/transaction_in_progress.dart | 4 +++- lib/screens/wallet_view.dart | 14 ++++++++++---- 11 files changed, 31 insertions(+), 14 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index eb1d4f3..84e6836 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -192,5 +192,6 @@ "confirmMyIdentity": "Confirm my identity", "revokeMyIdentity": "Revoke my identity", "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", - "showUdAmounts": "Show amounts in UD" + "showUdAmounts": "Show amounts in UD", + "ud": "{}UD" } \ No newline at end of file diff --git a/assets/translations/es.json b/assets/translations/es.json index a0b1076..16e8025 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -192,5 +192,6 @@ "confirmMyIdentity": "Confirm my identity", "revokeMyIdentity": "Revoke my identity", "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", - "showUdAmounts": "Show amounts in UD" + "showUdAmounts": "Show amounts in UD", + "ud": "{}UD" } \ No newline at end of file diff --git a/assets/translations/fr.json b/assets/translations/fr.json index f8ba7ee..99164e8 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -193,5 +193,6 @@ "confirmMyIdentity": "Confirmer mon identité", "revokeMyIdentity": "Révoquer mon identité", "youCannotRevokeThisIdentity": "Vous ne pouvez pas révoquer cette identité tant\nqu'elle fait partie de la toile forgerons", - "showUdAmounts": "Afficher les montants en DU" + "showUdAmounts": "Afficher les montants en DU", + "ud": "{}DU" } \ No newline at end of file diff --git a/integration_test/scenarios/migrate_cesium_identity.dart b/integration_test/scenarios/migrate_cesium_identity.dart index fc8f2cd..d091040 100644 --- a/integration_test/scenarios/migrate_cesium_identity.dart +++ b/integration_test/scenarios/migrate_cesium_identity.dart @@ -27,7 +27,7 @@ void main() async { await enterText(keyCesiumId, 'test'); await enterText(keyCesiumPassword, 'test'); await waitFor(cesiumTest1.shortAddress()); - await waitFor('100.0', exactMatch: true); + await waitFor('100.0'); await waitFor('3', exactMatch: true); isObscureText(); diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index c511989..98aabeb 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -194,7 +194,7 @@ class SubstrateSdk with ChangeNotifier { final bool isUdUnit = configBox.get('isUdUnit') ?? false; final udValue = await getUdValue(); - final double balanceRatio = isUdUnit ? round(udValue / 100, 4) : 1; + final double balanceRatio = isUdUnit ? round(udValue / 100, 6) : 1; // log.d('udValue: $udValue'); diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index a206e65..9eea572 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -616,7 +616,7 @@ Widget udUnitDisplay(double size, [Color color = Colors.black]) { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - 'DU', + 'ud'.tr(args: ['']), style: TextStyle(fontSize: isTall ? size : size * 0.9, color: color), ), diff --git a/lib/screens/activity.dart b/lib/screens/activity.dart index aed20fc..fa05a59 100644 --- a/lib/screens/activity.dart +++ b/lib/screens/activity.dart @@ -282,7 +282,7 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { if (isUdUnit) { amount = round(amount / (sub.udValue / 100)); - finalAmount = "$amount DU"; + finalAmount = 'ud'.tr(args: ['$amount ']); } else { finalAmount = '$amount $currencyName'; } diff --git a/lib/screens/myWallets/import_g1_v1.dart b/lib/screens/myWallets/import_g1_v1.dart index 052754c..ca70bc2 100644 --- a/lib/screens/myWallets/import_g1_v1.dart +++ b/lib/screens/myWallets/import_g1_v1.dart @@ -106,6 +106,9 @@ class ImportG1v1 extends StatelessWidget { validationStatus = ''; } + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + final unit = isUdUnit ? 'ud'.tr(args: ['']) : currencyName; + return Column(children: [ const SizedBox(height: 20), TextFormField( @@ -195,7 +198,7 @@ class ImportG1v1 extends StatelessWidget { ), const SizedBox(height: 20), Text( - '${balance['transferableBalance']} $currencyName', + '${balance['transferableBalance']} $unit', style: const TextStyle(fontSize: 17), ), Row( diff --git a/lib/screens/myWallets/migrate_identity.dart b/lib/screens/myWallets/migrate_identity.dart index e3dfc75..92dd423 100644 --- a/lib/screens/myWallets/migrate_identity.dart +++ b/lib/screens/myWallets/migrate_identity.dart @@ -129,6 +129,9 @@ class MigrateIdentityScreen extends StatelessWidget { .removeWhere((element) => element.address == fromAddress); // walletsList.add(WalletData(address: 'custom', name: 'custom')); + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + final unit = isUdUnit ? 'ud'.tr(args: ['']) : currencyName; + return Column(children: [ Row(children: const []), const SizedBox(height: 20), @@ -139,7 +142,7 @@ class MigrateIdentityScreen extends StatelessWidget { data: 'areYouSureMigrateIdentity'.tr(args: [ duniterIndexer.walletNameIndexer[fromAddress] ?? '???', - '${balance['transferableBalance']} $currencyName' + '${balance['transferableBalance']} $unit' ]), styleSheet: mdStyle), ), diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index 768e5c3..5547f12 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -197,7 +197,9 @@ class TransactionInProgress extends StatelessWidget { const SizedBox(height: 10), if (transType == 'pay') Text( - isUdUnit ? '$amount DU' : '$amount $currencyName', + isUdUnit + ? 'ud'.tr(args: ['$amount ']) + : '$amount $currencyName', textAlign: TextAlign.center, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w600), diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 482f16e..67a3abb 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -405,7 +405,7 @@ class WalletViewScreen extends StatelessWidget { final myWalletProvider = Provider.of(context, listen: false); - // final _sub = Provider.of(context, listen: false); + final sub = Provider.of(context, listen: false); const double shapeSize = 20; WalletData? defaultWallet = myWalletProvider.getDefaultWallet(); @@ -413,6 +413,10 @@ class WalletViewScreen extends StatelessWidget { bool canValidate = false; + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + final udValue = sub.udValue; + final double balanceRatio = isUdUnit ? round(udValue / 100, 6) : 1; + showModalBottomSheet( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.only( @@ -426,11 +430,13 @@ class WalletViewScreen extends StatelessWidget { return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { if (walletViewProvider.payAmount.text != '' && - (double.parse(walletViewProvider.payAmount.text) + 2) <= + (double.parse(walletViewProvider.payAmount.text) + + 2 / balanceRatio) <= (balanceCache[defaultWallet.address] ?? 0) && walletViewProvider.address != defaultWallet.address) { if ((balanceCache[pubkey] == 0 || balanceCache[pubkey] == null) && - double.parse(walletViewProvider.payAmount.text) < 5) { + double.parse(walletViewProvider.payAmount.text) < + 5 / balanceRatio) { canValidate = false; } else { canValidate = true; @@ -562,7 +568,7 @@ class WalletViewScreen extends StatelessWidget { decoration: InputDecoration( hintText: '0.00', suffix: Text(isUdUnit - ? 'DU' + ? 'ud'.tr(args: ['']) : currencyName), // udUnitDisplay(40), filled: true, fillColor: Colors.transparent,