more fixes

This commit is contained in:
fosse 2023-08-16 13:23:53 -04:00
parent 6a63e08e74
commit a15a1053a4
5 changed files with 23 additions and 16 deletions

View file

@ -250,7 +250,7 @@ Node? getEthereumDefaultNode({required Box<Node> nodes}) {
Node? getNanoDefaultNode({required Box<Node> nodes}) { Node? getNanoDefaultNode({required Box<Node> nodes}) {
return nodes.values.firstWhereOrNull((Node node) => node.uriRaw == nanoDefaultNodeUri) ?? return nodes.values.firstWhereOrNull((Node node) => node.uriRaw == nanoDefaultNodeUri) ??
nodes.values.firstWhereOrNull((node) => node.type == WalletType.ethereum); nodes.values.firstWhereOrNull((node) => node.type == WalletType.nano);
} }
Node getMoneroDefaultNode({required Box<Node> nodes}) { Node getMoneroDefaultNode({required Box<Node> nodes}) {
@ -430,6 +430,7 @@ Future<void> checkCurrentNodes(Box<Node> nodeSource, SharedPreferences sharedPre
sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey); sharedPreferences.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
final currentHavenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey); final currentHavenNodeId = sharedPreferences.getInt(PreferencesKey.currentHavenNodeIdKey);
final currentEthereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey); final currentEthereumNodeId = sharedPreferences.getInt(PreferencesKey.currentEthereumNodeIdKey);
final currentNanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNanoNodeIdKey);
final currentMoneroNode = final currentMoneroNode =
nodeSource.values.firstWhereOrNull((node) => node.key == currentMoneroNodeId); nodeSource.values.firstWhereOrNull((node) => node.key == currentMoneroNodeId);
final currentBitcoinElectrumServer = final currentBitcoinElectrumServer =
@ -440,6 +441,8 @@ Future<void> checkCurrentNodes(Box<Node> nodeSource, SharedPreferences sharedPre
nodeSource.values.firstWhereOrNull((node) => node.key == currentHavenNodeId); nodeSource.values.firstWhereOrNull((node) => node.key == currentHavenNodeId);
final currentEthereumNodeServer = final currentEthereumNodeServer =
nodeSource.values.firstWhereOrNull((node) => node.key == currentEthereumNodeId); nodeSource.values.firstWhereOrNull((node) => node.key == currentEthereumNodeId);
final currentNanoNodeServer =
nodeSource.values.firstWhereOrNull((node) => node.key == currentNanoNodeId);
if (currentMoneroNode == null) { if (currentMoneroNode == null) {
final newCakeWalletNode = Node(uri: newCakeWalletMoneroUri, type: WalletType.monero); final newCakeWalletNode = Node(uri: newCakeWalletMoneroUri, type: WalletType.monero);
@ -473,11 +476,11 @@ Future<void> checkCurrentNodes(Box<Node> nodeSource, SharedPreferences sharedPre
await sharedPreferences.setInt(PreferencesKey.currentEthereumNodeIdKey, node.key as int); await sharedPreferences.setInt(PreferencesKey.currentEthereumNodeIdKey, node.key as int);
} }
if (currentEthereumNodeServer == null) { if (currentNanoNodeServer == null) {
final node = Node(uri: ethereumDefaultNodeUri, type: WalletType.ethereum); final node = Node(uri: nanoDefaultNodeUri, type: WalletType.nano);
await nodeSource.add(node); await nodeSource.add(node);
await sharedPreferences.setInt( await sharedPreferences.setInt(
PreferencesKey.currentEthereumNodeIdKey, node.key as int); PreferencesKey.currentNanoNodeIdKey, node.key as int);
} }
} }

View file

@ -36,9 +36,9 @@ class WalletRestoreChooseDerivationPage extends BasePage {
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
); );
} else if (snapshot.hasError) { } else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}'); return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData || snapshot.data!.isEmpty) { } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Text('Error! No derivations available!'); return Center(child: Text('Error! No derivations available!'));
} else { } else {
return ListView.separated( return ListView.separated(
shrinkWrap: true, shrinkWrap: true,
@ -62,8 +62,10 @@ class WalletRestoreChooseDerivationPage extends BasePage {
title: Center( title: Center(
child: Text( child: Text(
"${derivation.derivationType.toString().split('.').last}", "${derivation.derivationType.toString().split('.').last}",
style: style: Theme.of(context)
Theme.of(context).primaryTextTheme.labelMedium!.copyWith(fontSize: 18), .primaryTextTheme
.labelMedium!
.copyWith(fontSize: 18),
), ),
), ),
subtitle: Column( subtitle: Column(

View file

@ -281,6 +281,7 @@ class WalletRestorePage extends BasePage {
} }
credentials['derivationType'] = this.derivationType; credentials['derivationType'] = this.derivationType;
credentials['walletType'] = walletRestoreViewModel.type;
return credentials; return credentials;
} }

View file

@ -33,16 +33,15 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
Future<List<Derivation>> get derivations async { Future<List<Derivation>> get derivations async {
var list = <Derivation>[]; var list = <Derivation>[];
var walletType = credentials["walletType"] as WalletType;
var appStore = getIt.get<AppStore>(); var appStore = getIt.get<AppStore>();
var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type); var node = appStore.settingsStore.getCurrentNode(walletType);
switch ((await getIt.get<AppStore>().wallet!.type)) { switch (walletType) {
case WalletType.nano: case WalletType.nano:
String? mnemonic = credentials['seed'] as String?; String? mnemonic = credentials['seed'] as String?;
String? seedKey = credentials['seedKey'] as String?; String? seedKey = credentials['seedKey'] as String?;
var bip39Info = await NanoWalletService.getInfoFromSeedOrMnemonic(DerivationType.bip39, var bip39Info = await NanoWalletService.getInfoFromSeedOrMnemonic(DerivationType.bip39,
mnemonic: mnemonic, mnemonic: mnemonic, seedKey: seedKey, node: node);
seedKey: seedKey,
node: node);
var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic( var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic(
DerivationType.nano, DerivationType.nano,
mnemonic: mnemonic, mnemonic: mnemonic,
@ -50,7 +49,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
node: node, node: node,
); );
if (standardInfo["address"] != null) { if (standardInfo["balance"] != null) {
list.add(Derivation( list.add(Derivation(
NanoUtil.getRawAsUsableString(standardInfo["balance"] as String, NanoUtil.rawPerNano), NanoUtil.getRawAsUsableString(standardInfo["balance"] as String, NanoUtil.rawPerNano),
standardInfo["address"] as String, standardInfo["address"] as String,
@ -77,6 +76,7 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store {
default: default:
break; break;
} }
return list; return list;
} }
} }

View file

@ -138,8 +138,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
Future<List<DerivationType>> getDerivationType(dynamic options) async { Future<List<DerivationType>> getDerivationType(dynamic options) async {
final seedKey = options['seedKey'] as String?; final seedKey = options['seedKey'] as String?;
final mnemonic = options['seed'] as String?; final mnemonic = options['seed'] as String?;
WalletType walletType = options['walletType'] as WalletType;
var appStore = getIt.get<AppStore>(); var appStore = getIt.get<AppStore>();
var node = appStore.settingsStore.getCurrentNode(appStore.wallet!.type); var node = appStore.settingsStore.getCurrentNode(walletType);
switch (type) { switch (type) {
// case WalletType.bitcoin: // case WalletType.bitcoin: