diff --git a/lib/di.dart b/lib/di.dart index 66ac2223..5af42cda 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -482,10 +482,14 @@ Future setup( getIt .registerFactoryParam( - (TransactionInfo transactionInfo, _) => TransactionDetailsViewModel( - transactionInfo: transactionInfo, - transactionDescriptionBox: _transactionDescriptionBox, - settingsStore: getIt.get())); + (TransactionInfo transactionInfo, _) { + final wallet = getIt.get().wallet; + return TransactionDetailsViewModel( + transactionInfo: transactionInfo, + transactionDescriptionBox: _transactionDescriptionBox, + wallet: wallet, + settingsStore: getIt.get()); + }); getIt.registerFactoryParam( (TransactionInfo transactionInfo, _) => TransactionDetailsPage( diff --git a/lib/monero/monero_transaction_info.dart b/lib/monero/monero_transaction_info.dart index 71bc5957..e28835fe 100644 --- a/lib/monero/monero_transaction_info.dart +++ b/lib/monero/monero_transaction_info.dart @@ -8,7 +8,7 @@ import 'package:cw_monero/transaction_history.dart'; class MoneroTransactionInfo extends TransactionInfo { MoneroTransactionInfo(this.id, this.height, this.direction, this.date, - this.isPending, this.amount, this.accountIndex, this.fee); + this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee); MoneroTransactionInfo.fromMap(Map map) : id = (map['hash'] ?? '') as String, @@ -21,6 +21,7 @@ class MoneroTransactionInfo extends TransactionInfo { isPending = parseBoolFromString(map['isPending'] as String), amount = map['amount'] as int, accountIndex = int.parse(map['accountIndex'] as String), + addressIndex = map['addressIndex'] as List, key = getTxKey((map['hash'] ?? '') as String), fee = map['fee'] as int ?? 0; @@ -33,6 +34,7 @@ class MoneroTransactionInfo extends TransactionInfo { isPending = row.isPending != 0, amount = row.getAmount(), accountIndex = row.subaddrAccount, + addressIndex = row.getSubaddrIndex(), key = getTxKey(row.getHash()), fee = row.fee; @@ -44,6 +46,7 @@ class MoneroTransactionInfo extends TransactionInfo { final bool isPending; final int amount; final int fee; + final List addressIndex; String recipientAddress; String key; diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 0891100c..0c194903 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -262,6 +262,11 @@ abstract class MoneroWalletBase extends WalletBase with Store { await walletInfo.save(); } + String getTransactionAddress(int accountIndex, int addressIndex) => + monero_wallet.getAddress( + accountIndex: accountIndex, + addressIndex: addressIndex); + void _setListeners() { _listener?.stop(); _listener = monero_wallet.setListeners(_onNewBlock, _onNewTransaction); diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index 67822e20..51afb355 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -1,10 +1,13 @@ import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart'; +import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/entities/transaction_info.dart'; import 'package:cake_wallet/monero/monero_transaction_info.dart'; +import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/textfield_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/transaction_details_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart'; +import 'package:cake_wallet/entities/transaction_direction.dart'; import 'package:cake_wallet/utils/date_formatter.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:hive/hive.dart'; @@ -22,6 +25,7 @@ abstract class TransactionDetailsViewModelBase with Store { TransactionDetailsViewModelBase( {this.transactionInfo, this.transactionDescriptionBox, + this.wallet, this.settingsStore}) : items = [] { showRecipientAddress = settingsStore?.shouldSaveRecipientAddress ?? false; @@ -56,6 +60,25 @@ abstract class TransactionDetailsViewModelBase with Store { StandartListItem(title: S.current.transaction_key, value: tx.key)); } + if ((tx.direction == TransactionDirection.incoming)&& + (wallet is MoneroWallet)) { + try { + final accountIndex = tx.accountIndex; + final addressIndex = tx.addressIndex; + final _wallet = wallet as MoneroWallet; + + for (var index in addressIndex) { + final address = _wallet.getTransactionAddress(accountIndex, index); + _items.add( + StandartListItem( + title: S.current.transaction_details_recipient_address, + value: address)); + } + } catch (e) { + print(e.toString()); + } + } + items.addAll(_items); } @@ -122,6 +145,7 @@ abstract class TransactionDetailsViewModelBase with Store { final TransactionInfo transactionInfo; final Box transactionDescriptionBox; final SettingsStore settingsStore; + final WalletBase wallet; final List items; bool showRecipientAddress;