more fixes

This commit is contained in:
fosse 2023-08-02 13:16:43 -04:00
parent 9c3322b2b6
commit 94db74160a
5 changed files with 67 additions and 110 deletions

View file

@ -12,16 +12,13 @@ import 'package:flutter/services.dart';
int _boolToInt(bool value) => value ? 1 : 0; int _boolToInt(bool value) => value ? 1 : 0;
final getFileNameNative = moneroApi final getFileNameNative =
.lookup<NativeFunction<get_filename>>('get_filename') moneroApi.lookup<NativeFunction<get_filename>>('get_filename').asFunction<GetFilename>();
.asFunction<GetFilename>();
final getSeedNative = final getSeedNative = moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
moneroApi.lookup<NativeFunction<get_seed>>('seed').asFunction<GetSeed>();
final getAddressNative = moneroApi final getAddressNative =
.lookup<NativeFunction<get_address>>('get_address') moneroApi.lookup<NativeFunction<get_address>>('get_address').asFunction<GetAddress>();
.asFunction<GetAddress>();
final getFullBalanceNative = moneroApi final getFullBalanceNative = moneroApi
.lookup<NativeFunction<get_full_balanace>>('get_full_balance') .lookup<NativeFunction<get_full_balanace>>('get_full_balance')
@ -39,41 +36,34 @@ final getNodeHeightNative = moneroApi
.lookup<NativeFunction<get_node_height>>('get_node_height') .lookup<NativeFunction<get_node_height>>('get_node_height')
.asFunction<GetNodeHeight>(); .asFunction<GetNodeHeight>();
final isConnectedNative = moneroApi final isConnectedNative =
.lookup<NativeFunction<is_connected>>('is_connected') moneroApi.lookup<NativeFunction<is_connected>>('is_connected').asFunction<IsConnected>();
.asFunction<IsConnected>();
final setupNodeNative = moneroApi final setupNodeNative =
.lookup<NativeFunction<setup_node>>('setup_node') moneroApi.lookup<NativeFunction<setup_node>>('setup_node').asFunction<SetupNode>();
.asFunction<SetupNode>();
final startRefreshNative = moneroApi final startRefreshNative =
.lookup<NativeFunction<start_refresh>>('start_refresh') moneroApi.lookup<NativeFunction<start_refresh>>('start_refresh').asFunction<StartRefresh>();
.asFunction<StartRefresh>();
final connecToNodeNative = moneroApi final connecToNodeNative = moneroApi
.lookup<NativeFunction<connect_to_node>>('connect_to_node') .lookup<NativeFunction<connect_to_node>>('connect_to_node')
.asFunction<ConnectToNode>(); .asFunction<ConnectToNode>();
final setRefreshFromBlockHeightNative = moneroApi final setRefreshFromBlockHeightNative = moneroApi
.lookup<NativeFunction<set_refresh_from_block_height>>( .lookup<NativeFunction<set_refresh_from_block_height>>('set_refresh_from_block_height')
'set_refresh_from_block_height')
.asFunction<SetRefreshFromBlockHeight>(); .asFunction<SetRefreshFromBlockHeight>();
final setRecoveringFromSeedNative = moneroApi final setRecoveringFromSeedNative = moneroApi
.lookup<NativeFunction<set_recovering_from_seed>>( .lookup<NativeFunction<set_recovering_from_seed>>('set_recovering_from_seed')
'set_recovering_from_seed')
.asFunction<SetRecoveringFromSeed>(); .asFunction<SetRecoveringFromSeed>();
final storeNative = final storeNative = moneroApi.lookup<NativeFunction<store_c>>('store').asFunction<Store>();
moneroApi.lookup<NativeFunction<store_c>>('store').asFunction<Store>();
final setPasswordNative = final setPasswordNative =
moneroApi.lookup<NativeFunction<set_password>>('set_password').asFunction<SetPassword>(); moneroApi.lookup<NativeFunction<set_password>>('set_password').asFunction<SetPassword>();
final setListenerNative = moneroApi final setListenerNative =
.lookup<NativeFunction<set_listener>>('set_listener') moneroApi.lookup<NativeFunction<set_listener>>('set_listener').asFunction<SetListener>();
.asFunction<SetListener>();
final getSyncingHeightNative = moneroApi final getSyncingHeightNative = moneroApi
.lookup<NativeFunction<get_syncing_height>>('get_syncing_height') .lookup<NativeFunction<get_syncing_height>>('get_syncing_height')
@ -84,8 +74,7 @@ final isNeededToRefreshNative = moneroApi
.asFunction<IsNeededToRefresh>(); .asFunction<IsNeededToRefresh>();
final isNewTransactionExistNative = moneroApi final isNewTransactionExistNative = moneroApi
.lookup<NativeFunction<is_new_transaction_exist>>( .lookup<NativeFunction<is_new_transaction_exist>>('is_new_transaction_exist')
'is_new_transaction_exist')
.asFunction<IsNewTransactionExist>(); .asFunction<IsNewTransactionExist>();
final getSecretViewKeyNative = moneroApi final getSecretViewKeyNative = moneroApi
@ -108,9 +97,8 @@ final closeCurrentWalletNative = moneroApi
.lookup<NativeFunction<close_current_wallet>>('close_current_wallet') .lookup<NativeFunction<close_current_wallet>>('close_current_wallet')
.asFunction<CloseCurrentWallet>(); .asFunction<CloseCurrentWallet>();
final onStartupNative = moneroApi final onStartupNative =
.lookup<NativeFunction<on_startup>>('on_startup') moneroApi.lookup<NativeFunction<on_startup>>('on_startup').asFunction<OnStartup>();
.asFunction<OnStartup>();
final rescanBlockchainAsyncNative = moneroApi final rescanBlockchainAsyncNative = moneroApi
.lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain') .lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain')
@ -124,9 +112,8 @@ final setTrustedDaemonNative = moneroApi
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon') .lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
.asFunction<SetTrustedDaemon>(); .asFunction<SetTrustedDaemon>();
final trustedDaemonNative = moneroApi final trustedDaemonNative =
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon') moneroApi.lookup<NativeFunction<trusted_daemon>>('trusted_daemon').asFunction<TrustedDaemon>();
.asFunction<TrustedDaemon>();
int getSyncingHeight() => getSyncingHeightNative(); int getSyncingHeight() => getSyncingHeightNative();
@ -141,11 +128,9 @@ String getSeed() => convertUTF8ToString(pointer: getSeedNative());
String getAddress({int accountIndex = 0, int addressIndex = 0}) => String getAddress({int accountIndex = 0, int addressIndex = 0}) =>
convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex)); convertUTF8ToString(pointer: getAddressNative(accountIndex, addressIndex));
int getFullBalance({int accountIndex = 0}) => int getFullBalance({int accountIndex = 0}) => getFullBalanceNative(accountIndex);
getFullBalanceNative(accountIndex);
int getUnlockedBalance({int accountIndex = 0}) => int getUnlockedBalance({int accountIndex = 0}) => getUnlockedBalanceNative(accountIndex);
getUnlockedBalanceNative(accountIndex);
int getCurrentHeight() => getCurrentHeightNative(); int getCurrentHeight() => getCurrentHeightNative();
@ -172,14 +157,14 @@ bool setupNodeSync(
} }
final errorMessagePointer = ''.toNativeUtf8(); final errorMessagePointer = ''.toNativeUtf8();
final isSetupNode = setupNodeNative( // final isSetupNode = setupNodeNative(
addressPointer, // addressPointer,
loginPointer, // loginPointer,
passwordPointer, // passwordPointer,
_boolToInt(useSSL), // _boolToInt(useSSL),
_boolToInt(isLightWallet), // _boolToInt(isLightWallet),
errorMessagePointer) != // errorMessagePointer) !=
0; // 0;
calloc.free(addressPointer); calloc.free(addressPointer);
@ -191,20 +176,20 @@ bool setupNodeSync(
calloc.free(passwordPointer); calloc.free(passwordPointer);
} }
if (!isSetupNode) { // if (!isSetupNode) {
throw SetupWalletException( // throw SetupWalletException(
message: convertUTF8ToString(pointer: errorMessagePointer)); // message: convertUTF8ToString(pointer: errorMessagePointer));
} // }
return isSetupNode; // return isSetupNode;
return true;
} }
void startRefreshSync() => startRefreshNative(); void startRefreshSync() => startRefreshNative();
Future<bool> connectToNode() async => connecToNodeNative() != 0; Future<bool> connectToNode() async => connecToNodeNative() != 0;
void setRefreshFromBlockHeight({required int height}) => void setRefreshFromBlockHeight({required int height}) => setRefreshFromBlockHeightNative(height);
setRefreshFromBlockHeightNative(height);
void setRecoveringFromSeed({required bool isRecovery}) => void setRecoveringFromSeed({required bool isRecovery}) =>
setRecoveringFromSeedNative(_boolToInt(isRecovery)); setRecoveringFromSeedNative(_boolToInt(isRecovery));
@ -220,7 +205,7 @@ void setPasswordSync(String password) {
final errorMessagePointer = calloc<Utf8Box>(); final errorMessagePointer = calloc<Utf8Box>();
final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0; final changed = setPasswordNative(passwordPointer, errorMessagePointer) != 0;
calloc.free(passwordPointer); calloc.free(passwordPointer);
if (!changed) { if (!changed) {
final message = errorMessagePointer.ref.getValue(); final message = errorMessagePointer.ref.getValue();
calloc.free(errorMessagePointer); calloc.free(errorMessagePointer);
@ -232,24 +217,19 @@ void setPasswordSync(String password) {
void closeCurrentWallet() => closeCurrentWalletNative(); void closeCurrentWallet() => closeCurrentWalletNative();
String getSecretViewKey() => String getSecretViewKey() => convertUTF8ToString(pointer: getSecretViewKeyNative());
convertUTF8ToString(pointer: getSecretViewKeyNative());
String getPublicViewKey() => String getPublicViewKey() => convertUTF8ToString(pointer: getPublicViewKeyNative());
convertUTF8ToString(pointer: getPublicViewKeyNative());
String getSecretSpendKey() => String getSecretSpendKey() => convertUTF8ToString(pointer: getSecretSpendKeyNative());
convertUTF8ToString(pointer: getSecretSpendKeyNative());
String getPublicSpendKey() => String getPublicSpendKey() => convertUTF8ToString(pointer: getPublicSpendKeyNative());
convertUTF8ToString(pointer: getPublicSpendKeyNative());
class SyncListener { class SyncListener {
SyncListener(this.onNewBlock, this.onNewTransaction) SyncListener(this.onNewBlock, this.onNewTransaction)
: _cachedBlockchainHeight = 0, : _cachedBlockchainHeight = 0,
_lastKnownBlockHeight = 0, _lastKnownBlockHeight = 0,
_initialSyncHeight = 0; _initialSyncHeight = 0;
void Function(int, int, double) onNewBlock; void Function(int, int, double) onNewBlock;
void Function() onNewTransaction; void Function() onNewTransaction;
@ -271,8 +251,7 @@ class SyncListener {
_cachedBlockchainHeight = 0; _cachedBlockchainHeight = 0;
_lastKnownBlockHeight = 0; _lastKnownBlockHeight = 0;
_initialSyncHeight = 0; _initialSyncHeight = 0;
_updateSyncInfoTimer ??= _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async {
Timer.periodic(Duration(milliseconds: 1200), (_) async {
if (isNewTransactionExist()) { if (isNewTransactionExist()) {
onNewTransaction(); onNewTransaction();
} }
@ -311,8 +290,8 @@ class SyncListener {
void stop() => _updateSyncInfoTimer?.cancel(); void stop() => _updateSyncInfoTimer?.cancel();
} }
SyncListener setListeners(void Function(int, int, double) onNewBlock, SyncListener setListeners(
void Function() onNewTransaction) { void Function(int, int, double) onNewBlock, void Function() onNewTransaction) {
final listener = SyncListener(onNewBlock, onNewTransaction); final listener = SyncListener(onNewBlock, onNewTransaction);
setListenerNative(); setListenerNative();
return listener; return listener;
@ -351,7 +330,7 @@ Future<void> setupNode(
bool isLightWallet = false}) => bool isLightWallet = false}) =>
compute<Map<String, Object?>, void>(_setupNodeSync, { compute<Map<String, Object?>, void>(_setupNodeSync, {
'address': address, 'address': address,
'login': login , 'login': login,
'password': password, 'password': password,
'useSSL': useSSL, 'useSSL': useSSL,
'isLightWallet': isLightWallet 'isLightWallet': isLightWallet
@ -371,4 +350,4 @@ String getSubaddressLabel(int accountIndex, int addressIndex) {
Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted)); Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
Future<bool> trustedDaemon() async => trustedDaemonNative() != 0; Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;

View file

@ -11,10 +11,6 @@ class CWNano extends Nano {
return NanoWalletService(walletInfoSource); return NanoWalletService(walletInfoSource);
} }
NanoWalletDetails getNanoWalletDetails(Object wallet) {
throw UnimplementedError();
}
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) { String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
throw UnimplementedError(); throw UnimplementedError();
} }

View file

@ -1,45 +1,26 @@
import 'package:cw_core/crypto_currency.dart';
import 'package:cake_wallet/view_model/send/output.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.dart';
import 'package:cw_nano/nano_wallet_info.dart';
import 'package:cw_nano/nano_wallet_service.dart'; import 'package:cw_nano/nano_wallet_service.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_credentials.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/wallet_info.dart';
import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/wallet_service.dart';
import 'package:cw_core/output_info.dart';
import 'package:hive/hive.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_balance.dart';
import 'package:cw_nano/nano_wallet_creation_credentials.dart'; import 'package:cw_nano/nano_wallet_creation_credentials.dart';
import 'package:cw_nano/nano_transaction_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'; part 'cw_nano.dart';
Nano? nano = CWNano(); 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 { abstract class Nano {
// NanoAccountList getAccountList(Object wallet); // NanoAccountList getAccountList(Object wallet);
@ -47,13 +28,11 @@ abstract class Nano {
TransactionHistoryBase getTransactionHistory(Object wallet); TransactionHistoryBase getTransactionHistory(Object wallet);
NanoWalletDetails getNanoWalletDetails(Object wallet);
WalletCredentials createNanoNewWalletCredentials({ WalletCredentials createNanoNewWalletCredentials({
required String name, required String name,
String password, String password,
}); });
WalletCredentials createNanoRestoreWalletFromSeedCredentials({ WalletCredentials createNanoRestoreWalletFromSeedCredentials({
required String name, required String name,
required String password, required String password,
@ -66,7 +45,6 @@ abstract class Nano {
void onStartup(); void onStartup();
List<String> getNanoWordList(String language); List<String> getNanoWordList(String language);
Map<String, String> getKeys(Object wallet); Map<String, String> getKeys(Object wallet);
Object createNanoTransactionCredentials(List<Output> outputs); Object createNanoTransactionCredentials(List<Output> outputs);
} }
@ -79,3 +57,4 @@ abstract class NanoAccountList {
Future<void> addAccount(Object wallet, {required String label}); Future<void> addAccount(Object wallet, {required String label});
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label}); Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
} }

View file

@ -63,7 +63,7 @@ class NanoChangeRepPage extends BasePage {
// final CryptoCurrency type; // final CryptoCurrency type;
@override @override
String get title => S.current.change; String get title => S.current.change_rep;
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
@ -102,7 +102,7 @@ class NanoChangeRepPage extends BasePage {
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertWithTwoActions( return AlertWithTwoActions(
alertTitle: S.of(context).remove_node, alertTitle: S.of(context).change_rep,
alertContent: S.of(context).remove_node_message, alertContent: S.of(context).remove_node_message,
rightButtonText: S.of(context).change, rightButtonText: S.of(context).change,
leftButtonText: S.of(context).cancel, leftButtonText: S.of(context).cancel,

View file

@ -579,6 +579,11 @@ Future<void> generateNano(bool hasImplementation) async {
const nanoCommonHeaders = """ const nanoCommonHeaders = """
"""; """;
const nanoCWHeaders = """ 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:mobx/mobx.dart';
import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_nano/nano_wallet_info.dart'; import 'package:cw_nano/nano_wallet_info.dart';
@ -601,8 +606,6 @@ abstract class Nano {
TransactionHistoryBase getTransactionHistory(Object wallet); TransactionHistoryBase getTransactionHistory(Object wallet);
NanoWalletDetails getNanoWalletDetails(Object wallet);
WalletCredentials createNanoNewWalletCredentials({ WalletCredentials createNanoNewWalletCredentials({
required String name, required String name,
String password, String password,