diff --git a/assets/translations/en.json b/assets/translations/en.json index 90236ab..84e6836 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -191,5 +191,7 @@ "someoneCreatedYourIdentity": "Someone created your {} identity !", "confirmMyIdentity": "Confirm my identity", "revokeMyIdentity": "Revoke my identity", - "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web" + "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", + "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 89d9f46..16e8025 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -191,5 +191,7 @@ "someoneCreatedYourIdentity": "Someone created your {} identity !", "confirmMyIdentity": "Confirm my identity", "revokeMyIdentity": "Revoke my identity", - "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web" + "youCannotRevokeThisIdentity": "You cannot revoke this identity while\nit is member of the blacksmiths web", + "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 ed7b11e..99164e8 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -192,5 +192,7 @@ "someoneCreatedYourIdentity": "Quelqu'un a créé votre identité {} !", "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" + "youCannotRevokeThisIdentity": "Vous ne pouvez pas révoquer cette identité tant\nqu'elle fait partie de la toile forgerons", + "showUdAmounts": "Afficher les montants en DU", + "ud": "{}DU" } \ No newline at end of file diff --git a/integration_test/scenarios/cert_state.dart b/integration_test/scenarios/cert_state.dart index 67ea322..905b302 100644 --- a/integration_test/scenarios/cert_state.dart +++ b/integration_test/scenarios/cert_state.dart @@ -1,6 +1,5 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:gecko/globals.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:integration_test/integration_test.dart'; import '../utility/general_actions.dart'; @@ -33,9 +32,9 @@ void main() async { // Background pay 25 await bkPay( fromAddress: test1.address, destAddress: test5.address, amount: 25); - await waitFor('25.0 $currencyName'); + await waitFor('25.0', exactMatch: true); await spawnBlock(); - await waitFor('22.0 $currencyName'); + await waitFor('22.0', exactMatch: true); await bkCertify( fromAddress: test1.address, destAddress: test5.address, @@ -53,10 +52,10 @@ void main() async { await waitFor('4', exactMatch: true); // await bkPay( // fromAddress: test2.address, destAddress: test5.address, amount: 40); - await waitFor('21.99 $currencyName'); + await waitFor('21.99', exactMatch: true); await spawnBlock(until: 30); - await waitFor('121.99 $currencyName'); + await waitFor('121.99', exactMatch: true); await spawnBlock(until: 40); - await waitFor('221.99 $currencyName'); + await waitFor('221.99', exactMatch: true); }, timeout: testTimeout()); } diff --git a/integration_test/scenarios/gecko_complete.dart b/integration_test/scenarios/gecko_complete.dart index 07e5961..f8dd7d2 100644 --- a/integration_test/scenarios/gecko_complete.dart +++ b/integration_test/scenarios/gecko_complete.dart @@ -45,7 +45,7 @@ Future payTest2() async { await waitFor(endAddress); await tapKey(keySearchResult(addressToSearch)); await waitFor(endAddress); - await waitFor('0.0 ĞD'); + await waitFor('0.0', exactMatch: true); await tapKey(keyPay); await enterText(keyAmountField, '12.14'); await tapKey(keyConfirmPayment); diff --git a/integration_test/scenarios/migrate_cesium_identity.dart b/integration_test/scenarios/migrate_cesium_identity.dart index 554c539..d091040 100644 --- a/integration_test/scenarios/migrate_cesium_identity.dart +++ b/integration_test/scenarios/migrate_cesium_identity.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:gecko/globals.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:integration_test/integration_test.dart'; import '../utility/general_actions.dart'; @@ -28,7 +27,7 @@ void main() async { await enterText(keyCesiumId, 'test'); await enterText(keyCesiumPassword, 'test'); await waitFor(cesiumTest1.shortAddress()); - await waitFor('100.0 $currencyName'); + await waitFor('100.0'); await waitFor('3', exactMatch: true); isObscureText(); @@ -51,7 +50,7 @@ void main() async { await waitFor('3', exactMatch: true); await waitFor('Membre validé !'); - await waitFor('99.98 $currencyName'); + await waitFor('99.98', exactMatch: true); }, timeout: testTimeout()); } diff --git a/integration_test/scenarios/ud_creation_state.dart b/integration_test/scenarios/ud_creation_state.dart index 9859feb..f562dae 100644 --- a/integration_test/scenarios/ud_creation_state.dart +++ b/integration_test/scenarios/ud_creation_state.dart @@ -1,6 +1,5 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:gecko/globals.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:integration_test/integration_test.dart'; import '../utility/general_actions.dart'; @@ -20,10 +19,10 @@ void main() async { // Go to test1 options and check if balance growup with UDs creations await tapKey(keyOpenWallet(test1.address)); - await waitFor('100.0 $currencyName'); + await waitFor('100.0', exactMatch: true); await spawnBlock(until: 10); - await waitFor('200.0 $currencyName'); + await waitFor('200.0', exactMatch: true); await spawnBlock(until: 20); - await waitFor('300.0 $currencyName'); + await waitFor('300.0', exactMatch: true); }, timeout: testTimeout()); } diff --git a/integration_test/utility/general_actions.dart b/integration_test/utility/general_actions.dart index 612675a..2bf06f5 100644 --- a/integration_test/utility/general_actions.dart +++ b/integration_test/utility/general_actions.dart @@ -28,6 +28,12 @@ Future deleteAllWallets() async { if (await isPresent('Rechercher')) { await tapKey(keyDrawerMenu); await tapKey(keyParameters); + + // Check if ud unit checkbox is checked + final isUdUnit = await isIconPresent(Icons.check_box); + // If yes, tap on to use currency value + if (isUdUnit) await tapKey(keyUdUnit, duration: 0); + await tapKey(keyDeleteAllWallets); await tapKey(keyConfirm); await tester.pumpAndSettle(); @@ -142,9 +148,9 @@ Future onboardingNewChest() async { // Go to wallets home await tapKey(keyGoWalletsHome, duration: 0); - // Check if string "ĞD" is present in screen + // Check if string "Mon portefeuille co" is present in screen await waitFor('Mon portefeuille co'); - await waitFor('0.0 $currencyName'); + await waitFor('0.0', exactMatch: true); // await waitFor('Scanner un'); } @@ -159,5 +165,5 @@ Future firstOpenChest() async { final isCached = await isIconPresent(Icons.check_box); if (!isCached) await tapKey(keyCachePassword, duration: 0); await enterText(keyPinForm, 'AAAAA', 0); - await waitFor('100.0 $currencyName'); + await waitFor('100.0', exactMatch: true); } diff --git a/integration_test/utility/tests_utility.dart b/integration_test/utility/tests_utility.dart index 99b327b..65f0c7a 100644 --- a/integration_test/utility/tests_utility.dart +++ b/integration_test/utility/tests_utility.dart @@ -280,6 +280,7 @@ Future bkDeleteAllWallets() async { await walletBox.clear(); await chestBox.clear(); await configBox.delete('defaultWallet'); + await configBox.delete('isUdUnit'); await sub.deleteAllAccounts(); myWalletProvider.pinCode = ''; myWalletProvider.reload(); diff --git a/lib/models/widgets_keys.dart b/lib/models/widgets_keys.dart index 85bb691..af2ecb1 100644 --- a/lib/models/widgets_keys.dart +++ b/lib/models/widgets_keys.dart @@ -70,6 +70,7 @@ const keyDeleteAllWallets = Key('keyDeleteAllWallets'); const keySelectDuniterNodeDropDown = Key('keySelectDuniterNodeDropDown'); const keyCustomDuniterEndpoint = Key('keyCustomDuniterEndpoint'); const keyConnectToEndpoint = Key('keyConnectToEndpoint'); +const keyUdUnit = Key('keyUdUnit'); // Onboarding const keyPastMnemonic = Key('keyPastMnemonic'); diff --git a/lib/providers/duniter_indexer.dart b/lib/providers/duniter_indexer.dart index 8d6123b..0def0b8 100644 --- a/lib/providers/duniter_indexer.dart +++ b/lib/providers/duniter_indexer.dart @@ -313,9 +313,18 @@ class DuniterIndexer with ChangeNotifier { fontWeight: FontWeight.w500), textAlign: TextAlign.center), ]), - trailing: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [balance(context, profile['id'], 16)]), + trailing: SizedBox( + width: 110, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + balance(context, profile['id'], 16), + ]), + ]), + ), subtitle: Row(children: [ Text(profile['name'] ?? '', style: const TextStyle( @@ -360,16 +369,16 @@ class DuniterIndexer with ChangeNotifier { transBC[i] = []; transBC[i].add(DateTime.parse(transaction['created_at'])); final int amountBrut = transaction['amount']; - final num amount = removeDecimalZero(amountBrut / 100); + final double amount = removeDecimalZero(amountBrut / 100); if (direction == "RECEIVED") { transBC[i].add(transaction['issuer_id']); transBC[i].add(transaction['issuer']['identity']?['name'] ?? ''); - transBC[i].add(amount.toString()); } else if (direction == "SENT") { transBC[i].add(transaction['receiver_id']); transBC[i].add(transaction['receiver']['identity']?['name'] ?? ''); - transBC[i].add('- $amount'); } + transBC[i].add(amount); + transBC[i].add(direction); // transBC[i].add(''); //transaction comment i++; @@ -429,9 +438,9 @@ class DuniterIndexer with ChangeNotifier { return opts; } - num removeDecimalZero(double n) { + double removeDecimalZero(double n) { String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); - return num.parse(result); + return double.parse(result); } // checkHistoryResult( diff --git a/lib/providers/home.dart b/lib/providers/home.dart index 9ff8cff..4fadc5a 100644 --- a/lib/providers/home.dart +++ b/lib/providers/home.dart @@ -13,6 +13,7 @@ import 'package:gecko/globals.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:gecko/providers/my_wallets.dart'; +import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:gecko/screens/myWallets/wallets_home.dart'; @@ -63,6 +64,13 @@ class HomeProvider with ChangeNotifier { } } + Future changeCurrencyUnit() async { + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + await configBox.put('isUdUnit', !isUdUnit); + balanceCache = {}; + notifyListeners(); + } + Future getAppVersion() async { String version; String buildNumber; diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 3b3f6ec..98aabeb 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -41,6 +41,7 @@ class SubstrateSdk with ChangeNotifier { String g1V1NewAddress = ''; bool isCesiumIDVisible = false; bool isCesiumAddresLoading = false; + late int udValue; ///////////////////////////////////// ////////// 1: API METHODS /////////// @@ -154,20 +155,10 @@ class SubstrateSdk with ChangeNotifier { return consumers == 0 ? false : true; } - // Future getBalance(String address) async { - // double balance = 0.0; - - // if (nodeConnected) { - // final brutBalance = await sdk.api.account.queryBalance(address); - // // log.d(brutBalance?.toJson()); - // balance = int.parse(brutBalance!.freeBalance) / 100; - // } else { - // balance = -1; - // } - - // await getUnclaimedUd(address); - // return balance; - // } + Future getUdValue() async { + udValue = int.parse(await _getStorage('universalDividend.currentUd()')); + return udValue; + } Future> getBalance(String address) async { // log.d('currencyParameters: $currencyParameters'); @@ -201,11 +192,18 @@ class SubstrateSdk with ChangeNotifier { final int transferableBalance = (balanceGlobal['data']['free'] + unclaimedUds); + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + final udValue = await getUdValue(); + final double balanceRatio = isUdUnit ? round(udValue / 100, 6) : 1; + + // log.d('udValue: $udValue'); + Map finalBalances = { - 'transferableBalance': transferableBalance / 100, - 'free': balanceGlobal['data']['free'] / 100, - 'unclaimedUds': unclaimedUds / 100, - 'reserved': balanceGlobal['data']['reserved'] / 100, + 'transferableBalance': round((transferableBalance / balanceRatio) / 100), + 'free': round((balanceGlobal['data']['free'] / balanceRatio) / 100), + 'unclaimedUds': round((unclaimedUds / balanceRatio) / 100), + 'reserved': + round((balanceGlobal['data']['reserved'] / balanceRatio) / 100), }; // log.i(finalBalances); @@ -701,11 +699,30 @@ class SubstrateSdk with ChangeNotifier { TxInfoData txInfo; List txOptions = []; String? rawParams; + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + late String palette; + late String call; + late String tx2; + + if (amount == -1) { + palette = 'balances'; + call = 'transferAll'; + txOptions = [destAddress, false]; + tx2 = 'api.tx.balances.transferAll("$destAddress", false)'; + } else { + if (isUdUnit) { + palette = 'universalDividend'; + call = 'transferUd'; + } else { + palette = 'balances'; + call = 'transferKeepAlive'; + } + txOptions = [destAddress, amountUnit]; + tx2 = 'api.tx.$palette.$call("$destAddress", $amountUnit)'; + } if (globalBalance['unclaimedUds'] == 0) { - txInfo = TxInfoData('balances', - amount == -1 ? 'transferAll' : 'transferKeepAlive', sender); - txOptions = [destAddress, amount == -1 ? false : amountUnit]; + txInfo = TxInfoData(palette, call, sender); } else { txInfo = TxInfoData( 'utility', @@ -713,14 +730,9 @@ class SubstrateSdk with ChangeNotifier { sender, ); const tx1 = 'api.tx.universalDividend.claimUds()'; - final tx2 = amount == -1 - ? 'api.tx.balances.transferAll("$destAddress", false)' - : 'api.tx.balances.transferKeepAlive("$destAddress", $amountUnit)'; - rawParams = '[[$tx1, $tx2]]'; } - // log.d('pay args: ${txInfo.module}, ${txInfo.call}, $txOptions, $rawParams'); return await _executeCall(txInfo, txOptions, password, rawParams); } @@ -1013,3 +1025,7 @@ class PasswordException implements Exception { Uint8List _int32bytes(int value) => Uint8List(4)..buffer.asInt32List()[0] = value; + +double round(double number, [int decimal = 2]) { + return double.parse((number.toStringAsFixed(decimal))); +} diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index 817b370..9eea572 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -541,10 +541,13 @@ Widget balance(BuildContext context, String address, double size, globalBalance.hasError) { if (balanceCache[address] != null && balanceCache[address] != -1) { - return Text( - "${balanceCache[address]!.toString()} $currencyName", - style: TextStyle( - fontSize: isTall ? size : size * 0.9, color: color)); + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); } else { return SizedBox( height: 15, @@ -558,13 +561,17 @@ Widget balance(BuildContext context, String address, double size, } balanceCache[address] = globalBalance.data!['transferableBalance']!; if (balanceCache[address] != -1) { - return Text( - "${balanceCache[address]!.toString()} $currencyName", - style: TextStyle( - fontSize: isTall ? size : size * 0.9, - color: color, + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), ), - ); + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); } else { return const Text(''); } @@ -601,3 +608,32 @@ Widget getCerts(BuildContext context, String address, double size, }), ]); } + +Widget udUnitDisplay(double size, [Color color = Colors.black]) { + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + return isUdUnit + ? Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + 'ud'.tr(args: ['']), + style: + TextStyle(fontSize: isTall ? size : size * 0.9, color: color), + ), + Column( + children: [ + Text( + currencyName, + style: TextStyle( + fontSize: (isTall ? size : size * 0.9) * 0.7, + fontWeight: FontWeight.w500, + color: color), + ), + const SizedBox(height: 15) + ], + ) + ], + ) + : Text(currencyName, + style: TextStyle(fontSize: isTall ? size : size * 0.9, color: color)); +} diff --git a/lib/screens/activity.dart b/lib/screens/activity.dart index 2be757d..fa05a59 100644 --- a/lib/screens/activity.dart +++ b/lib/screens/activity.dart @@ -195,6 +195,8 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { BuildContext context, DuniterIndexer duniterIndexer) { CesiumPlusProvider cesiumPlusProvider = Provider.of(context, listen: false); + SubstrateSdk sub = Provider.of(context, listen: false); + int keyID = 0; String? dateDelimiter; String? lastDateDelimiter; @@ -273,6 +275,18 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { dateDelimiter = null; } + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + late double amount; + late String finalAmount; + amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1; + + if (isUdUnit) { + amount = round(amount / (sub.udValue / 100)); + finalAmount = 'ud'.tr(args: ['$amount ']); + } else { + finalAmount = '$amount $currencyName'; + } + return Column(children: [ if (dateDelimiter != null) Padding( @@ -328,7 +342,7 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier { ], ), ), - trailing: Text("${repository[3]} $currencyName", + trailing: Text(finalAmount, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w500), textAlign: TextAlign.justify), diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 2803626..9bd8638 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -31,8 +31,8 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); homeContext = context; + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); MyWalletsProvider myWalletProvider = Provider.of(context); Provider.of(context); diff --git a/lib/screens/myWallets/choose_wallet.dart b/lib/screens/myWallets/choose_wallet.dart index bc489e6..0e26d01 100644 --- a/lib/screens/myWallets/choose_wallet.dart +++ b/lib/screens/myWallets/choose_wallet.dart @@ -218,7 +218,7 @@ class ChooseWalletScreen extends StatelessWidget { width: double.infinity, color: isDefault ? orangeC : yellowC, child: SizedBox( - height: 25, + height: 30, child: Column(children: [ const Spacer(), // Text( @@ -226,7 +226,10 @@ class ChooseWalletScreen extends StatelessWidget { // textAlign: TextAlign.center, // style: TextStyle(color: isDefault ? Colors.white : Colors.black), // ), - balance(context, address, 15, isDefault ? Colors.white : Colors.black) + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + balance( + context, address, 16, isDefault ? Colors.white : Colors.black), + ]) ]), ), ); 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/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 2cb0d0a..c799a65 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -293,12 +293,17 @@ class WalletsHome extends StatelessWidget { color: isDefault ? orangeC : yellowC, child: Padding( padding: const EdgeInsets.only(left: 5, right: 5, top: 38), - child: balance( - context, - address, - 15, - isDefault ? Colors.white : Colors.black, - isDefault ? yellowC : orangeC)), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + balance( + context, + address, + 15, + isDefault ? Colors.white : Colors.black, + isDefault ? yellowC : orangeC) + ], + )), ); } diff --git a/lib/screens/my_contacts.dart b/lib/screens/my_contacts.dart index 3307e35..2f78986 100644 --- a/lib/screens/my_contacts.dart +++ b/lib/screens/my_contacts.dart @@ -87,7 +87,21 @@ class ContactsScreen extends StatelessWidget { trailing: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - balance(context, g1Wallet.pubkey!, 16) + SizedBox( + width: 110, + child: Row( + mainAxisAlignment: + MainAxisAlignment.end, + children: [ + Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + balance(context, + g1Wallet.pubkey!, 16), + ]), + ]), + ), ]), subtitle: Row(children: [ duniterIndexer.getNameByAddress( diff --git a/lib/screens/search_result.dart b/lib/screens/search_result.dart index c1ca7f0..d4416d9 100644 --- a/lib/screens/search_result.dart +++ b/lib/screens/search_result.dart @@ -48,7 +48,7 @@ class SearchResultScreen extends StatelessWidget { body: SafeArea( child: Stack(children: [ Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), + padding: const EdgeInsets.only(left: 15, right: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -111,8 +111,24 @@ class SearchResultScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ - balance( - context, g1Wallet.pubkey!, 16) + SizedBox( + width: 110, + child: Row( + mainAxisAlignment: + MainAxisAlignment.end, + children: [ + Column( + mainAxisAlignment: + MainAxisAlignment + .center, + children: [ + balance( + context, + g1Wallet.pubkey!, + 16), + ]), + ]), + ), ]), subtitle: Row(children: [ duniterIndexer.getNameByAddress( diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index e4931c0..4ce6de2 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:gecko/models/widgets_keys.dart'; import 'package:gecko/providers/duniter_indexer.dart'; +import 'package:gecko/providers/home.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/settings_provider.dart'; import 'package:gecko/providers/substrate_sdk.dart'; @@ -33,9 +34,21 @@ class SettingsScreen extends StatelessWidget { )), body: Column(children: [ const SizedBox(height: 30), + Text( + 'Connectivité réseau', + style: TextStyle(color: Colors.grey[500], fontSize: 22), + ), + const SizedBox(height: 20), duniterEndpointSelection(context), - const SizedBox(height: 50), + const SizedBox(height: 30), indexerEndpointSelection(context), + const SizedBox(height: 40), + Text( + 'Affichage', + style: TextStyle(color: Colors.grey[500], fontSize: 22), + ), + const SizedBox(height: 20), + chooseCurrencyUnit(context), // SizedBox(height: isTall ? 80 : 120), const Spacer(), @@ -66,6 +79,36 @@ class SettingsScreen extends StatelessWidget { ); } + Widget chooseCurrencyUnit(BuildContext context) { + HomeProvider homeProvider = + Provider.of(context, listen: false); + return InkWell( + key: keyUdUnit, + onTap: () async { + await homeProvider.changeCurrencyUnit(); + }, + child: SizedBox( + height: 50, + child: Row( + children: [ + const SizedBox(width: 12), + Text('showUdAmounts'.tr()), + const Spacer(), + Consumer(builder: (context, homeProvider, _) { + final bool isUdUnit = configBox.get('isUdUnit') ?? false; + return Icon( + isUdUnit ? Icons.check_box : Icons.check_box_outline_blank, + color: orangeC, + size: 32, + ); + }), + const SizedBox(width: 30), + ], + ), + ), + ); + } + Widget duniterEndpointSelection(BuildContext context) { SubstrateSdk sub = Provider.of(context, listen: false); String? selectedDuniterEndpoint; diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index 88d10e2..5547f12 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -41,6 +41,7 @@ class TransactionInProgress extends StatelessWidget { final to = toAddress ?? getShortPubkey(walletViewProvider.address!); final amount = walletViewProvider.payAmount.text; String actionName = ''; + final bool isUdUnit = configBox.get('isUdUnit') ?? false; switch (transType) { case 'pay': @@ -196,7 +197,9 @@ class TransactionInProgress extends StatelessWidget { const SizedBox(height: 10), if (transType == 'pay') Text( - '$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 e116a12..67a3abb 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -403,9 +403,9 @@ class WalletViewScreen extends StatelessWidget { // WalletsProfilesProvider _walletViewProvider = // Provider.of(context, listen: false); - MyWalletsProvider myWalletProvider = + final myWalletProvider = Provider.of(context, listen: false); - // SubstrateSdk _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; @@ -438,6 +444,7 @@ class WalletViewScreen extends StatelessWidget { } else { canValidate = false; } + final bool isUdUnit = configBox.get('isUdUnit') ?? false; return Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom), @@ -524,44 +531,7 @@ class WalletViewScreen extends StatelessWidget { child: Row(children: [ Text(defaultWallet.name!), const Spacer(), - FutureBuilder( - future: - sub.getBalance(defaultWallet.address!), - builder: (BuildContext context, - AsyncSnapshot> - globalBalance) { - if (globalBalance.connectionState != - ConnectionState.done || - globalBalance.hasError) { - if (balanceCache[ - defaultWallet.address!] != - null) { - return Text( - "${balanceCache[defaultWallet.address!]} $currencyName", - style: const TextStyle( - fontSize: 20, - )); - } else { - return SizedBox( - height: 15, - width: 15, - child: CircularProgressIndicator( - color: orangeC, - strokeWidth: 2, - ), - ); - } - } - balanceCache[defaultWallet.address!] = - globalBalance - .data!['transferableBalance']!; - return Text( - "${balanceCache[defaultWallet.address!]} $currencyName", - style: const TextStyle( - fontSize: 20, - ), - ); - }), + balance(context, defaultWallet.address!, 20) ]), ), ); @@ -597,7 +567,9 @@ class WalletViewScreen extends StatelessWidget { // onChanged: (v) => _searchProvider.reload(), decoration: InputDecoration( hintText: '0.00', - suffix: Text(currencyName), + suffix: Text(isUdUnit + ? 'ud'.tr(args: ['']) + : currencyName), // udUnitDisplay(40), filled: true, fillColor: Colors.transparent, // border: OutlineInputBorder(