fix: monero address display in tx history (#3249)

* fix: monero address display in tx history * chore: Add comment for regex function [skip ci] * chore: Add doc comment --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

David Adegoke committed May 26, 2026 at 14:40 UTC f3de4b258801b4206337876c65d3aa981e10b1b8
2 files changed +27 -8
lib/view_model/send/send_view_model.dart
+8 -4
@@ -1106,10 +1106,14 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
1106 Future<void> updateWalletBalance() async => await wallet.updateBalance();
1107
1108 Future<void> _addTransactionDescription() async {
1109 - String address = outputs.fold('', (acc, value) {
1110 - return value.isParsedAddress
1111 - ? '$acc${value.address}\n${value.extractedAddress}\n\n'
1112 - : '$acc${value.address}\n\n';
1109 + String address = outputs.fold('', (acc, value) {
1110 + final canonical = value.extractedAddress.trim().isNotEmpty
1111 + ? value.extractedAddress.trim()
1112 + : value.address.trim();
1113 + if (canonical.isEmpty) {
1114 + return acc;
1115 + }
1116 + return '$acc$canonical\n\n';
1117 });
1118
1119 address = address.trim();
lib/view_model/transaction_details_view_model.dart
+19 -4
@@ -37,6 +37,19 @@ part 'transaction_details_view_model.g.dart';
37
38 bool _trueFunc(_) => true;
39
40 +/// We're adding a regex here so we can remove any already saved address that has the account in it.
41 +/// In the refactor, we will make another separate variable for accounts and the UI would handle it as needed.
42 +String _moneroRecipientAddressForDisplay(String raw, WalletType walletType) {
43 + if (walletType != WalletType.monero || raw.isEmpty) return raw;
44 +
45 + final compact = raw.replaceAll(RegExp(r'\s'), '');
46 + final match = RegExp(
47 + r'4[0-9a-zA-Z]{94}|8[0-9a-zA-Z]{94}|[0-9a-zA-Z]{106}',
48 + caseSensitive: false,
49 + ).firstMatch(compact);
50 + return match?.group(0) ?? raw.trim();
51 +}
52 +
53 bool isLightning(TransactionInfo tx) {
54 printV(tx.additionalInfo);
55 return (tx.additionalInfo["isLightning"] as bool?) ?? false;
@@ -121,8 +134,9 @@ class TxDetailRowDefinition {
134 if(ret == null) {
135 ret = vm.transactionInfo.to ?? "";
136 }
124 - vm.isRecipientAddressShown = ret.isNotEmpty;
125 - return ret;
137 + final resolvedAddress = _moneroRecipientAddressForDisplay(ret, vm.wallet.type);
138 + vm.isRecipientAddressShown = resolvedAddress.isNotEmpty;
139 + return resolvedAddress;
140 },
141 applicable: (vm) =>
142 vm.showRecipientAddress &&
@@ -252,11 +266,12 @@ abstract class TransactionDetailsViewModelBase with Store {
266 final recipientAddress = description.recipientAddress;
267
268 if (recipientAddress?.isNotEmpty ?? false) {
269 + final recipientAddressForDisplay = _moneroRecipientAddressForDisplay(recipientAddress!, wallet.type);
270 items.add(
271 AddressListItem(
272 title: S.current.transaction_details_recipient_address,
258 - value: recipientAddress!,
259 - key: ValueKey('standard_list_item_${recipientAddress}_key'),
273 + value: recipientAddressForDisplay,
274 + key: ValueKey('standard_list_item_${recipientAddressForDisplay}_key'),
275 ),
276 );
277 }