From 94db74160a57c5bc45d4ac6ce4270f690d60d4c8 Mon Sep 17 00:00:00 2001 From: fosse Date: Wed, 2 Aug 2023 13:16:43 -0400 Subject: [PATCH] more fixes --- cw_nano/lib/api/wallet.dart | 125 ++++++++---------- lib/nano/cw_nano.dart | 4 - lib/nano/nano.dart | 37 ++---- .../screens/nano/nano_change_rep_page.dart | 4 +- tool/configure.dart | 7 +- 5 files changed, 67 insertions(+), 110 deletions(-) diff --git a/cw_nano/lib/api/wallet.dart b/cw_nano/lib/api/wallet.dart index 7ddbf29dc..c61c7beb9 100644 --- a/cw_nano/lib/api/wallet.dart +++ b/cw_nano/lib/api/wallet.dart @@ -12,16 +12,13 @@ import 'package:flutter/services.dart'; int _boolToInt(bool value) => value ? 1 : 0; -final getFileNameNative = moneroApi - .lookup>('get_filename') - .asFunction(); +final getFileNameNative = + moneroApi.lookup>('get_filename').asFunction(); -final getSeedNative = - moneroApi.lookup>('seed').asFunction(); +final getSeedNative = moneroApi.lookup>('seed').asFunction(); -final getAddressNative = moneroApi - .lookup>('get_address') - .asFunction(); +final getAddressNative = + moneroApi.lookup>('get_address').asFunction(); final getFullBalanceNative = moneroApi .lookup>('get_full_balance') @@ -39,41 +36,34 @@ final getNodeHeightNative = moneroApi .lookup>('get_node_height') .asFunction(); -final isConnectedNative = moneroApi - .lookup>('is_connected') - .asFunction(); +final isConnectedNative = + moneroApi.lookup>('is_connected').asFunction(); -final setupNodeNative = moneroApi - .lookup>('setup_node') - .asFunction(); +final setupNodeNative = + moneroApi.lookup>('setup_node').asFunction(); -final startRefreshNative = moneroApi - .lookup>('start_refresh') - .asFunction(); +final startRefreshNative = + moneroApi.lookup>('start_refresh').asFunction(); final connecToNodeNative = moneroApi .lookup>('connect_to_node') .asFunction(); final setRefreshFromBlockHeightNative = moneroApi - .lookup>( - 'set_refresh_from_block_height') + .lookup>('set_refresh_from_block_height') .asFunction(); final setRecoveringFromSeedNative = moneroApi - .lookup>( - 'set_recovering_from_seed') + .lookup>('set_recovering_from_seed') .asFunction(); -final storeNative = - moneroApi.lookup>('store').asFunction(); +final storeNative = moneroApi.lookup>('store').asFunction(); final setPasswordNative = moneroApi.lookup>('set_password').asFunction(); -final setListenerNative = moneroApi - .lookup>('set_listener') - .asFunction(); +final setListenerNative = + moneroApi.lookup>('set_listener').asFunction(); final getSyncingHeightNative = moneroApi .lookup>('get_syncing_height') @@ -84,8 +74,7 @@ final isNeededToRefreshNative = moneroApi .asFunction(); final isNewTransactionExistNative = moneroApi - .lookup>( - 'is_new_transaction_exist') + .lookup>('is_new_transaction_exist') .asFunction(); final getSecretViewKeyNative = moneroApi @@ -108,9 +97,8 @@ final closeCurrentWalletNative = moneroApi .lookup>('close_current_wallet') .asFunction(); -final onStartupNative = moneroApi - .lookup>('on_startup') - .asFunction(); +final onStartupNative = + moneroApi.lookup>('on_startup').asFunction(); final rescanBlockchainAsyncNative = moneroApi .lookup>('rescan_blockchain') @@ -124,9 +112,8 @@ final setTrustedDaemonNative = moneroApi .lookup>('set_trusted_daemon') .asFunction(); -final trustedDaemonNative = moneroApi - .lookup>('trusted_daemon') - .asFunction(); +final trustedDaemonNative = + moneroApi.lookup>('trusted_daemon').asFunction(); int getSyncingHeight() => getSyncingHeightNative(); @@ -141,11 +128,9 @@ String getSeed() => convertUTF8ToString(pointer: getSeedNative()); String getAddress({int accountIndex = 0, int addressIndex = 0}) => convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex)); -int getFullBalance({int accountIndex = 0}) => - getFullBalanceNative(accountIndex); +int getFullBalance({int accountIndex = 0}) => getFullBalanceNative(accountIndex); -int getUnlockedBalance({int accountIndex = 0}) => - getUnlockedBalanceNative(accountIndex); +int getUnlockedBalance({int accountIndex = 0}) => getUnlockedBalanceNative(accountIndex); int getCurrentHeight() => getCurrentHeightNative(); @@ -172,14 +157,14 @@ bool setupNodeSync( } final errorMessagePointer = ''.toNativeUtf8(); - final isSetupNode = setupNodeNative( - addressPointer, - loginPointer, - passwordPointer, - _boolToInt(useSSL), - _boolToInt(isLightWallet), - errorMessagePointer) != - 0; + // final isSetupNode = setupNodeNative( + // addressPointer, + // loginPointer, + // passwordPointer, + // _boolToInt(useSSL), + // _boolToInt(isLightWallet), + // errorMessagePointer) != + // 0; calloc.free(addressPointer); @@ -191,20 +176,20 @@ bool setupNodeSync( calloc.free(passwordPointer); } - if (!isSetupNode) { - throw SetupWalletException( - message: convertUTF8ToString(pointer: errorMessagePointer)); - } + // if (!isSetupNode) { + // throw SetupWalletException( + // message: convertUTF8ToString(pointer: errorMessagePointer)); + // } - return isSetupNode; + // return isSetupNode; + return true; } void startRefreshSync() => startRefreshNative(); Future connectToNode() async => connecToNodeNative() != 0; -void setRefreshFromBlockHeight({required int height}) => - setRefreshFromBlockHeightNative(height); +void setRefreshFromBlockHeight({required int height}) => setRefreshFromBlockHeightNative(height); void setRecoveringFromSeed({required bool isRecovery}) => setRecoveringFromSeedNative(_boolToInt(isRecovery)); @@ -220,7 +205,7 @@ void setPasswordSync(String password) { final errorMessagePointer = calloc(); final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0; calloc.free(passwordPointer); - + if (!changed) { final message = errorMessagePointer.ref.getValue(); calloc.free(errorMessagePointer); @@ -232,24 +217,19 @@ void setPasswordSync(String password) { void closeCurrentWallet() => closeCurrentWalletNative(); -String getSecretViewKey() => - convertUTF8ToString(pointer: getSecretViewKeyNative()); +String getSecretViewKey() => convertUTF8ToString(pointer: getSecretViewKeyNative()); -String getPublicViewKey() => - convertUTF8ToString(pointer: getPublicViewKeyNative()); +String getPublicViewKey() => convertUTF8ToString(pointer: getPublicViewKeyNative()); -String getSecretSpendKey() => - convertUTF8ToString(pointer: getSecretSpendKeyNative()); +String getSecretSpendKey() => convertUTF8ToString(pointer: getSecretSpendKeyNative()); -String getPublicSpendKey() => - convertUTF8ToString(pointer: getPublicSpendKeyNative()); +String getPublicSpendKey() => convertUTF8ToString(pointer: getPublicSpendKeyNative()); class SyncListener { - SyncListener(this.onNewBlock, this.onNewTransaction) - : _cachedBlockchainHeight = 0, - _lastKnownBlockHeight = 0, - _initialSyncHeight = 0; - + SyncListener(this.onNewBlock, this.onNewTransaction) + : _cachedBlockchainHeight = 0, + _lastKnownBlockHeight = 0, + _initialSyncHeight = 0; void Function(int, int, double) onNewBlock; void Function() onNewTransaction; @@ -271,8 +251,7 @@ class SyncListener { _cachedBlockchainHeight = 0; _lastKnownBlockHeight = 0; _initialSyncHeight = 0; - _updateSyncInfoTimer ??= - Timer.periodic(Duration(milliseconds: 1200), (_) async { + _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { if (isNewTransactionExist()) { onNewTransaction(); } @@ -311,8 +290,8 @@ class SyncListener { void stop() => _updateSyncInfoTimer?.cancel(); } -SyncListener setListeners(void Function(int, int, double) onNewBlock, - void Function() onNewTransaction) { +SyncListener setListeners( + void Function(int, int, double) onNewBlock, void Function() onNewTransaction) { final listener = SyncListener(onNewBlock, onNewTransaction); setListenerNative(); return listener; @@ -351,7 +330,7 @@ Future setupNode( bool isLightWallet = false}) => compute, void>(_setupNodeSync, { 'address': address, - 'login': login , + 'login': login, 'password': password, 'useSSL': useSSL, 'isLightWallet': isLightWallet @@ -371,4 +350,4 @@ String getSubaddressLabel(int accountIndex, int addressIndex) { Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted)); -Future trustedDaemon() async => trustedDaemonNative() != 0; \ No newline at end of file +Future trustedDaemon() async => trustedDaemonNative() != 0; diff --git a/lib/nano/cw_nano.dart b/lib/nano/cw_nano.dart index f3a5be736..e7af788ea 100644 --- a/lib/nano/cw_nano.dart +++ b/lib/nano/cw_nano.dart @@ -11,10 +11,6 @@ class CWNano extends Nano { return NanoWalletService(walletInfoSource); } - NanoWalletDetails getNanoWalletDetails(Object wallet) { - throw UnimplementedError(); - } - String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) { throw UnimplementedError(); } diff --git a/lib/nano/nano.dart b/lib/nano/nano.dart index f94e40f49..971d0c8e9 100644 --- a/lib/nano/nano.dart +++ b/lib/nano/nano.dart @@ -1,45 +1,26 @@ -import 'package:cw_core/crypto_currency.dart'; + import 'package:cake_wallet/view_model/send/output.dart'; -import 'package:cw_core/output_info.dart'; +import 'package:cw_core/account.dart'; +import 'package:cw_nano/nano_mnemonic.dart'; import 'package:cw_nano/nano_wallet.dart'; -import 'package:cw_nano/nano_wallet_info.dart'; import 'package:cw_nano/nano_wallet_service.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/wallet_credentials.dart'; +import 'package:cw_nano/nano_wallet_info.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/wallet_service.dart'; +import 'package:cw_core/output_info.dart'; import 'package:hive/hive.dart'; +import 'package:cw_nano/api/wallet.dart' as nano_wallet_api; import 'package:cw_nano/nano_balance.dart'; import 'package:cw_nano/nano_wallet_creation_credentials.dart'; import 'package:cw_nano/nano_transaction_credentials.dart'; -import 'package:mobx/mobx.dart'; -import 'package:cw_core/wallet_credentials.dart'; -import 'package:cw_core/wallet_info.dart'; -import 'package:cw_core/transaction_history.dart'; -import 'package:cw_core/wallet_service.dart'; -import 'package:hive/hive.dart'; -import 'package:cw_nano/nano_mnemonic.dart'; part 'cw_nano.dart'; Nano? nano = CWNano(); -class Account { - Account({required this.id, required this.label, this.balance}); - final int id; - final String label; - final String? balance; -} - -abstract class NanoWalletDetails { - @observable - late Account account; - - @observable - late NanoBalance balance; -} - abstract class Nano { // NanoAccountList getAccountList(Object wallet); @@ -47,13 +28,11 @@ abstract class Nano { TransactionHistoryBase getTransactionHistory(Object wallet); - NanoWalletDetails getNanoWalletDetails(Object wallet); - WalletCredentials createNanoNewWalletCredentials({ required String name, String password, }); - + WalletCredentials createNanoRestoreWalletFromSeedCredentials({ required String name, required String password, @@ -66,7 +45,6 @@ abstract class Nano { void onStartup(); List getNanoWordList(String language); - Map getKeys(Object wallet); Object createNanoTransactionCredentials(List outputs); } @@ -79,3 +57,4 @@ abstract class NanoAccountList { Future addAccount(Object wallet, {required String label}); Future setLabelAccount(Object wallet, {required int accountIndex, required String label}); } + \ No newline at end of file diff --git a/lib/src/screens/nano/nano_change_rep_page.dart b/lib/src/screens/nano/nano_change_rep_page.dart index fdd7b5b85..92f808943 100644 --- a/lib/src/screens/nano/nano_change_rep_page.dart +++ b/lib/src/screens/nano/nano_change_rep_page.dart @@ -63,7 +63,7 @@ class NanoChangeRepPage extends BasePage { // final CryptoCurrency type; @override - String get title => S.current.change; + String get title => S.current.change_rep; @override Widget body(BuildContext context) { @@ -102,7 +102,7 @@ class NanoChangeRepPage extends BasePage { context: context, builder: (BuildContext context) { return AlertWithTwoActions( - alertTitle: S.of(context).remove_node, + alertTitle: S.of(context).change_rep, alertContent: S.of(context).remove_node_message, rightButtonText: S.of(context).change, leftButtonText: S.of(context).cancel, diff --git a/tool/configure.dart b/tool/configure.dart index e8c9f9e63..3829da6f3 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -579,6 +579,11 @@ Future generateNano(bool hasImplementation) async { const nanoCommonHeaders = """ """; const nanoCWHeaders = """ +import 'package:cw_nano/nano_mnemonic.dart'; +import 'package:cw_nano/nano_wallet.dart'; +import 'package:cw_nano/nano_wallet_service.dart'; +import 'package:cake_wallet/view_model/send/output.dart'; +import 'package:cw_core/account.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_nano/nano_wallet_info.dart'; @@ -601,8 +606,6 @@ abstract class Nano { TransactionHistoryBase getTransactionHistory(Object wallet); - NanoWalletDetails getNanoWalletDetails(Object wallet); - WalletCredentials createNanoNewWalletCredentials({ required String name, String password,