diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 741befbc0..7d7fdb889 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -406,24 +406,16 @@ class WalletRestorePage extends BasePage { ) as DerivationInfo?; } else if (derivationsWithHistory == 1) { dInfo = derivations[derivationWithHistoryIndex]; - } - - // get the default derivation for this wallet type: - if (dInfo == null) { + } else if (derivations.length == 1) { // we only return 1 derivation if we're pretty sure we know which one to use: - if (derivations.length == 1) { - dInfo = derivations.first; - } else { - // if we have multiple possible derivations, and none have histories - // we just default to the most common one: - dInfo = walletRestoreViewModel.getCommonRestoreDerivation(); - } + dInfo = derivations.first; + } else { + // if we have multiple possible derivations, and none (or multiple) have histories + // we just default to the most common one: + dInfo = walletRestoreViewModel.getCommonRestoreDerivation(); } this.derivationInfo = dInfo; - if (this.derivationInfo == null) { - this.derivationInfo = walletRestoreViewModel.getDefaultDerivation(); - } await walletRestoreViewModel.create(options: _credentials()); seedSettingsViewModel.setPassphrase(null); diff --git a/lib/view_model/restore/restore_from_qr_vm.dart b/lib/view_model/restore/restore_from_qr_vm.dart index 789d7da52..bb7d0f8d1 100644 --- a/lib/view_model/restore/restore_from_qr_vm.dart +++ b/lib/view_model/restore/restore_from_qr_vm.dart @@ -62,7 +62,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store derivationInfo = options["derivationInfo"] as DerivationInfo?; passphrase = options["passphrase"] as String?; } - derivationInfo ??= getDefaultDerivation(); + derivationInfo ??= getDefaultCreateDerivation(); switch (restoreWallet.restoreMode) { case WalletRestoreMode.keys: diff --git a/lib/view_model/wallet_creation_vm.dart b/lib/view_model/wallet_creation_vm.dart index 5760f5eec..e563be37a 100644 --- a/lib/view_model/wallet_creation_vm.dart +++ b/lib/view_model/wallet_creation_vm.dart @@ -97,7 +97,7 @@ abstract class WalletCreationVMBase with Store { dirPath: dirPath, address: '', showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven, - derivationInfo: credentials.derivationInfo ?? getDefaultDerivation(), + derivationInfo: credentials.derivationInfo ?? getDefaultCreateDerivation(), hardwareWalletType: credentials.hardwareWalletType, ); @@ -116,7 +116,7 @@ abstract class WalletCreationVMBase with Store { } } - DerivationInfo? getDefaultDerivation() { + DerivationInfo? getDefaultCreateDerivation() { final useBip39 = seedSettingsViewModel.bitcoinSeedType.type == DerivationType.bip39; switch (type) { case WalletType.nano: @@ -147,10 +147,14 @@ abstract class WalletCreationVMBase with Store { } DerivationInfo? getCommonRestoreDerivation() { + final useElectrum = seedSettingsViewModel.bitcoinSeedType.type == DerivationType.electrum; switch (this.type) { case WalletType.nano: return DerivationInfo(derivationType: DerivationType.nano); case WalletType.bitcoin: + if (useElectrum) { + return bitcoin!.getElectrumDerivations()[DerivationType.electrum]!.first; + } return DerivationInfo( derivationType: DerivationType.bip39, derivationPath: "m/84'/0'/0'/0", @@ -158,6 +162,9 @@ abstract class WalletCreationVMBase with Store { scriptType: "p2wpkh", ); case WalletType.litecoin: + if (useElectrum) { + return bitcoin!.getElectrumDerivations()[DerivationType.electrum]!.first; + } return DerivationInfo( derivationType: DerivationType.bip39, derivationPath: "m/84'/2'/0'/0",