From a15a1053a42c002fa9c4bcc2eb4ba3a4f16f3aea Mon Sep 17 00:00:00 2001 From: fosse Date: Wed, 16 Aug 2023 13:23:53 -0400 Subject: [PATCH] more fixes --- lib/entities/default_settings_migration.dart | 11 +++++++---- .../restore/wallet_restore_choose_derivation.dart | 10 ++++++---- lib/src/screens/restore/wallet_restore_page.dart | 1 + .../wallet_restore_choose_derivation_view_model.dart | 12 ++++++------ lib/view_model/wallet_restore_view_model.dart | 5 +++-- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/entities/default_settings_migration.dart b/lib/entities/default_settings_migration.dart index c96e69611..b45a79c0a 100644 --- a/lib/entities/default_settings_migration.dart +++ b/lib/entities/default_settings_migration.dart @@ -250,7 +250,7 @@ Node? getEthereumDefaultNode({required Box nodes}) { Node? getNanoDefaultNode({required Box nodes}) { return nodes.values.firstWhereOrNull((Node node) => node.uriRaw == nanoDefaultNodeUri) ?? - nodes.values.firstWhereOrNull((node) => node.type == WalletType.ethereum); + nodes.values.firstWhereOrNull((node) => node.type == WalletType.nano); } Node getMoneroDefaultNode({required Box nodes}) { @@ -430,6 +430,7 @@ Future checkCurrentNodes(Box nodeSource, SharedPreferences sharedPre sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey); final currentHavenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey); final currentEthereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey); + final currentNanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey); final currentMoneroNode = nodeSource.values.firstWhereOrNull((node) => node.key == currentMoneroNodeId); final currentBitcoinElectrumServer = @@ -440,6 +441,8 @@ Future checkCurrentNodes(Box nodeSource, SharedPreferences sharedPre nodeSource.values.firstWhereOrNull((node) => node.key == currentHavenNodeId); final currentEthereumNodeServer = nodeSource.values.firstWhereOrNull((node) => node.key == currentEthereumNodeId); + final currentNanoNodeServer = + nodeSource.values.firstWhereOrNull((node) => node.key == currentNanoNodeId); if (currentMoneroNode == null) { final newCakeWalletNode = Node(uri: newCakeWalletMoneroUri, type: WalletType.monero); @@ -473,11 +476,11 @@ Future checkCurrentNodes(Box nodeSource, SharedPreferences sharedPre await sharedPreferences.setInt(PreferencesKey.currentEthereumNodeIdKey, node.key as int); } - if (currentEthereumNodeServer == null) { - final node = Node(uri: ethereumDefaultNodeUri, type: WalletType.ethereum); + if (currentNanoNodeServer == null) { + final node = Node(uri: nanoDefaultNodeUri, type: WalletType.nano); await nodeSource.add(node); await sharedPreferences.setInt( - PreferencesKey.currentEthereumNodeIdKey, node.key as int); + PreferencesKey.currentNanoNodeIdKey, node.key as int); } } diff --git a/lib/src/screens/restore/wallet_restore_choose_derivation.dart b/lib/src/screens/restore/wallet_restore_choose_derivation.dart index 08664bc28..8a777c720 100644 --- a/lib/src/screens/restore/wallet_restore_choose_derivation.dart +++ b/lib/src/screens/restore/wallet_restore_choose_derivation.dart @@ -36,9 +36,9 @@ class WalletRestoreChooseDerivationPage extends BasePage { child: CircularProgressIndicator(), ); } else if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); + return Center(child: Text('Error: ${snapshot.error}')); } else if (!snapshot.hasData || snapshot.data!.isEmpty) { - return Text('Error! No derivations available!'); + return Center(child: Text('Error! No derivations available!')); } else { return ListView.separated( shrinkWrap: true, @@ -62,8 +62,10 @@ class WalletRestoreChooseDerivationPage extends BasePage { title: Center( child: Text( "${derivation.derivationType.toString().split('.').last}", - style: - Theme.of(context).primaryTextTheme.labelMedium!.copyWith(fontSize: 18), + style: Theme.of(context) + .primaryTextTheme + .labelMedium! + .copyWith(fontSize: 18), ), ), subtitle: Column( diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 6fd287be7..921f65ddc 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -281,6 +281,7 @@ class WalletRestorePage extends BasePage { } credentials['derivationType'] = this.derivationType; + credentials['walletType'] = walletRestoreViewModel.type; return credentials; } diff --git a/lib/view_model/wallet_restore_choose_derivation_view_model.dart b/lib/view_model/wallet_restore_choose_derivation_view_model.dart index c38245e80..7783ea2cb 100644 --- a/lib/view_model/wallet_restore_choose_derivation_view_model.dart +++ b/lib/view_model/wallet_restore_choose_derivation_view_model.dart @@ -33,16 +33,15 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { Future> get derivations async { var list = []; + var walletType = credentials["walletType"] as WalletType; var appStore = getIt.get(); - var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type); - switch ((await getIt.get().wallet!.type)) { + var node = appStore.settingsStore.getCurrentNode(walletType); + switch (walletType) { case WalletType.nano: String? mnemonic = credentials['seed'] as String?; String? seedKey = credentials['seedKey'] as String?; var bip39Info = await NanoWalletService.getInfoFromSeedOrMnemonic(DerivationType.bip39, - mnemonic: mnemonic, - seedKey: seedKey, - node: node); + mnemonic: mnemonic, seedKey: seedKey, node: node); var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic( DerivationType.nano, mnemonic: mnemonic, @@ -50,7 +49,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { node: node, ); - if (standardInfo["address"] != null) { + if (standardInfo["balance"] != null) { list.add(Derivation( NanoUtil.getRawAsUsableString(standardInfo["balance"] as String, NanoUtil.rawPerNano), standardInfo["address"] as String, @@ -77,6 +76,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { default: break; } + return list; } } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 49f1275cd..e306c8140 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -138,9 +138,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { Future> getDerivationType(dynamic options) async { final seedKey = options['seedKey'] as String?; final mnemonic = options['seed'] as String?; + WalletType walletType = options['walletType'] as WalletType; var appStore = getIt.get(); - var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type); - + var node = appStore.settingsStore.getCurrentNode(walletType); + switch (type) { // case WalletType.bitcoin: // return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(