From d9c30d337a1e08c1ae1703d124336234fa48f752 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 26 Nov 2023 21:07:17 +0100 Subject: [PATCH] refacto: username is nullable --- integration_test/duniter/docker-compose.yml | 2 +- integration_test/scenarios/gecko_complete.dart | 11 +++++++---- lib/providers/substrate_sdk.dart | 6 +++--- lib/providers/wallet_options.dart | 1 - lib/providers/wallets_profiles.dart | 2 +- lib/screens/search.dart | 2 +- lib/screens/transaction_in_progress.dart | 14 ++++---------- lib/screens/wallet_view.dart | 2 +- lib/widgets/contacts_list.dart | 5 ++--- lib/widgets/history_view.dart | 2 +- lib/widgets/payment_popup.dart | 6 ++---- lib/widgets/search_identity_query.dart | 2 +- lib/widgets/search_result_list.dart | 2 +- lib/widgets/transaction_tile.dart | 8 +++++--- 14 files changed, 30 insertions(+), 35 deletions(-) diff --git a/integration_test/duniter/docker-compose.yml b/integration_test/duniter/docker-compose.yml index d828b23..f944c16 100644 --- a/integration_test/duniter/docker-compose.yml +++ b/integration_test/duniter/docker-compose.yml @@ -5,7 +5,7 @@ services: container_name: duniter-v2s-gecko-tests # image: duniter/duniter-v2s:debug-sha-4d5e08be image: duniter/duniter-v2s:debug-sha-44b09061 - command: --alice --sealing=manual + command: --alice --sealing=manual --force-authoring --reserved-only --no-mdns ports: - "127.0.0.1:9615:9615" - "127.0.0.1:9933:9933" diff --git a/integration_test/scenarios/gecko_complete.dart b/integration_test/scenarios/gecko_complete.dart index be9e360..0671b08 100644 --- a/integration_test/scenarios/gecko_complete.dart +++ b/integration_test/scenarios/gecko_complete.dart @@ -54,8 +54,9 @@ Future payTest2() async { spawnBlock(duration: 500); await tester.pump(const Duration(seconds: 2)); await waitFor('sending'.tr(), - reverse: true, settle: false, timeout: const Duration(seconds: 20)); - + reverse: true, timeout: const Duration(seconds: 20)); + await waitFor('extrinsicValidated'.tr(args: ['transaction'.tr()]), + timeout: const Duration(seconds: 12)); await tapKey(keyCloseTransactionScreen, duration: 0); await waitFor('12.14'); spawnBlock(duration: 500); @@ -71,7 +72,9 @@ Future certifyTest5() async { spawnBlock(duration: 1000); await pump(number: 3); await waitFor('sending'.tr(), - reverse: true, settle: false, timeout: const Duration(seconds: 20)); + reverse: true, timeout: const Duration(seconds: 20)); + await waitFor('extrinsicValidated'.tr(args: ['certification'.tr()]), + timeout: const Duration(seconds: 6)); await tapKey(keyCloseTransactionScreen); await waitFor('identityCreated'.tr()); @@ -86,7 +89,7 @@ Future certifyTest5() async { spawnBlock(duration: 1000); await pump(number: 3); await waitFor('sending'.tr(), - reverse: true, settle: false, timeout: const Duration(seconds: 20)); + reverse: true, timeout: const Duration(seconds: 20)); await tapKey(keyCloseTransactionScreen); await waitFor('identityConfirmed'.tr()); humanRead(2); diff --git a/lib/providers/substrate_sdk.dart b/lib/providers/substrate_sdk.dart index 760cce3..3d64745 100644 --- a/lib/providers/substrate_sdk.dart +++ b/lib/providers/substrate_sdk.dart @@ -52,7 +52,7 @@ class SubstrateSdk with ChangeNotifier { ///////////////////////////////////// ////////// 1: API METHODS /////////// - ///////////////////////////////////// + /////////////////////////////////////3 Future _executeCall(TxInfoData txInfo, txOptions, String password, [String? rawParams]) async { @@ -71,10 +71,10 @@ class SubstrateSdk with ChangeNotifier { ); log.d(hash); if (hash.isEmpty) { - transactionStatus = 'timeout'; + transactionStatus = 'Exception: timeout'; notifyListeners(); - return 'timeout'; + return 'Exception: timeout'; } else { // Success ! transactionStatus = hash.toString(); diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index 44bf5ac..ff5bc28 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -161,7 +161,6 @@ class WalletOptionsProvider with ChangeNotifier { !await isIdtyExist(idtyName.text) && idtyName.text.length >= 2 && idtyName.text.length <= 32; - log.d('aaaaaaaaaa: $canValidate'); notifyListeners(); }, diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index 8be23fa..08c87a2 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -45,7 +45,7 @@ class WalletsProfilesProvider with ChangeNotifier { MaterialPageRoute(builder: (context) { return WalletViewScreen( address: barcode!.rawContent, - username: '', + username: null, ); }), ); diff --git a/lib/screens/search.dart b/lib/screens/search.dart index 824b7f2..c5e2f08 100644 --- a/lib/screens/search.dart +++ b/lib/screens/search.dart @@ -172,7 +172,7 @@ class _SearchScreenState extends State { context, MaterialPageRoute(builder: (context) { return WalletViewScreen( - address: pastedAddress, username: ''); + address: pastedAddress, username: null); }), ); } diff --git a/lib/screens/transaction_in_progress.dart b/lib/screens/transaction_in_progress.dart index d497370..d620415 100644 --- a/lib/screens/transaction_in_progress.dart +++ b/lib/screens/transaction_in_progress.dart @@ -36,6 +36,7 @@ class TransactionInProgress extends StatelessWidget { .get(myWalletProvider.getDefaultWallet().address) ?.username ?? myWalletProvider.getDefaultWallet().name!; + String to = toAddress ?? walletProfiles.address; to = myWalletProvider.getWalletDataByAddress(to)?.name ?? getShortPubkey(to); @@ -64,7 +65,7 @@ class TransactionInProgress extends StatelessWidget { '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low': 'youHaveToFeedThisAccountBeforeUsing'.tr(), 'Token.FundsUnavailable': 'fundsUnavailable'.tr(), - 'timeout': 'execTimeoutOver'.tr(), + 'Exception: timeout': 'execTimeoutOver'.tr(), }; if (result.contains('blockHash: ')) { @@ -73,17 +74,10 @@ class TransactionInProgress extends StatelessWidget { .tr(args: [actionMap[transType] ?? 'strangeTransaction'.tr()]); log.i('Bloc of last transaction: ${sub.blocNumber} --- $result'); } else if (result.contains('Exception: ')) { - isValid = false; resultText = "${"anErrorOccurred".tr()}:\n"; - final List exceptionSplit = result.split('Exception: '); - String exception; - if (exceptionSplit.length > 1) { - exception = exceptionSplit[1]; - } else { - exception = exceptionSplit[0]; - } + final String exception = result.split('Exception: ')[1]; resultText = resultMap[exception] ?? "$resultText\n$exception"; - log.d('expection: $exceptionSplit'); + log.d('Error: $exception'); } else { isLoading = true; resultText = resultMap[result] ?? 'unknown status...'; diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 4b02a28..573d4bc 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -29,7 +29,7 @@ class WalletViewScreen extends StatelessWidget { {required this.address, required this.username, this.avatar, Key? key}) : super(key: key); final String address; - final String username; + final String? username; final Image? avatar; final double buttonSize = 100; final double buttonFontSize = 18; diff --git a/lib/widgets/contacts_list.dart b/lib/widgets/contacts_list.dart index 0a51ec1..2dd8aab 100644 --- a/lib/widgets/contacts_list.dart +++ b/lib/widgets/contacts_list.dart @@ -88,9 +88,8 @@ class ContactsList extends StatelessWidget { walletsProfilesClass.address = g1Wallet.address; return WalletViewScreen( address: g1Wallet.address, - username: duniterIndexer.walletNameIndexer[ - g1Wallet.address] ?? - '', + username: duniterIndexer + .walletNameIndexer[g1Wallet.address], avatar: g1WalletsBox .get(g1Wallet.address) ?.avatar, diff --git a/lib/widgets/history_view.dart b/lib/widgets/history_view.dart index 3dbd228..b17a9d9 100644 --- a/lib/widgets/history_view.dart +++ b/lib/widgets/history_view.dart @@ -112,7 +112,7 @@ class HistoryView extends StatelessWidget { PageNoTransit(builder: (context) { return WalletViewScreen( address: sub.oldOwnerKeys[address]![0], - username: '', + username: null, ); }), ), diff --git a/lib/widgets/payment_popup.dart b/lib/widgets/payment_popup.dart index af905f8..23e39f9 100644 --- a/lib/widgets/payment_popup.dart +++ b/lib/widgets/payment_popup.dart @@ -17,7 +17,7 @@ import 'package:gecko/widgets/name_by_address.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; -void paymentPopup(BuildContext context, String toAddress, String username) { +void paymentPopup(BuildContext context, String toAddress, String? username) { final walletViewProvider = Provider.of(context, listen: false); final myWalletProvider = @@ -229,9 +229,7 @@ void paymentPopup(BuildContext context, String toAddress, String username) { children: [ const SizedBox(height: 2), Text( - username == '' - ? getShortPubkey(toAddress) - : username, + username ?? getShortPubkey(toAddress), style: const TextStyle( fontSize: 21, fontWeight: FontWeight.w600, diff --git a/lib/widgets/search_identity_query.dart b/lib/widgets/search_identity_query.dart index 45b5afc..8e6ddb8 100644 --- a/lib/widgets/search_identity_query.dart +++ b/lib/widgets/search_identity_query.dart @@ -124,7 +124,7 @@ class SearchIdentityQuery extends StatelessWidget { walletsProfiles.address = profile['pubkey']; return WalletViewScreen( address: profile['pubkey'], - username: profile['name'] ?? '', + username: profile['name'], avatar: g1WalletsBox.get(profile['pubkey'])?.avatar, ); diff --git a/lib/widgets/search_result_list.dart b/lib/widgets/search_result_list.dart index 43929e2..9a09db8 100644 --- a/lib/widgets/search_result_list.dart +++ b/lib/widgets/search_result_list.dart @@ -100,7 +100,7 @@ class SearchResult extends StatelessWidget { walletsProfilesClass.address = g1Wallet.address; return WalletViewScreen( address: g1Wallet.address, - username: g1Wallet.username ?? '', + username: g1Wallet.username, avatar: g1Wallet.avatar, ); }), diff --git a/lib/widgets/transaction_tile.dart b/lib/widgets/transaction_tile.dart index 5f2f0b0..86b79c4 100644 --- a/lib/widgets/transaction_tile.dart +++ b/lib/widgets/transaction_tile.dart @@ -29,6 +29,8 @@ class TransactionTile extends StatelessWidget { @override Widget build(BuildContext context) { final newKey = keyID + 1; + final String? username = repository[2] == '' ? null : repository[2]; + return Padding( padding: const EdgeInsets.only(right: 0), child: ListTile( @@ -53,7 +55,7 @@ class TransactionTile extends StatelessWidget { TextSpan( text: dateForm, ), - if (repository[2] != '') + if (username != null) TextSpan( text: ' ยท ', style: TextStyle( @@ -62,7 +64,7 @@ class TransactionTile extends StatelessWidget { ), ), TextSpan( - text: repository[2], + text: username, style: TextStyle( fontStyle: FontStyle.italic, color: Colors.grey[600], @@ -87,7 +89,7 @@ class TransactionTile extends StatelessWidget { PageNoTransit(builder: (context) { return WalletViewScreen( address: repository[1], - username: repository[2] ?? '', + username: username, ); }), );