From 9697baa5656da43a1471c7e5e61713e5be9a97b0 Mon Sep 17 00:00:00 2001 From: fosse Date: Wed, 6 Sep 2023 10:12:36 -0400 Subject: [PATCH] nano fixes pt.2 --- cw_core/lib/node.dart | 21 +++--- cw_nano/lib/nano_wallet.dart | 4 +- .../lib/nano_wallet_creation_credentials.dart | 72 +++++++++---------- cw_nano/lib/nano_wallet_service.dart | 42 +---------- cw_nano/lib/pending_nano_transaction.dart | 2 - lib/entities/priority_for_wallet_type.dart | 7 +- lib/nano/nano.dart | 1 + .../desktop_wallet_selection_dropdown.dart | 6 ++ .../nodes/widgets/pow_node_indicator.dart | 18 ----- .../settings/connection_sync_page.dart | 17 +++-- lib/view_model/restore/restore_mode.dart | 2 +- lib/view_model/send/send_view_model.dart | 2 +- lib/view_model/wallet_keys_view_model.dart | 5 +- lib/view_model/wallet_restore_view_model.dart | 26 ++++--- scripts/ios/app_config.sh | 2 +- scripts/macos/app_config.sh | 2 +- tool/configure.dart | 1 + 17 files changed, 90 insertions(+), 140 deletions(-) delete mode 100644 lib/src/screens/nodes/widgets/pow_node_indicator.dart diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 3f221a695..ec7c905dc 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -139,6 +139,7 @@ class Node extends HiveObject with Keyable { case WalletType.ethereum: return requestElectrumServer(); case WalletType.nano: + case WalletType.banano: return requestNanoNode(); default: return false; @@ -181,24 +182,20 @@ class Node extends HiveObject with Keyable { } Future requestNanoNode() async { - return http - .post( + http.Response response = await http.post( uri, headers: {'Content-type': 'application/json'}, body: json.encode( { - "action": "account_balance", - "account": "nano_38713x95zyjsqzx6nm1dsom1jmm668owkeb9913ax6nfgj15az3nu8xkx579" + "action": "block_count", }, ), - ) - .then((http.Response response) { - if (response.statusCode == 200) { - return true; - } else { - return false; - } - }); + ); + if (response.statusCode == 200) { + return true; + } else { + return false; + } } Future requestNodeWithProxy(String proxy) async { diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index bcae9aff8..78855334b 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -212,7 +212,6 @@ abstract class NanoWalletBase return PendingNanoTransaction( amount: runningAmount, - fee: 0, id: "", nanoClient: _client, blocks: blocks, @@ -280,6 +279,9 @@ abstract class NanoWalletBase return NanoWalletKeys(seedKey: _seedKey!); } + @override + String? get privateKey => _seedKey!; + @override Future rescan({required int height}) async { fetchTransactions(); diff --git a/cw_nano/lib/nano_wallet_creation_credentials.dart b/cw_nano/lib/nano_wallet_creation_credentials.dart index 4524608fe..84531e24a 100644 --- a/cw_nano/lib/nano_wallet_creation_credentials.dart +++ b/cw_nano/lib/nano_wallet_creation_credentials.dart @@ -1,47 +1,41 @@ import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; -// class NanoNewWalletCredentials extends WalletCredentials { -// NanoNewWalletCredentials({required String name, WalletInfo? walletInfo}) -// : super(name: name, walletInfo: walletInfo); -// } +class NanoNewWalletCredentials extends WalletCredentials { + NanoNewWalletCredentials({required String name, String? password}) + : super(name: name, password: password); +} -// class NanoRestoreWalletFromSeedCredentials extends WalletCredentials { -// NanoRestoreWalletFromSeedCredentials( -// {required String name, -// required String password, -// required this.mnemonic, -// WalletInfo? walletInfo}) -// : super(name: name, password: password, walletInfo: walletInfo); +class NanoRestoreWalletFromSeedCredentials extends WalletCredentials { + NanoRestoreWalletFromSeedCredentials({ + required String name, + required this.mnemonic, + int height = 0, + String? password, + DerivationType? derivationType, + }) : super( + name: name, + password: password, + height: height, + derivationType: derivationType, + ); -// final String mnemonic; -// } + final String mnemonic; +} -// class NanoRestoreWalletFromWIFCredentials extends WalletCredentials { -// NanoRestoreWalletFromWIFCredentials( -// {required String name, required String password, required this.wif, WalletInfo? walletInfo}) -// : super(name: name, password: password, walletInfo: walletInfo); +class NanoWalletLoadingException implements Exception { + @override + String toString() => 'Failure to load the wallet.'; +} -// final String wif; -// } +class NanoRestoreWalletFromKeysCredentials extends WalletCredentials { + NanoRestoreWalletFromKeysCredentials({ + required String name, + required String password, + required this.seedKey, + this.derivationType, + }) : super(name: name, password: password); - -// class NanoNewWalletCredentials extends WalletCredentials { -// NanoNewWalletCredentials({required String name, required this.language, String? password}) -// : super(name: name, password: password); - -// final String language; -// } - -// class NanoRestoreWalletFromSeedCredentials extends WalletCredentials { -// NanoRestoreWalletFromSeedCredentials( -// {required String name, required this.mnemonic, int height = 0, String? password}) -// : super(name: name, password: password, height: height); - -// final String mnemonic; -// } - -// class NanoWalletLoadingException implements Exception { -// @override -// String toString() => 'Failure to load the wallet.'; -// } + final String seedKey; + final DerivationType? derivationType; +} \ No newline at end of file diff --git a/cw_nano/lib/nano_wallet_service.dart b/cw_nano/lib/nano_wallet_service.dart index 59bbd900d..3a81ed6fb 100644 --- a/cw_nano/lib/nano_wallet_service.dart +++ b/cw_nano/lib/nano_wallet_service.dart @@ -3,58 +3,18 @@ import 'dart:io'; import 'package:cw_core/node.dart'; import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/wallet_base.dart'; -import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/wallet_type.dart'; -import 'package:cw_nano/nano_balance.dart'; import 'package:cw_nano/nano_client.dart'; import 'package:cw_nano/nano_mnemonic.dart' as nm; import 'package:cw_nano/nano_util.dart'; import 'package:cw_nano/nano_wallet.dart'; +import 'package:cw_nano/nano_wallet_creation_credentials.dart'; import 'package:hive/hive.dart'; import 'package:bip39/bip39.dart' as bip39; import 'package:nanodart/nanodart.dart'; -class NanoNewWalletCredentials extends WalletCredentials { - NanoNewWalletCredentials({required String name, String? password}) - : super(name: name, password: password); -} - -class NanoRestoreWalletFromSeedCredentials extends WalletCredentials { - NanoRestoreWalletFromSeedCredentials({ - required String name, - required this.mnemonic, - int height = 0, - String? password, - DerivationType? derivationType, - }) : super( - name: name, - password: password, - height: height, - derivationType: derivationType, - ); - - final String mnemonic; -} - -class NanoWalletLoadingException implements Exception { - @override - String toString() => 'Failure to load the wallet.'; -} - -class NanoRestoreWalletFromKeysCredentials extends WalletCredentials { - NanoRestoreWalletFromKeysCredentials({ - required String name, - required String password, - required this.seedKey, - this.derivationType, - }) : super(name: name, password: password); - - final String seedKey; - final DerivationType? derivationType; -} - class NanoWalletService extends WalletService { NanoWalletService(this.walletInfoSource); diff --git a/cw_nano/lib/pending_nano_transaction.dart b/cw_nano/lib/pending_nano_transaction.dart index 478288754..727f02534 100644 --- a/cw_nano/lib/pending_nano_transaction.dart +++ b/cw_nano/lib/pending_nano_transaction.dart @@ -6,14 +6,12 @@ class PendingNanoTransaction with PendingTransaction { PendingNanoTransaction({ required this.nanoClient, required this.amount, - required this.fee, required this.id, required this.blocks, }); final NanoClient nanoClient; final BigInt amount; - final int fee; final String id; final List> blocks; String hex = "unused"; diff --git a/lib/entities/priority_for_wallet_type.dart b/lib/entities/priority_for_wallet_type.dart index 5eded3a4a..378cf0ea2 100644 --- a/lib/entities/priority_for_wallet_type.dart +++ b/lib/entities/priority_for_wallet_type.dart @@ -2,7 +2,6 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/monero/monero.dart'; -import 'package:cake_wallet/nano/nano.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/wallet_type.dart'; @@ -18,10 +17,10 @@ List priorityForWalletType(WalletType type) { return haven!.getTransactionPriorities(); case WalletType.ethereum: return ethereum!.getTransactionPriorities(); - // we just get ethereum's here since there's no transaction priority in nano - // and so there's no point in bothering to implement it: + // no such thing for nano/banano: case WalletType.nano: - return ethereum!.getTransactionPriorities(); + case WalletType.banano: + return []; default: return []; } diff --git a/lib/nano/nano.dart b/lib/nano/nano.dart index 15a39ca0d..e8b9977ac 100644 --- a/lib/nano/nano.dart +++ b/lib/nano/nano.dart @@ -13,6 +13,7 @@ import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/output_info.dart'; import 'package:hive/hive.dart'; import 'package:cw_nano/nano_transaction_credentials.dart'; +import 'package:cw_nano/nano_wallet_creation_credentials.dart'; part 'cw_nano.dart'; diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index 684f7cd08..b22acdc8b 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -33,6 +33,8 @@ class _DesktopWalletSelectionDropDownState extends State Image.asset( @@ -141,6 +143,10 @@ class _DesktopWalletSelectionDropDownState extends State Navigator.of(context).pushNamed(Routes.managePowNodes), + if (!dashboardViewModel.hasPowNodes) return const SizedBox(); + + return Column( + children: [ + SettingsCellWithArrow( + title: S.current.manage_pow_nodes, + handler: (context) => Navigator.of(context).pushNamed(Routes.managePowNodes), + ), + const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)), + ], ); }, ), - const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)), ], ), ); diff --git a/lib/view_model/restore/restore_mode.dart b/lib/view_model/restore/restore_mode.dart index 3a4746c1d..d8344841d 100644 --- a/lib/view_model/restore/restore_mode.dart +++ b/lib/view_model/restore/restore_mode.dart @@ -1 +1 @@ -enum WalletRestoreMode { seed, keys, txids, seedKey } \ No newline at end of file +enum WalletRestoreMode { seed, keys, txids } \ No newline at end of file diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 487be1cfe..2030af1d7 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -64,7 +64,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor final priority = _settingsStore.priority[wallet.type]; final priorities = priorityForWalletType(wallet.type); - if (!priorityForWalletType(wallet.type).contains(priority)) { + if (!priorityForWalletType(wallet.type).contains(priority) && priorities.isNotEmpty) { _settingsStore.priority[wallet.type] = priorities.first; } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index fbf9311de..e2938c74e 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -107,7 +107,6 @@ abstract class WalletKeysViewModelBase with Store { } if (_appStore.wallet!.type == WalletType.nano || _appStore.wallet!.type == WalletType.banano) { - final keys = nano!.getKeys(_appStore.wallet!); // we don't necessarily have the seed phrase for nano / banano: if (_appStore.wallet!.seed != null) { @@ -118,8 +117,8 @@ abstract class WalletKeysViewModelBase with Store { // we always have the hex version of the seed: items.addAll([ - if (keys['private_key'] != null) - StandartListItem(title: S.current.spend_key_private, value: keys['private_key']!), + if (_appStore.wallet!.privateKey != null) + StandartListItem(title: S.current.spend_key_private, value: _appStore.wallet!.privateKey!), ]); } } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index a1270a81a..cf03a98d5 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -28,19 +28,27 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService, Box walletInfoSource, {required WalletType type}) - : availableModes = - (type == WalletType.monero || type == WalletType.haven || type == WalletType.ethereum) - ? WalletRestoreMode.values - : (type == WalletType.nano || type == WalletType.banano) - ? [WalletRestoreMode.seed, WalletRestoreMode.keys] - : [WalletRestoreMode.seed], - hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven, + : hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven, hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven, hasRestoreFromPrivateKey = type == WalletType.ethereum || type == WalletType.nano || type == WalletType.banano, isButtonEnabled = false, mode = WalletRestoreMode.seed, super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) { + switch (type) { + case WalletType.monero: + case WalletType.haven: + case WalletType.ethereum: + availableModes = WalletRestoreMode.values; + break; + case WalletType.nano: + case WalletType.banano: + availableModes = [WalletRestoreMode.seed, WalletRestoreMode.keys]; + break; + default: + availableModes = [WalletRestoreMode.seed]; + break; + } isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector; walletCreationService.changeWalletType(type: type); } @@ -49,7 +57,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { static const electrumSeedMnemonicLength = 24; static const electrumShortSeedMnemonicLength = 12; - final List availableModes; + late List availableModes; final bool hasSeedLanguageSelector; final bool hasBlockchainHeightLanguageSelector; final bool hasRestoreFromPrivateKey; @@ -158,7 +166,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { final mnemonic = options['seed'] as String?; WalletType walletType = options['walletType'] as WalletType; var appStore = getIt.get(); - var node = appStore.settingsStore.getCurrentNode(walletType) as Node; + var node = appStore.settingsStore.getCurrentNode(walletType); switch (type) { case WalletType.bitcoin: diff --git a/scripts/ios/app_config.sh b/scripts/ios/app_config.sh index 470f47efc..79365ab0c 100755 --- a/scripts/ios/app_config.sh +++ b/scripts/ios/app_config.sh @@ -23,7 +23,7 @@ case $APP_IOS_TYPE in CONFIG_ARGS="--monero" ;; $CAKEWALLET) - CONFIG_ARGS="--monero --bitcoin --haven --ethereum" + CONFIG_ARGS="--monero --bitcoin --haven --ethereum --nano" ;; $HAVEN) CONFIG_ARGS="--haven" diff --git a/scripts/macos/app_config.sh b/scripts/macos/app_config.sh index 8c05035c7..2af101485 100755 --- a/scripts/macos/app_config.sh +++ b/scripts/macos/app_config.sh @@ -23,7 +23,7 @@ CONFIG_ARGS="" case $APP_MACOS_TYPE in $CAKEWALLET) - CONFIG_ARGS="--monero --bitcoin --ethereum";; #--haven + CONFIG_ARGS="--monero --bitcoin --ethereum --nano";; #--haven esac cp -rf pubspec_description.yaml pubspec.yaml diff --git a/tool/configure.dart b/tool/configure.dart index 037ee0403..35ad5f3b4 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -583,6 +583,7 @@ import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/output_info.dart'; import 'package:hive/hive.dart'; import 'package:cw_nano/nano_transaction_credentials.dart'; +import 'package:cw_nano/nano_wallet_creation_credentials.dart'; """; const nanoCwPart = "part 'cw_nano.dart';"; const nanoContent = """