From 16f058e9e2336520db942be0b241582be32fbec4 Mon Sep 17 00:00:00 2001 From: rafael_xmr Date: Wed, 20 Aug 2025 23:06:35 -0300 Subject: [PATCH] sp improv (#2437) * fix(sp): proper address on details screen * fix(sp): fields to update on incoming msg * Update lib/bitcoin/cw_bitcoin.dart --------- Co-authored-by: Omar Hatem --- cw_bitcoin/lib/electrum_wallet.dart | 48 +++++++++---------- lib/bitcoin/cw_bitcoin.dart | 18 ++++--- .../transaction_details_view_model.dart | 20 ++++---- tool/configure.dart | 2 +- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index b92f4c872..7eb1c7b34 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -403,6 +403,9 @@ abstract class ElectrumWalletBase existingTxInfo.confirmations = tx.confirmations; existingTxInfo.height = tx.height; existingTxInfo.date = tx.date; + existingTxInfo.isReceivedSilentPayment = tx.isReceivedSilentPayment; + existingTxInfo.direction = tx.direction; + existingTxInfo.isPending = tx.isPending; final newUnspents = tx.unspents! .where((unspent) => !(existingTxInfo.unspents?.any((element) => @@ -2057,8 +2060,8 @@ abstract class ElectrumWalletBase .where((type) => type != SegwitAddresType.mweb) .map((type) => fetchTransactionsForAddressType(historiesWithDetails, type))); } else if (type == WalletType.dogecoin) { - await Future.wait(DOGECOIN_ADDRESS_TYPES.map( - (type) => fetchTransactionsForAddressType(historiesWithDetails, type))); + await Future.wait(DOGECOIN_ADDRESS_TYPES + .map((type) => fetchTransactionsForAddressType(historiesWithDetails, type))); } transactionHistory.transactions.values.forEach((tx) async { @@ -2875,6 +2878,23 @@ Future _handleScanSilentPayments(ScanData scanData) async { LogLevel.info, ); + void endScanningSuccesfully() { + if (scanData.isSingleScan) + scanData.sendPort.send(SyncResponse(syncHeight, SyncedSyncStatus())); + else + scanData.sendPort.send( + SyncResponse(syncHeight, SyncedTipSyncStatus(scanData.chainTip)), + ); + + _scanningStream?.close(); + _scanningStream = null; + + log( + "ended: syncHeight: $syncHeight, chainTip: ${scanData.chainTip}, isSingleScan: ${scanData.isSingleScan}", + LogLevel.info, + ); + } + void listenFn(Map event, ElectrumTweaksSubscribe req) async { final response = req.onResponse(event); @@ -2883,9 +2903,6 @@ Future _handleScanSilentPayments(ScanData scanData) async { "ending: response = $response, stream = $_scanningStream", LogLevel.error, ); - scanData.sendPort.send( - SyncResponse(scanData.height, LostConnectionSyncStatus()), - ); return; } @@ -2896,9 +2913,7 @@ Future _handleScanSilentPayments(ScanData scanData) async { if (scanData.isSingleScan) { log("ending: noData and isSingleScan", LogLevel.info); - scanData.sendPort.send( - SyncResponse(scanData.height, LostConnectionSyncStatus()), - ); + endScanningSuccesfully(); return; } @@ -3114,22 +3129,7 @@ Future _handleScanSilentPayments(ScanData scanData) async { syncHeight = tweakHeight; if ((tweakHeight >= scanData.chainTip) || scanData.isSingleScan) { - if (tweakHeight >= scanData.chainTip) - scanData.sendPort.send( - SyncResponse(syncHeight, SyncedTipSyncStatus(scanData.chainTip)), - ); - - if (scanData.isSingleScan) { - scanData.sendPort.send(SyncResponse(syncHeight, SyncedSyncStatus())); - } - - _scanningStream?.close(); - _scanningStream = null; - log( - "ending: syncHeight: $syncHeight, chainTip: ${scanData.chainTip}, isSingleScan: ${scanData.isSingleScan}", - LogLevel.info, - ); - return; + endScanningSuccesfully(); } } diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index c0abaa2be..e8c2559b5 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -802,7 +802,7 @@ class CWBitcoin extends Bitcoin { } @override - String? getTransactionAddress(Object wallet, TransactionInfo tx) { + List? getTransactionAddresses(Object wallet, TransactionInfo tx) { final bitcoinWallet = wallet as BitcoinWallet; final bitcoinTx = tx as ElectrumTransactionInfo; @@ -810,10 +810,16 @@ class CWBitcoin extends Bitcoin { return null; } - // final bitcoinSPAddrs = - // bitcoinTx.unspents!.first.bitcoinAddressRecord as BitcoinSilentPaymentAddressRecord; - final bitcoinSPAddrs = wallet.walletAddresses as BitcoinWalletAddresses; - final bitcoinSPAddr = bitcoinSPAddrs.silentAddresses.first; - return bitcoinSPAddr.address; + final addresses = []; + final labels = []; + try { + bitcoinTx.unspents!.forEach((unspent) { + addresses.add(bitcoinWallet.walletAddresses.silentAddresses + .firstWhere((address) => address.silentPaymentTweak == unspent.silentPaymentLabel) + .address); + }); + } catch (e) {} + + return addresses; } } diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index eec24a031..e55bc0428 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -351,17 +351,19 @@ abstract class TransactionDetailsViewModelBase with Store { if (wallet.type == WalletType.bitcoin && tx.direction == TransactionDirection.incoming) { try { - final address = bitcoin!.getTransactionAddress(wallet, tx); + final addresses = bitcoin!.getTransactionAddresses(wallet, tx); - if (address != null) { + if (addresses != null) { isRecipientAddressShown = true; - _items.add( - StandartListItem( - title: S.current.transaction_details_recipient_address, - value: address, - key: ValueKey('standard_list_item_transaction_details_recipient_address_key'), - ), - ); + for (final address in addresses) { + _items.add( + StandartListItem( + title: S.current.transaction_details_recipient_address, + value: address, + key: ValueKey('standard_list_item_transaction_details_recipient_address_key'), + ), + ); + } } } catch (e) { printV(e.toString()); diff --git a/tool/configure.dart b/tool/configure.dart index ea3d3e363..540768cf3 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -259,7 +259,7 @@ abstract class Bitcoin { void resumePayjoinSessions(Object wallet); void stopPayjoinSessions(Object wallet); Map getSilentPaymentKeys(Object wallet); - String? getTransactionAddress(Object wallet, TransactionInfo tx); + List? getTransactionAddresses(Object wallet, TransactionInfo tx); } """;