split default derivation in to defaultCreation and mostCommon

This commit is contained in:
Matthew Fosse 2024-04-26 16:05:03 -07:00
parent 7b49b2ad87
commit 34f7ed4eae
3 changed files with 21 additions and 6 deletions

View file

@ -377,8 +377,6 @@ class WalletRestorePage extends BasePage {
) as DerivationInfo?; ) as DerivationInfo?;
} else if (derivationsWithHistory == 1) { } else if (derivationsWithHistory == 1) {
dInfo = derivations[derivationWithHistoryIndex]; dInfo = derivations[derivationWithHistoryIndex];
} else if (derivationsWithHistory == 0 && derivations.isNotEmpty) {
dInfo = derivations.first;
} }
if (dInfo == null) { if (dInfo == null) {
@ -390,7 +388,7 @@ class WalletRestorePage extends BasePage {
// get the default derivation for this wallet type: // get the default derivation for this wallet type:
if (this.derivationInfo == null) { if (this.derivationInfo == null) {
this.derivationInfo = walletRestoreViewModel.getDefaultDerivation(); this.derivationInfo = walletRestoreViewModel.getMostCommonDerivation();
} }
walletRestoreViewModel.state = InitialExecutionState(); walletRestoreViewModel.state = InitialExecutionState();

View file

@ -59,7 +59,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
derivationInfo = options["derivationInfo"] as DerivationInfo?; derivationInfo = options["derivationInfo"] as DerivationInfo?;
passphrase = options["passphrase"] as String?; passphrase = options["passphrase"] as String?;
} }
derivationInfo ??= getDefaultDerivation(); derivationInfo ??= getDefaultCreationDerivation();
switch (restoreWallet.restoreMode) { switch (restoreWallet.restoreMode) {
case WalletRestoreMode.keys: case WalletRestoreMode.keys:

View file

@ -71,7 +71,7 @@ abstract class WalletCreationVMBase with Store {
dirPath: dirPath, dirPath: dirPath,
address: '', address: '',
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven, showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
derivationInfo: credentials.derivationInfo ?? getDefaultDerivation(), derivationInfo: credentials.derivationInfo ?? getDefaultCreationDerivation(),
); );
credentials.walletInfo = walletInfo; credentials.walletInfo = walletInfo;
@ -89,7 +89,7 @@ abstract class WalletCreationVMBase with Store {
} }
} }
DerivationInfo? getDefaultDerivation() { DerivationInfo? getDefaultCreationDerivation() {
switch (this.type) { switch (this.type) {
case WalletType.nano: case WalletType.nano:
return DerivationInfo( return DerivationInfo(
@ -106,6 +106,23 @@ abstract class WalletCreationVMBase with Store {
} }
} }
DerivationInfo? getMostCommonDerivation() {
switch (this.type) {
case WalletType.nano:
return DerivationInfo(
derivationType: DerivationType.nano,
);
case WalletType.bitcoin:
case WalletType.litecoin:
return DerivationInfo(
derivationType: DerivationType.electrum,
derivationPath: "m/84'/0'/0'/0",
);
default:
return null;
}
}
WalletCredentials getCredentials(dynamic options) => throw UnimplementedError(); WalletCredentials getCredentials(dynamic options) => throw UnimplementedError();
Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError(); Future<WalletBase> process(WalletCredentials credentials) => throw UnimplementedError();