Cw 772 restore from qr generates different wallet (#1742)

* fix derivation info for QR restoring * allow all available seed languages for Monero * set default derivation info for an empty wallet * fix electrum case

Serhii committed Oct 16, 2024 at 20:25 UTC 605d164998c0f964267861edfff1972c88e15ab1
2 files changed +34 -19
lib/view_model/restore/restore_from_qr_vm.dart
+10 -2
@@ -37,7 +37,8 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
37 spendKey = '',
38 wif = '',
39 address = '',
40 - super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel, type: type, isRecovery: true);
40 + super(appStore, walletInfoSource, walletCreationService, seedSettingsViewModel,
41 + type: type, isRecovery: true);
42
43 @observable
44 int height;
@@ -112,7 +113,14 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
113 );
114 case WalletType.bitcoin:
115 case WalletType.litecoin:
115 - final derivationInfo = (await getDerivationInfoFromQRCredentials(restoreWallet)).first;
116 +
117 + final derivationInfoList = await getDerivationInfoFromQRCredentials(restoreWallet);
118 + DerivationInfo derivationInfo;
119 + if (derivationInfoList.isEmpty) {
120 + derivationInfo = getDefaultCreateDerivation()!;
121 + } else {
122 + derivationInfo = derivationInfoList.first;
123 + }
124 return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
125 name: name,
126 mnemonic: restoreWallet.mnemonicSeed ?? '',
lib/view_model/wallet_creation_vm.dart
+24 -17
@@ -194,24 +194,31 @@ abstract class WalletCreationVMBase with Store {
194 final walletType = restoreWallet.type;
195 var appStore = getIt.get<AppStore>();
196 var node = appStore.settingsStore.getCurrentNode(walletType);
197 +
198 + switch (walletType) {
199 + case WalletType.bitcoin:
200 + case WalletType.litecoin:
201 +
202 + final derivationList = await bitcoin!.getDerivationsFromMnemonic(
203 + mnemonic: restoreWallet.mnemonicSeed!,
204 + node: node,
205 + passphrase: restoreWallet.passphrase,
206 + );
207
198 - switch (walletType) {
199 - case WalletType.bitcoin:
200 - case WalletType.litecoin:
201 - return bitcoin!.getDerivationsFromMnemonic(
202 - mnemonic: restoreWallet.mnemonicSeed!,
203 - node: node,
204 - passphrase: restoreWallet.passphrase,
205 - );
206 - case WalletType.nano:
207 - return nanoUtil!.getDerivationsFromMnemonic(
208 - mnemonic: restoreWallet.mnemonicSeed!,
209 - node: node,
210 - );
211 - default:
212 - break;
213 - }
214 - return list;
208 +
209 + if (derivationList.first.transactionsCount == 0 && derivationList.length > 1) return [];
210 +
211 + return derivationList;
212 +
213 + case WalletType.nano:
214 + return nanoUtil!.getDerivationsFromMnemonic(
215 + mnemonic: restoreWallet.mnemonicSeed!,
216 + node: node,
217 + );
218 + default:
219 + break;
220 + }
221 + return list;
222 }
223
224 WalletCredentials getCredentials(dynamic options) => throw UnimplementedError();