From a6a4e88a940c5bf7afb9feec04cf0cda41e8acb1 Mon Sep 17 00:00:00 2001 From: fosse Date: Mon, 20 Nov 2023 10:51:19 -0500 Subject: [PATCH] fixes for restoring --- lib/view_model/restore/restore_from_qr_vm.dart | 13 ++++++++++--- lib/view_model/wallet_keys_view_model.dart | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/view_model/restore/restore_from_qr_vm.dart b/lib/view_model/restore/restore_from_qr_vm.dart index 1bb1e88dd..3cd1d91bc 100644 --- a/lib/view_model/restore/restore_from_qr_vm.dart +++ b/lib/view_model/restore/restore_from_qr_vm.dart @@ -51,7 +51,11 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store WalletCredentials getCredentialsFromRestoredWallet( dynamic options, RestoredWallet restoreWallet) { final password = generateWalletPassword(); - DerivationInfo? derivationInfo = options["derivationInfo"] as DerivationInfo?; + DerivationInfo? derivationInfo; + if (options != null) { + derivationInfo = options["derivationInfo"] as DerivationInfo?; + } + derivationInfo ??= getDefaultDerivation(); switch (restoreWallet.restoreMode) { case WalletRestoreMode.keys: @@ -89,7 +93,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password, - derivationType: derivationInfo!.derivationType!, + derivationType: derivationInfo.derivationType!, derivationPath: derivationInfo.derivationPath!, ); case WalletType.bitcoinCash: @@ -100,7 +104,10 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password); case WalletType.nano: return nano!.createNanoRestoreWalletFromSeedCredentials( - name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password, derivationType: DerivationType.def); + name: name, + mnemonic: restoreWallet.mnemonicSeed ?? '', + password: password, + derivationType: derivationInfo.derivationType!); default: throw Exception('Unexpected type: ${type.toString()}'); } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index 257bae1fd..f88135672 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -172,7 +172,7 @@ abstract class WalletKeysViewModelBase with Store { final restoreHeightResult = await restoreHeight; return { if (_appStore.wallet!.seed != null) 'seed': _appStore.wallet!.seed!, - if (_appStore.wallet!.privateKey != null) 'private_key': _appStore.wallet!.privateKey!, + if (_appStore.wallet!.privateKey != null && _appStore.wallet!.seed == null) 'private_key': _appStore.wallet!.privateKey!, if (restoreHeightResult != null) ...{'height': restoreHeightResult} }; }