From db83cb625f0f0b2b5c040f06c1e4545875f37ba3 Mon Sep 17 00:00:00 2001 From: fosse Date: Thu, 5 Oct 2023 10:39:07 -0400 Subject: [PATCH] move wallet restore page proxy code to the view model --- .../screens/restore/wallet_restore_page.dart | 52 +------------------ lib/view_model/wallet_restore_view_model.dart | 50 ++++++++++++++++++ 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 9081e24a9..42b73106f 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -300,56 +300,6 @@ class WalletRestorePage extends BasePage { return credentials; } - Future> getDerivationInfo(dynamic credentials) async { - var list = []; - var walletType = credentials["walletType"] as WalletType; - var appStore = getIt.get(); - var node = appStore.settingsStore.getCurrentNode(walletType); - - switch (walletType) { - case WalletType.bitcoin: - String? mnemonic = credentials['seed'] as String?; - return bitcoin!.getDerivationsFromMnemonic( - mnemonic: mnemonic!, node: node); - case WalletType.nano: - String? mnemonic = credentials['seed'] as String?; - String? seedKey = credentials['private_key'] as String?; - AccountInfoResponse? bip39Info = await nanoUtil!.getInfoFromSeedOrMnemonic( - DerivationType.bip39, - mnemonic: mnemonic, - seedKey: seedKey, - node: node); - AccountInfoResponse? standardInfo = await nanoUtil!.getInfoFromSeedOrMnemonic( - DerivationType.nano, - mnemonic: mnemonic, - seedKey: seedKey, - node: node, - ); - - if (standardInfo?.balance != null) { - list.add(DerivationInfo( - derivationType: DerivationType.nano, - balance: nanoUtil!.getRawAsUsableString(standardInfo!.balance, nanoUtil!.rawPerNano), - address: standardInfo.address!, - height: standardInfo.confirmationHeight, - )); - } - - if (bip39Info?.balance != null) { - list.add(DerivationInfo( - derivationType: DerivationType.bip39, - balance: nanoUtil!.getRawAsUsableString(bip39Info!.balance, nanoUtil!.rawPerNano), - address: bip39Info.address!, - height: bip39Info.confirmationHeight, - )); - } - break; - default: - break; - } - return list; - } - Future _confirmForm(BuildContext context) async { // Dismissing all visible keyboard to provide context for navigation FocusManager.instance.primaryFocus?.unfocus(); @@ -383,7 +333,7 @@ class WalletRestorePage extends BasePage { if (derivationTypes[0] == DerivationType.unknown || derivationTypes.length > 1) { // push screen to choose the derivation type: - List derivations = await getDerivationInfo(_credentials()); + List derivations = await walletRestoreViewModel.getDerivationInfo(_credentials()); int derivationsWithHistory = 0; int derivationWithHistoryIndex = 0; diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 30313e830..d8ee2b6c1 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/nano/nano.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; +import 'package:cw_core/nano_account_info_response.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/store/app_store.dart'; @@ -157,6 +158,55 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { throw Exception('Unexpected type: ${type.toString()}'); } + Future> getDerivationInfo(dynamic credentials) async { + var list = []; + var walletType = credentials["walletType"] as WalletType; + var appStore = getIt.get(); + var node = appStore.settingsStore.getCurrentNode(walletType); + + switch (walletType) { + case WalletType.bitcoin: + String? mnemonic = credentials['seed'] as String?; + return bitcoin!.getDerivationsFromMnemonic(mnemonic: mnemonic!, node: node); + case WalletType.nano: + String? mnemonic = credentials['seed'] as String?; + String? seedKey = credentials['private_key'] as String?; + AccountInfoResponse? bip39Info = await nanoUtil!.getInfoFromSeedOrMnemonic( + DerivationType.bip39, + mnemonic: mnemonic, + seedKey: seedKey, + node: node); + AccountInfoResponse? standardInfo = await nanoUtil!.getInfoFromSeedOrMnemonic( + DerivationType.nano, + mnemonic: mnemonic, + seedKey: seedKey, + node: node, + ); + + if (standardInfo?.balance != null) { + list.add(DerivationInfo( + derivationType: DerivationType.nano, + balance: nanoUtil!.getRawAsUsableString(standardInfo!.balance, nanoUtil!.rawPerNano), + address: standardInfo.address!, + height: standardInfo.confirmationHeight, + )); + } + + if (bip39Info?.balance != null) { + list.add(DerivationInfo( + derivationType: DerivationType.bip39, + balance: nanoUtil!.getRawAsUsableString(bip39Info!.balance, nanoUtil!.rawPerNano), + address: bip39Info.address!, + height: bip39Info.confirmationHeight, + )); + } + break; + default: + break; + } + return list; + } + Future> getDerivationTypes(dynamic options) async { final seedKey = options['private_key'] as String?; final mnemonic = options['seed'] as String?;