diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 7041fa382..9fce86712 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -5,8 +5,10 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/background_tasks.dart'; import 'package:cake_wallet/entities/generate_name.dart'; import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/nano/nano.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cake_wallet/view_model/restore/restore_mode.dart'; import 'package:cake_wallet/view_model/restore/restore_wallet.dart'; import 'package:cake_wallet/view_model/seed_settings_view_model.dart'; import 'package:cw_core/pathForWallet.dart'; @@ -82,9 +84,22 @@ abstract class WalletCreationVMBase with Store { walletCreationService.checkIfExists(name); final dirPath = await pathForWalletDir(name: name, type: type); final path = await pathForWallet(name: name, type: type); - final credentials = restoreWallet != null - ? getCredentialsFromRestoredWallet(options, restoreWallet) - : getCredentials(options); + + WalletCredentials credentials; + if (restoreWallet != null) { + if (restoreWallet.restoreMode == WalletRestoreMode.seed && + options == null && + (type == WalletType.nano || + type == WalletType.bitcoin || + type == WalletType.litecoin)) { + final derivationInfo = await getDerivationInfo(restoreWallet); + options ??= {}; + options["derivationInfo"] = derivationInfo.first; + } + credentials = getCredentialsFromRestoredWallet(options, restoreWallet); + } else { + credentials = getCredentials(options); + } final walletInfo = WalletInfo.external( id: WalletBase.idFor(name, type), @@ -185,6 +200,30 @@ abstract class WalletCreationVMBase with Store { } } + Future> getDerivationInfo(RestoredWallet restoreWallet) async { + var list = []; + final walletType = restoreWallet.type; + var appStore = getIt.get(); + var node = appStore.settingsStore.getCurrentNode(walletType); + + switch (walletType) { + case WalletType.bitcoin: + case WalletType.litecoin: + return bitcoin!.getDerivationsFromMnemonic( + mnemonic: restoreWallet.mnemonicSeed!, + node: node, + ); + case WalletType.nano: + return nanoUtil!.getDerivationsFromMnemonic( + mnemonic: restoreWallet.mnemonicSeed!, + node: node, + ); + default: + break; + } + return list; + } + WalletCredentials getCredentials(dynamic options) => throw UnimplementedError(); Future process(WalletCredentials credentials) => throw UnimplementedError();