diff --git a/cw_core/lib/transaction_info.dart b/cw_core/lib/transaction_info.dart index 7b02bf1ff..a270c0479 100644 --- a/cw_core/lib/transaction_info.dart +++ b/cw_core/lib/transaction_info.dart @@ -3,6 +3,7 @@ import 'package:cw_core/keyable.dart'; abstract class TransactionInfo extends Object with Keyable { late String id; + late String txhash = id; late int amount; int? fee; late TransactionDirection direction; diff --git a/cw_monero/lib/api/wallet_manager.dart b/cw_monero/lib/api/wallet_manager.dart index 8a1eee3f7..f77ef05e2 100644 --- a/cw_monero/lib/api/wallet_manager.dart +++ b/cw_monero/lib/api/wallet_manager.dart @@ -194,28 +194,24 @@ void loadWallet( wptr = openedWalletsByPath[path]!; return; } - try { - if (wptr == null || path != _lastOpenedWallet) { - if (wptr != null) { - final addr = wptr!.address; - Isolate.run(() { - monero.Wallet_store(Pointer.fromAddress(addr)); - }); - } - txhistory = null; - wptr = monero.WalletManager_openWallet(wmPtr, - path: path, password: password); - openedWalletsByPath[path] = wptr!; - _lastOpenedWallet = path; + if (wptr == null || path != _lastOpenedWallet) { + if (wptr != null) { + final addr = wptr!.address; + Isolate.run(() { + monero.Wallet_store(Pointer.fromAddress(addr)); + }); } - } catch (e) { - print(e); - } - final status = monero.Wallet_status(wptr!); - if (status != 0) { - final err = monero.Wallet_errorString(wptr!); - print(err); - throw WalletOpeningException(message: err); + txhistory = null; + wptr = monero.WalletManager_openWallet(wmPtr, + path: path, password: password); + _lastOpenedWallet = path; + final status = monero.Wallet_status(wptr!); + if (status != 0) { + final err = monero.Wallet_errorString(wptr!); + print(err); + throw WalletOpeningException(message: err); + } + openedWalletsByPath[path] = wptr!; } } diff --git a/cw_monero/lib/monero_subaddress_list.dart b/cw_monero/lib/monero_subaddress_list.dart index 676a9536c..623d744fd 100644 --- a/cw_monero/lib/monero_subaddress_list.dart +++ b/cw_monero/lib/monero_subaddress_list.dart @@ -124,7 +124,7 @@ abstract class MoneroSubaddressListBase with Store { Future> _getAllUnusedAddresses( {required int accountIndex, required String label}) async { final allAddresses = subaddress_list.getAllSubaddresses(); - final lastAddress = allAddresses.last.address; + final lastAddress = allAddresses.length == 0 ? allAddresses.last.address : Subaddress(id: -1, address: "", label: ""); if (allAddresses.isEmpty || _usedAddresses.contains(lastAddress)) { final isAddressUnused = await _newSubaddress(accountIndex: accountIndex, label: label); if (!isAddressUnused) { diff --git a/cw_monero/lib/monero_transaction_info.dart b/cw_monero/lib/monero_transaction_info.dart index 748b65329..b1a4e4229 100644 --- a/cw_monero/lib/monero_transaction_info.dart +++ b/cw_monero/lib/monero_transaction_info.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/monero_amount_format.dart'; import 'package:cw_monero/api/structs/transaction_info_row.dart'; @@ -7,12 +9,14 @@ import 'package:cw_core/format_amount.dart'; import 'package:cw_monero/api/transaction_history.dart'; class MoneroTransactionInfo extends TransactionInfo { - MoneroTransactionInfo(this.id, this.height, this.direction, this.date, + MoneroTransactionInfo(this.txhash, this.height, this.direction, this.date, this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, - this.confirmations); + this.confirmations) : + id = "${txhash}_${amount}_${accountIndex}_${addressIndex}"; MoneroTransactionInfo.fromMap(Map map) - : id = (map['hash'] ?? '') as String, + : id = "${map['hash']}_${map['amount']}_${map['accountIndex']}_${map['addressIndex']}", + txhash = map['hash'] as String, height = (map['height'] ?? 0) as int, direction = map['direction'] != null ? parseTransactionDirectionFromNumber(map['direction'] as String) @@ -34,7 +38,8 @@ class MoneroTransactionInfo extends TransactionInfo { } MoneroTransactionInfo.fromRow(TransactionInfoRow row) - : id = row.getHash(), + : id = "${row.getHash()}_${row.getAmount()}_${row.subaddrAccount}_${row.subaddrIndex}", + txhash = row.getHash(), height = row.blockHeight, direction = parseTransactionDirectionFromInt(row.direction), date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000), @@ -53,6 +58,7 @@ class MoneroTransactionInfo extends TransactionInfo { } final String id; + final String txhash; final int height; final TransactionDirection direction; final DateTime date; diff --git a/cw_wownero/lib/api/wallet_manager.dart b/cw_wownero/lib/api/wallet_manager.dart index 2f92bb080..e90843538 100644 --- a/cw_wownero/lib/api/wallet_manager.dart +++ b/cw_wownero/lib/api/wallet_manager.dart @@ -208,28 +208,24 @@ void loadWallet( wptr = openedWalletsByPath[path]!; return; } - try { - if (wptr == null || path != _lastOpenedWallet) { - if (wptr != null) { - final addr = wptr!.address; - Isolate.run(() { - wownero.Wallet_store(Pointer.fromAddress(addr)); - }); - } - txhistory = null; - wptr = wownero.WalletManager_openWallet(wmPtr, - path: path, password: password); - openedWalletsByPath[path] = wptr!; - _lastOpenedWallet = path; + if (wptr == null || path != _lastOpenedWallet) { + if (wptr != null) { + final addr = wptr!.address; + Isolate.run(() { + wownero.Wallet_store(Pointer.fromAddress(addr)); + }); } - } catch (e) { - print(e); - } - final status = wownero.Wallet_status(wptr!); - if (status != 0) { - final err = wownero.Wallet_errorString(wptr!); - print(err); - throw WalletOpeningException(message: err); + txhistory = null; + wptr = wownero.WalletManager_openWallet(wmPtr, + path: path, password: password); + _lastOpenedWallet = path; + final status = wownero.Wallet_status(wptr!); + if (status != 0) { + final err = wownero.Wallet_errorString(wptr!); + print(err); + throw WalletOpeningException(message: err); + } + openedWalletsByPath[path] = wptr!; } } diff --git a/cw_wownero/lib/wownero_transaction_info.dart b/cw_wownero/lib/wownero_transaction_info.dart index 2060f1f95..6016e2e59 100644 --- a/cw_wownero/lib/wownero_transaction_info.dart +++ b/cw_wownero/lib/wownero_transaction_info.dart @@ -7,12 +7,14 @@ import 'package:cw_core/format_amount.dart'; import 'package:cw_wownero/api/transaction_history.dart'; class WowneroTransactionInfo extends TransactionInfo { - WowneroTransactionInfo(this.id, this.height, this.direction, this.date, + WowneroTransactionInfo(this.txhash, this.height, this.direction, this.date, this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee, - this.confirmations); + this.confirmations) : + id = "${txhash}_${amount}_${accountIndex}_${addressIndex}"; WowneroTransactionInfo.fromMap(Map map) - : id = (map['hash'] ?? '') as String, + : id = "${map['hash']}_${map['amount']}_${map['accountIndex']}_${map['addressIndex']}", + txhash = map['hash'] as String, height = (map['height'] ?? 0) as int, direction = map['direction'] != null ? parseTransactionDirectionFromNumber(map['direction'] as String) @@ -34,7 +36,8 @@ class WowneroTransactionInfo extends TransactionInfo { } WowneroTransactionInfo.fromRow(TransactionInfoRow row) - : id = row.getHash(), + : id = "${row.getHash()}_${row.getAmount()}_${row.subaddrAccount}_${row.subaddrIndex}", + txhash = row.getHash(), height = row.blockHeight, direction = parseTransactionDirectionFromInt(row.direction), date = DateTime.fromMillisecondsSinceEpoch(row.getDatetime() * 1000), @@ -53,6 +56,7 @@ class WowneroTransactionInfo extends TransactionInfo { } final String id; + final String txhash; final int height; final TransactionDirection direction; final DateTime date; diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index acf334382..025ccab9b 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -214,7 +214,7 @@ abstract class TransactionDetailsViewModelBase with Store { final addressIndex = tx.additionalInfo['addressIndex'] as int; final feeFormatted = tx.feeFormatted(); final _items = [ - StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id), + StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.txhash), StandartListItem( title: S.current.transaction_details_date, value: dateFormat.format(tx.date)), StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'), @@ -455,7 +455,7 @@ abstract class TransactionDetailsViewModelBase with Store { final addressIndex = tx.additionalInfo['addressIndex'] as int; final feeFormatted = tx.feeFormatted(); final _items = [ - StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id), + StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.txhash), StandartListItem( title: S.current.transaction_details_date, value: dateFormat.format(tx.date)), StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'), diff --git a/scripts/prepare_moneroc.sh b/scripts/prepare_moneroc.sh index 27d839ef4..e91b3d4a4 100755 --- a/scripts/prepare_moneroc.sh +++ b/scripts/prepare_moneroc.sh @@ -8,7 +8,7 @@ if [[ ! -d "monero_c" ]]; then git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip cd monero_c - git checkout eaa7bdb8be3479418445ddb18bf33d453f64afcf + git checkout d1e246aaf4c53b60ff9e4ab4a4ac3ae4a1f94a33 git reset --hard git submodule update --init --force --recursive ./apply_patches.sh monero