diff --git a/cw_nano/lib/nano_account_list.dart b/cw_nano/lib/nano_account_list.dart index 6b0367aac..6ee673cb4 100644 --- a/cw_nano/lib/nano_account_list.dart +++ b/cw_nano/lib/nano_account_list.dart @@ -13,7 +13,7 @@ abstract class NanoAccountListBase with Store { : accounts = ObservableList(), _isRefreshing = false, _isUpdating = false { - refresh(); + // refresh(); } @observable diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index b2ddb73ec..a5a646852 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -1,344 +1,3 @@ -// import 'dart:async'; -// import 'dart:io'; -// import 'package:cw_core/pathForWallet.dart'; -// import 'package:cw_core/transaction_priority.dart'; -// import 'package:cw_nano/nano_balance.dart'; -// import 'package:cw_nano/nano_transaction_history.dart'; -// import 'package:cw_nano/nano_transaction_info.dart'; -// import 'package:cw_nano/nano_wallet_addresses.dart'; -// import 'package:cw_nano/nano_wallet_keys.dart'; -// import 'package:mobx/mobx.dart'; -// import 'package:cw_core/pending_transaction.dart'; -// import 'package:cw_core/wallet_base.dart'; -// import 'package:cw_core/sync_status.dart'; -// import 'package:cw_core/wallet_info.dart'; -// import 'package:cw_core/node.dart'; -// import 'package:cw_core/crypto_currency.dart'; - -// part 'nano_wallet.g.dart'; - -// const moneroBlockSize = 1000; - -// class NanoWallet = NanoWalletBase with _$NanoWallet; - -// abstract class NanoWalletBase -// extends WalletBase with Store { -// NanoWalletBase({ -// required WalletInfo walletInfo, -// required String mnemonic, -// required String password, -// }) : balance = ObservableMap.of({ -// CryptoCurrency.nano: -// NanoBalance(currentBalance: BigInt.zero, receivableBalance: BigInt.zero) -// }), -// _isTransactionUpdating = false, -// _hasSyncAfterStartup = false, -// _password = password, -// _mnemonic = mnemonic, -// walletAddresses = NanoWalletAddresses(walletInfo), -// syncStatus = NotConnectedSyncStatus(), -// super(walletInfo) { -// transactionHistory = NanoTransactionHistory(); - -// // _onAccountChangeReaction = reaction((_) => walletAddresses.account, (Account? account) { -// // if (account == null) { -// // return; -// // } - -// // balance = ObservableMap.of({ -// // currency: MoneroBalance( -// // fullBalance: monero_wallet.getFullBalance(accountIndex: account.id), -// // unlockedBalance: monero_wallet.getUnlockedBalance(accountIndex: account.id)) -// // }); -// // walletAddresses.updateSubaddressList(accountIndex: account.id); -// // }); -// } - -// final String _mnemonic; -// final String _password; - -// static const int _autoSaveInterval = 30; - -// @override -// NanoWalletAddresses walletAddresses; - -// @override -// @observable -// SyncStatus syncStatus; - -// @override -// @observable -// ObservableMap balance; - -// @override -// String get seed { -// throw UnimplementedError(); -// } - -// @override -// NanoWalletKeys get keys => NanoWalletKeys( -// derivationType: "bip39", -// mnemonic: "todo", -// privateKey: "todo", -// ); -// // NanoWalletKeys get keys => NanoWalletKeys( -// // privateSpendKey: monero_wallet.getSecretSpendKey(), -// // privateViewKey: monero_wallet.getSecretViewKey(), -// // publicSpendKey: monero_wallet.getPublicSpendKey(), -// // publicViewKey: monero_wallet.getPublicViewKey()); - -// // SyncListener? _listener; -// ReactionDisposer? _onAccountChangeReaction; -// bool _isTransactionUpdating; -// bool _hasSyncAfterStartup; -// Timer? _autoSaveTimer; - -// Future init() async { -// // await walletAddresses.init(); -// // balance = ObservableMap.of({ -// // currency: MoneroBalance( -// // fullBalance: monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id), -// // unlockedBalance: -// // monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id)) -// // }); -// // _setListeners(); -// // await updateTransactions(); - -// // if (walletInfo.isRecovery) { -// // monero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery); - -// // if (monero_wallet.getCurrentHeight() <= 1) { -// // monero_wallet.setRefreshFromBlockHeight(height: walletInfo.restoreHeight); -// // } -// // } - -// // _autoSaveTimer = Timer.periodic( -// // Duration(seconds: _autoSaveInterval), -// // (_) async => await save()); -// } - -// @override -// Future? updateBalance() => null; - -// @override -// void close() { -// // _listener?.stop(); -// // _onAccountChangeReaction?.reaction.dispose(); -// // _autoSaveTimer?.cancel(); -// } - -// @override -// Future connectToNode({required Node node}) async { -// // try { -// // syncStatus = ConnectingSyncStatus(); -// // await monero_wallet.setupNode( -// // address: node.uri.toString(), useSSL: node.isSSL, isLightWallet: false); - -// // monero_wallet.setTrustedDaemon(node.trusted); -// // syncStatus = ConnectedSyncStatus(); -// // } catch (e) { -// // syncStatus = FailedSyncStatus(); -// // print(e); -// // } -// } - -// @override -// Future startSync() async { -// // try { -// // _setInitialHeight(); -// // } catch (_) {} - -// // try { -// // syncStatus = AttemptingSyncStatus(); -// // monero_wallet.startRefresh(); -// // _setListeners(); -// // _listener?.start(); -// // } catch (e) { -// // syncStatus = FailedSyncStatus(); -// // print(e); -// // rethrow; -// // } -// } - -// @override -// Future createTransaction(Object credentials) async { -// // final _credentials = credentials as MoneroTransactionCreationCredentials; -// // return null; -// throw UnimplementedError(); -// } - -// @override -// int calculateEstimatedFee(TransactionPriority priority, int? amount) { -// // FIXME: hardcoded value; -// return 0; -// } - -// @override -// Future save() async { -// // await walletAddresses.updateAddressesInBox(); -// // await backupWalletFiles(name); -// // await monero_wallet.store(); -// } - -// @override -// Future renameWalletFiles(String newWalletName) async { -// final currentWalletDirPath = await pathForWalletDir(name: name, type: type); - -// try { -// // -- rename the waller folder -- -// final currentWalletDir = Directory(await pathForWalletDir(name: name, type: type)); -// final newWalletDirPath = await pathForWalletDir(name: newWalletName, type: type); -// await currentWalletDir.rename(newWalletDirPath); - -// // -- use new waller folder to rename files with old names still -- -// final renamedWalletPath = newWalletDirPath + '/$name'; - -// final currentCacheFile = File(renamedWalletPath); -// final currentKeysFile = File('$renamedWalletPath.keys'); -// final currentAddressListFile = File('$renamedWalletPath.address.txt'); - -// final newWalletPath = await pathForWallet(name: newWalletName, type: type); - -// if (currentCacheFile.existsSync()) { -// await currentCacheFile.rename(newWalletPath); -// } -// if (currentKeysFile.existsSync()) { -// await currentKeysFile.rename('$newWalletPath.keys'); -// } -// if (currentAddressListFile.existsSync()) { -// await currentAddressListFile.rename('$newWalletPath.address.txt'); -// } -// } catch (e) { -// final currentWalletPath = await pathForWallet(name: name, type: type); - -// final currentCacheFile = File(currentWalletPath); -// final currentKeysFile = File('$currentWalletPath.keys'); -// final currentAddressListFile = File('$currentWalletPath.address.txt'); - -// final newWalletPath = await pathForWallet(name: newWalletName, type: type); - -// // Copies current wallet files into new wallet name's dir and files -// if (currentCacheFile.existsSync()) { -// await currentCacheFile.copy(newWalletPath); -// } -// if (currentKeysFile.existsSync()) { -// await currentKeysFile.copy('$newWalletPath.keys'); -// } -// if (currentAddressListFile.existsSync()) { -// await currentAddressListFile.copy('$newWalletPath.address.txt'); -// } - -// // Delete old name's dir and files -// await Directory(currentWalletDirPath).delete(recursive: true); -// } -// } - -// @override -// Future changePassword(String password) async { -// // monero_wallet.setPasswordSync(password); -// } - -// // Future getNodeHeight() async => nano_wallet.getNodeHeight(); - -// // Future isConnected() async => nano_wallet.isConnected(); - -// Future setAsRecovered() async { -// walletInfo.isRecovery = false; -// await walletInfo.save(); -// } - -// @override -// Future rescan({required int height}) async { -// // walletInfo.restoreHeight = height; -// // walletInfo.isRecovery = true; -// // monero_wallet.setRefreshFromBlockHeight(height: height); -// // monero_wallet.rescanBlockchainAsync(); -// // await startSync(); -// // _askForUpdateBalance(); -// // walletAddresses.accountList.update(); -// // await _askForUpdateTransactionHistory(); -// // await save(); -// // await walletInfo.save(); -// } - -// // String getTransactionAddress(int accountIndex, int addressIndex) => -// // monero_wallet.getAddress(accountIndex: accountIndex, addressIndex: addressIndex); - -// @override -// Future> fetchTransactions() async { -// throw UnimplementedError(); -// // monero_transaction_history.refreshTransactions(); -// // return _getAllTransactions(null) -// // .fold>({}, -// // (Map acc, MoneroTransactionInfo tx) { -// // acc[tx.id] = tx; -// // return acc; -// // }); -// } - -// Future updateTransactions() async { -// // try { -// // if (_isTransactionUpdating) { -// // return; -// // } - -// // _isTransactionUpdating = true; -// // final transactions = await fetchTransactions(); -// // transactionHistory.addMany(transactions); -// // await transactionHistory.save(); -// // _isTransactionUpdating = false; -// // } catch (e) { -// // print(e); -// // _isTransactionUpdating = false; -// // } -// } - -// // String getSubaddressLabel(int accountIndex, int addressIndex) { -// // // return monero_wallet.getSubaddressLabel(accountIndex, addressIndex); -// // } - -// // List _getAllTransactions(dynamic _) => monero_transaction_history -// // .getAllTransations() -// // .map((row) => MoneroTransactionInfo.fromRow(row)) -// // .toList(); - -// void _setListeners() { -// // _listener?.stop(); -// // _listener = monero_wallet.setListeners(_onNewBlock, _onNewTransaction); -// } - -// void _setInitialHeight() { -// // if (walletInfo.isRecovery) { -// // return; -// // } - -// // final currentHeight = getCurrentHeight(); - -// // if (currentHeight <= 1) { -// // final height = _getHeightByDate(walletInfo.date); -// // monero_wallet.setRecoveringFromSeed(isRecovery: true); -// // monero_wallet.setRefreshFromBlockHeight(height: height); -// // } -// } - -// Future _askForUpdateTransactionHistory() async => await updateTransactions(); - -// // int _getFullBalance() => monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id); - -// // int _getUnlockedBalance() => -// // monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id); - -// void _onNewTransaction() async { -// // try { -// // await _askForUpdateTransactionHistory(); -// // _askForUpdateBalance(); -// // await Future.delayed(Duration(seconds: 1)); -// // } catch (e) { -// // print(e.toString()); -// // } -// } -// } - import 'dart:convert'; import 'package:cw_core/crypto_currency.dart'; @@ -380,7 +39,7 @@ abstract class NanoWalletBase _priorityFees = [], walletAddresses = NanoWalletAddresses(walletInfo), balance = ObservableMap.of({ - CryptoCurrency.eth: initialBalance ?? + CryptoCurrency.nano: initialBalance ?? NanoBalance(currentBalance: BigInt.zero, receivableBalance: BigInt.zero) }), super(walletInfo) { @@ -407,14 +66,7 @@ abstract class NanoWalletBase @observable late ObservableMap balance; - Future init() async { - // erc20TokensBox = await Hive.openBox(Erc20Token.boxName); - // await walletAddresses.init(); - // await transactionHistory.init(); - // _privateKey = await getPrivateKey(_mnemonic, _password); - // walletAddresses.address = _privateKey.address.toString(); - // await save(); - } + Future init() async {} @override int calculateEstimatedFee(TransactionPriority priority, int? amount) { @@ -423,6 +75,7 @@ abstract class NanoWalletBase @override Future changePassword(String password) { + print("e"); throw UnimplementedError("changePassword"); } @@ -434,74 +87,42 @@ abstract class NanoWalletBase @action @override Future connectToNode({required Node node}) async { + print("f"); throw UnimplementedError(); } @override Future createTransaction(Object credentials) async { + print("g"); throw UnimplementedError(); } Future updateTransactions() async { + print("h"); throw UnimplementedError(); } @override Future> fetchTransactions() async { + print("i"); throw UnimplementedError(); - // final address = _privateKey.address.hex; - // final transactions = await _client.fetchTransactions(address); - - // final List>> erc20TokensTransactions = []; - - // for (var token in balance.keys) { - // if (token is Erc20Token) { - // erc20TokensTransactions.add(_client.fetchTransactions( - // address, - // contractAddress: token.contractAddress, - // )); - // } - // } - - // final tokensTransaction = await Future.wait(erc20TokensTransactions); - // transactions.addAll(tokensTransaction.expand((element) => element)); - - // final Map result = {}; - - // for (var transactionModel in transactions) { - // if (transactionModel.isError) { - // continue; - // } - - // result[transactionModel.hash] = EthereumTransactionInfo( - // id: transactionModel.hash, - // height: transactionModel.blockNumber, - // ethAmount: transactionModel.amount, - // direction: transactionModel.from == address - // ? TransactionDirection.outgoing - // : TransactionDirection.incoming, - // isPending: false, - // date: transactionModel.date, - // confirmations: transactionModel.confirmations, - // ethFee: BigInt.from(transactionModel.gasUsed) * transactionModel.gasPrice, - // exponent: transactionModel.tokenDecimal ?? 18, - // tokenSymbol: transactionModel.tokenSymbol ?? "ETH", - // ); - // } - - // return result; } @override - Object get keys => throw UnimplementedError("keys"); + Object get keys { + print("j"); + throw UnimplementedError("keys"); + } @override Future rescan({required int height}) { + print("k"); throw UnimplementedError("rescan"); } @override Future save() async { + print("l"); throw UnimplementedError(); } @@ -518,13 +139,6 @@ abstract class NanoWalletBase throw UnimplementedError(); } - // Future makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type); - - // String toJSON() => json.encode({ - // 'mnemonic': _mnemonic, - // 'balance': balance[currency]!.toJSON(), - // }); - static Future open({ required String name, required String password, @@ -534,9 +148,6 @@ abstract class NanoWalletBase } Future _updateBalance() async { - // balance[currency] = await _fetchEthBalance(); - - // await _fetchErc20Balances(); await save(); } @@ -545,6 +156,7 @@ abstract class NanoWalletBase } Future getPrivateKey(String mnemonic, String password) async { + print("o"); throw UnimplementedError(); } @@ -562,10 +174,6 @@ abstract class NanoWalletBase throw UnimplementedError(); } - void addInitialTokens() { - throw UnimplementedError(); - } - @override Future renameWalletFiles(String newWalletName) async { print("rename"); diff --git a/cw_nano/lib/nano_wallet_addresses.dart b/cw_nano/lib/nano_wallet_addresses.dart index f0ffd59db..c45bd28d7 100644 --- a/cw_nano/lib/nano_wallet_addresses.dart +++ b/cw_nano/lib/nano_wallet_addresses.dart @@ -11,38 +11,26 @@ class NanoWalletAddresses = NanoWalletAddressesBase with _$NanoWalletAddresses; abstract class NanoWalletAddressesBase extends WalletAddresses with Store { NanoWalletAddressesBase(WalletInfo walletInfo) - : accountList = NanoAccountList(), - address = '', + : address = '', super(walletInfo); @override - @observable String address; - @observable - Account? account; - - NanoAccountList accountList; - @override Future init() async { - accountList.update(); - account = accountList.accounts.first; + address = walletInfo.address; + await updateAddressesInBox(); } @override Future updateAddressesInBox() async { - throw UnimplementedError(); - } - - bool validate() { - accountList.update(); - final accountListLength = accountList.accounts.length ?? 0; - - if (accountListLength <= 0) { - return false; + try { + addressesMap.clear(); + addressesMap[address] = ''; + await saveAddressesInBox(); + } catch (e) { + print(e.toString()); } - - return true; } -} +} \ 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 c20bc385d..b95e8b6ed 100644 --- a/cw_nano/lib/nano_wallet_service.dart +++ b/cw_nano/lib/nano_wallet_service.dart @@ -63,16 +63,11 @@ class NanoWalletService extends WalletService create(NanoNewWalletCredentials credentials) async { print("nano_wallet_service create"); final mnemonic = bip39.generateMnemonic(); - print("gened"); final wallet = NanoWallet( walletInfo: credentials.walletInfo!, mnemonic: mnemonic, password: credentials.password!, ); - print("nano_wallet created"); - // await wallet.init(); - // await wallet.save(); - throw Exception("stop"); return wallet; } @@ -108,6 +103,7 @@ class NanoWalletService extends WalletService restoreFromKeys(NanoRestoreWalletFromKeysCredentials credentials) async { + print("a"); throw UnimplementedError(); // try { // final path = await pathForWallet(name: credentials.name, type: getType()); @@ -132,6 +128,7 @@ class NanoWalletService extends WalletService restoreFromSeed(NanoRestoreWalletFromSeedCredentials credentials) async { + print("b"); throw UnimplementedError(); // try { // final path = await pathForWallet(name: credentials.name, type: getType()); @@ -153,11 +150,13 @@ class NanoWalletService extends WalletService isWalletExit(String s) async { + print("c"); throw UnimplementedError(); } @override Future openWallet(String s, String s2) async { + print("d"); throw UnimplementedError(); } } diff --git a/lib/nano/cw_nano.dart b/lib/nano/cw_nano.dart index 59c00bb03..e0eebf6f6 100644 --- a/lib/nano/cw_nano.dart +++ b/lib/nano/cw_nano.dart @@ -13,8 +13,8 @@ class CWNano extends Nano { @override WalletService createNanoWalletService(Box walletInfoSource) { + print("creating NanoWalletService"); return NanoWalletService(walletInfoSource); - // throw UnimplementedError(); } NanoWalletDetails getNanoWalletDetails(Object wallet) { diff --git a/lib/view_model/wallet_new_vm.dart b/lib/view_model/wallet_new_vm.dart index 26f4f666f..04da7190e 100644 --- a/lib/view_model/wallet_new_vm.dart +++ b/lib/view_model/wallet_new_vm.dart @@ -47,7 +47,7 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store { case WalletType.ethereum: return ethereum!.createEthereumNewWalletCredentials(name: name); case WalletType.nano: - return nano!.createNanoNewWalletCredentials(name: name, language: options as String); + return nano!.createNanoNewWalletCredentials(name: name); default: throw Exception('Unexpected type: ${type.toString()}');; }