refactor fixes

This commit is contained in:
fosse 2023-10-10 11:27:11 -04:00
parent 8e130166ac
commit 95e7ee1cbb
6 changed files with 20 additions and 28 deletions

View file

@ -46,10 +46,6 @@ class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
@override
Future<BitcoinWallet> create(BitcoinNewWalletCredentials credentials) async {
// set the walletInfo's derivationInfo if not present:
credentials.walletInfo!.derivationInfo ??= credentials.derivationInfo;
final wallet = await BitcoinWalletBase.create(
mnemonic: await generateElectrumMnemonic(strength: 132),
password: credentials.password!,

View file

@ -6,12 +6,15 @@ abstract class WalletCredentials {
this.height,
this.walletInfo,
this.password,
this.derivationInfo,
});
DerivationInfo? derivationInfo,
}) {
if (this.walletInfo != null && derivationInfo != null) {
this.walletInfo!.derivationInfo = derivationInfo;
}
}
final String name;
final int? height;
String? password;
WalletInfo? walletInfo;
DerivationInfo? derivationInfo;
}

View file

@ -355,6 +355,9 @@ abstract class NanoWalletBase
}
walletInfo.derivationInfo ??= DerivationInfo(derivationType: derivationType);
if (walletInfo.derivationInfo!.derivationType == null) {
walletInfo.derivationInfo!.derivationType = derivationType;
}
return NanoWallet(
walletInfo: walletInfo,

View file

@ -31,10 +31,8 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
String seedKey = NanoSeeds.generateSeed();
String mnemonic = NanoUtil.seedToMnemonic(seedKey);
// set default if not present:
DerivationType derivationType =
credentials.derivationInfo?.derivationType ?? DerivationType.nano;
credentials.walletInfo!.derivationInfo ??= DerivationInfo(derivationType: derivationType);
// ensure default if not present:
credentials.walletInfo!.derivationInfo ??= DerivationInfo(derivationType: DerivationType.nano);
final wallet = NanoWallet(
walletInfo: credentials.walletInfo!,
@ -89,9 +87,6 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
}
}
// set the walletInfo's derivationInfo if not present:
credentials.walletInfo!.derivationInfo ??= credentials.derivationInfo;
String? mnemonic;
// we can't derive the mnemonic from the key in all cases, only if it's a "nano" seed
@ -153,6 +148,7 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
Future<NanoWallet> openWallet(String name, String password) async {
final walletInfo =
walletInfoSource.values.firstWhere((info) => info.id == WalletBase.idFor(name, getType()));
final wallet = await NanoWalletBase.open(
name: name,
password: password,

View file

@ -101,12 +101,12 @@ abstract class ExchangeTradeViewModelBase with Store {
return;
}
// sendViewModel.clearOutputs();
// final output = sendViewModel.outputs.first;
// output.address = trade.inputAddress ?? '';
// output.setCryptoAmount(trade.amount);
// sendViewModel.selectedCryptoCurrency = trade.from;
// await sendViewModel.createTransaction();
sendViewModel.clearOutputs();
final output = sendViewModel.outputs.first;
output.address = trade.inputAddress ?? '';
output.setCryptoAmount(trade.amount);
sendViewModel.selectedCryptoCurrency = trade.from;
await sendViewModel.createTransaction();
}
@action

View file

@ -47,13 +47,6 @@ abstract class WalletCreationVMBase with Store {
name = await generateName();
}
if (options == null || options["derivationInfo"] == null) {
if (options == null) {
options = {};
}
options["derivationInfo"] = getDefaultDerivation();
}
walletCreationService.checkIfExists(name);
final dirPath = await pathForWalletDir(name: name, type: type);
final path = await pathForWallet(name: name, type: type);
@ -72,8 +65,9 @@ abstract class WalletCreationVMBase with Store {
dirPath: dirPath,
address: '',
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
derivationInfo: credentials.derivationInfo,
derivationInfo: getDefaultDerivation(),
);
credentials.walletInfo = walletInfo;
final wallet = restoreWallet != null
? await processFromRestoredWallet(credentials, restoreWallet)