diff --git a/cw_nano/lib/nano_client.dart b/cw_nano/lib/nano_client.dart index 478a6c125..7f8e1d0a9 100644 --- a/cw_nano/lib/nano_client.dart +++ b/cw_nano/lib/nano_client.dart @@ -466,21 +466,25 @@ class NanoClient { blocks = blocks as Map; - // confirm all receivable blocks: - for (final blockHash in blocks.keys) { - final block = blocks[blockHash]; - final String amountRaw = block["amount"] as String; - await receiveBlock( - blockHash: blockHash, - amountRaw: amountRaw, - privateKey: privateKey, - destinationAddress: destinationAddress, - ); - // a bit of a hack: - await Future.delayed(const Duration(seconds: 2)); + try { + // confirm all receivable blocks: + for (final blockHash in blocks.keys) { + final block = blocks[blockHash]; + final String amountRaw = block["amount"] as String; + await receiveBlock( + blockHash: blockHash, + amountRaw: amountRaw, + privateKey: privateKey, + destinationAddress: destinationAddress, + ); + // a bit of a hack: + await Future.delayed(const Duration(seconds: 2)); + } + return blocks.keys.length; + } catch (_) { + // we failed to confirm all receivable blocks for w/e reason (PoW / node outage / etc) + return 0; } - - return blocks.keys.length; } void stop() {} diff --git a/cw_nano/lib/nano_wallet_service.dart b/cw_nano/lib/nano_wallet_service.dart index ac3d6581a..6dbcc68ab 100644 --- a/cw_nano/lib/nano_wallet_service.dart +++ b/cw_nano/lib/nano_wallet_service.dart @@ -14,8 +14,11 @@ import 'package:bip39/bip39.dart' as bip39; import 'package:nanodart/nanodart.dart'; import 'package:nanoutil/nanoutil.dart'; -class NanoWalletService extends WalletService { +class NanoWalletService extends WalletService< + NanoNewWalletCredentials, + NanoRestoreWalletFromSeedCredentials, + NanoRestoreWalletFromKeysCredentials, + NanoNewWalletCredentials> { NanoWalletService(this.walletInfoSource, this.isDirect); final Box walletInfoSource; @@ -33,8 +36,12 @@ class NanoWalletService extends WalletService restoreFromKeys(NanoRestoreWalletFromKeysCredentials credentials, {bool? isTestnet}) async { + Future restoreFromKeys(NanoRestoreWalletFromKeysCredentials credentials, + {bool? isTestnet}) async { if (credentials.seedKey.contains(' ')) { throw Exception("Invalid key!"); } else { @@ -106,6 +114,13 @@ class NanoWalletService extends WalletService restoreFromHardwareWallet(NanoNewWalletCredentials credentials) { - throw UnimplementedError("Restoring a Nano wallet from a hardware wallet is not yet supported!"); + throw UnimplementedError( + "Restoring a Nano wallet from a hardware wallet is not yet supported!"); } @override - Future restoreFromSeed(NanoRestoreWalletFromSeedCredentials credentials, {bool? isTestnet}) async { + Future restoreFromSeed(NanoRestoreWalletFromSeedCredentials credentials, + {bool? isTestnet}) async { if (credentials.mnemonic.contains(' ')) { if (!bip39.validateMnemonic(credentials.mnemonic)) { throw nm.NanoMnemonicIsIncorrectException(); diff --git a/lib/src/screens/nano/nano_change_rep_page.dart b/lib/src/screens/nano/nano_change_rep_page.dart index 9f71bb59c..60207b507 100644 --- a/lib/src/screens/nano/nano_change_rep_page.dart +++ b/lib/src/screens/nano/nano_change_rep_page.dart @@ -40,13 +40,11 @@ class NanoChangeRepPage extends BasePage { (node) => node.account == currentRepAccount, orElse: () => N2Node( account: currentRepAccount, - alias: currentRepAccount, score: 0, uptime: "???", weight: 0, ), ); - return currentNode; } @@ -57,9 +55,7 @@ class NanoChangeRepPage extends BasePage { child: FutureBuilder( future: nano!.getN2Reps(_wallet), builder: (context, snapshot) { - if (snapshot.data == null) { - return SizedBox(); - } + final reps = snapshot.data ?? []; return Container( padding: EdgeInsets.only(left: 24, right: 24), @@ -101,29 +97,35 @@ class NanoChangeRepPage extends BasePage { ), _buildSingleRepresentative( context, - getCurrentRepNode(snapshot.data as List), + getCurrentRepNode(reps), isList: false, + divider: false, ), - Divider(height: 20), - Container( - margin: EdgeInsets.only(top: 12), - child: Text( - S.current.nano_pick_new_rep, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w700, + if (reps.isNotEmpty) ...[ + Divider(height: 20), + Container( + margin: EdgeInsets.only(top: 12), + child: Text( + S.current.nano_pick_new_rep, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w700, + ), ), ), - ), + Divider(height: 20), + ], ], ), ], ), contentPadding: EdgeInsets.only(bottom: 24), content: Container( - child: Column( - children: _getRepresentativeWidgets(context, snapshot.data as List), - ), + child: reps.isNotEmpty + ? Column( + children: _getRepresentativeWidgets(context, reps), + ) + : SizedBox(), ), bottomSectionPadding: EdgeInsets.only(bottom: 24), bottomSection: Observer( @@ -207,19 +209,22 @@ class NanoChangeRepPage extends BasePage { final List ret = []; for (final N2Node node in list) { if (node.alias != null && node.alias!.trim().isNotEmpty) { - ret.add(_buildSingleRepresentative(context, node)); + bool divider = node != list.first; + ret.add(_buildSingleRepresentative(context, node, divider: divider, isList: true)); } } return ret; } - Widget _buildSingleRepresentative(BuildContext context, N2Node rep, {bool isList = true}) { + Widget _buildSingleRepresentative( + BuildContext context, + N2Node rep, { + bool isList = true, + bool divider = false, + }) { return Column( children: [ - if (isList) - Divider( - height: 2, - ), + if (divider) Divider(height: 2), TextButton( style: TextButton.styleFrom( padding: EdgeInsets.zero, @@ -244,11 +249,11 @@ class NanoChangeRepPage extends BasePage { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _sanitizeAlias(rep.alias), + rep.alias ?? rep.account!, style: TextStyle( color: Theme.of(context).extension()!.titleColor, fontWeight: FontWeight.w700, - fontSize: 18, + fontSize: rep.alias == null ? 14 : 18, ), ), Container( @@ -337,11 +342,4 @@ class NanoChangeRepPage extends BasePage { ], ); } - - String _sanitizeAlias(String? alias) { - if (alias != null) { - return alias.replaceAll(RegExp(r'[^a-zA-Z_.!?_;:-]'), ''); - } - return ''; - } } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index a365a2040..5462ce4c8 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -42,7 +42,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { type == WalletType.tron, isButtonEnabled = false, mode = WalletRestoreMode.seed, - super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, type: type, isRecovery: true) { + super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, + type: type, isRecovery: true) { switch (type) { case WalletType.monero: availableModes = WalletRestoreMode.values; @@ -194,10 +195,11 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { case WalletType.nano: return nano!.createNanoRestoreWalletFromKeysCredentials( - name: name, - password: password, - seedKey: options['private_key'] as String, - derivationType: options["derivationType"] as DerivationType); + name: name, + password: password, + seedKey: options['private_key'] as String, + derivationType: derivationInfo!.derivationType!, + ); case WalletType.polygon: return polygon!.createPolygonRestoreWalletFromPrivateKey( name: name,