last minute fixes

This commit is contained in:
fosse 2023-08-16 12:22:25 -04:00
parent cd7f636558
commit 3041fcc8b8
4 changed files with 31 additions and 34 deletions

View file

@ -121,14 +121,14 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}
static Future<dynamic> getInfoFromSeedOrMnemonic(DerivationType derivationType,
{String? seedKey, String? mnemonic}) async {
static Future<dynamic> getInfoFromSeedOrMnemonic(
DerivationType derivationType, {
String? seedKey,
String? mnemonic,
required Node node,
}) async {
NanoClient nanoClient = NanoClient();
// TODO: figure out how to load the current node uri in this context:
nanoClient.connect(Node(
uri: NanoClient.BACKUP_NODE_URI,
type: WalletType.nano,
));
nanoClient.connect(node);
late String publicAddress;
if (seedKey != null) {
@ -159,7 +159,7 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
}
static Future<List<DerivationType>> compareDerivationMethods(
{String? mnemonic, String? seedKey}) async {
{String? mnemonic, String? seedKey, required Node node}) async {
if (mnemonic?.split(' ').length == 12) {
return [DerivationType.bip39];
}
@ -174,11 +174,7 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
try {
NanoClient nanoClient = NanoClient();
// TODO: figure out how to load the current node uri in this context:
nanoClient.connect(Node(
uri: NanoClient.BACKUP_NODE_URI,
type: WalletType.nano,
));
nanoClient.connect(node);
if (mnemonic != null) {
seedKey = await NanoUtil.hdMnemonicListToSeed(mnemonic.split(' '));
@ -240,13 +236,12 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
}
}
DerivationType derivationType = credentials.derivationType ?? DerivationType.nano;
credentials.walletInfo!.derivationType = derivationType;
final wallet = await NanoWallet(
password: credentials.password!,
mnemonic: credentials.seedKey,// we can't derive the mnemonic from the key in all cases
mnemonic: credentials.seedKey, // we can't derive the mnemonic from the key in all cases
walletInfo: credentials.walletInfo!,
);
await wallet.init();

View file

@ -331,14 +331,8 @@ class WalletRestorePage extends BasePage {
}
walletRestoreViewModel.state = InitialExecutionState();
// todo: re-enable
try {
walletRestoreViewModel.create(options: _credentials());
} catch (e) {
print(e);
rethrow;
}
walletRestoreViewModel.create(options: _credentials());
}
Future<void> showNameExistsAlert(BuildContext context) {

View file

@ -33,19 +33,21 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
Future<List<Derivation>> get derivations async {
var list = <Derivation>[];
var appStore = getIt.get<AppStore>();
var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type);
switch ((await getIt.get<AppStore>().wallet!.type)) {
case WalletType.nano:
String? mnemonic = credentials['seed'] as String?;
String? seedKey = credentials['seedKey'] as String?;
var bip39Info = await NanoWalletService.getInfoFromSeedOrMnemonic(
DerivationType.bip39,
mnemonic: mnemonic,
seedKey: seedKey,
);
var bip39Info = await NanoWalletService.getInfoFromSeedOrMnemonic(DerivationType.bip39,
mnemonic: mnemonic,
seedKey: seedKey,
node: node);
var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic(
DerivationType.nano,
mnemonic: mnemonic,
seedKey: seedKey,
node: node,
);
if (standardInfo["address"] != null) {

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cw_nano/nano_wallet.dart';
@ -121,11 +122,11 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
} else {
if (type == WalletType.nano) {
return nano!.createNanoRestoreWalletFromKeysCredentials(
name: name,
password: password,
seedKey: options['seedKey'] as String,
derivationType: options["derivationType"] as DerivationType,
);
name: name,
password: password,
seedKey: options['seedKey'] as String,
derivationType: options["derivationType"] as DerivationType,
);
}
}
}
@ -137,6 +138,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
Future<List<DerivationType>> getDerivationType(dynamic options) async {
final seedKey = options['seedKey'] as String?;
final mnemonic = options['seed'] as String?;
var appStore = getIt.get<AppStore>();
var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type);
switch (type) {
// case WalletType.bitcoin:
@ -147,7 +150,10 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
// name: name, mnemonic: seed, password: password);
case WalletType.nano:
return await NanoWalletService.compareDerivationMethods(
mnemonic: mnemonic, seedKey: seedKey);
mnemonic: mnemonic,
seedKey: seedKey,
node: node,
);
default:
break;
}