fix: missing txcount from addresses

This commit is contained in:
Rafael Saes 2024-04-12 18:31:23 -03:00
parent 2df4a17d5e
commit 2b42b55bd0

View file

@ -150,15 +150,15 @@ abstract class ElectrumWalletBase
bool silentPaymentsScanningActive = false; bool silentPaymentsScanningActive = false;
@action @action
void setSilentPaymentsScanning(bool active) { Future<void> setSilentPaymentsScanning(bool active) async {
silentPaymentsScanningActive = active; silentPaymentsScanningActive = active;
if (active) { if (active) {
_setInitialHeight().then((_) { await _setInitialHeight();
if ((currentChainTip ?? 0) > walletInfo.restoreHeight) {
_setListeners(walletInfo.restoreHeight, chainTip: currentChainTip); if ((currentChainTip ?? 0) > walletInfo.restoreHeight) {
} _setListeners(walletInfo.restoreHeight, chainTip: currentChainTip);
}); }
} else { } else {
_isolate?.then((runningIsolate) => runningIsolate.kill(priority: Isolate.immediate)); _isolate?.then((runningIsolate) => runningIsolate.kill(priority: Isolate.immediate));
@ -166,9 +166,8 @@ abstract class ElectrumWalletBase
syncStatus = SyncedSyncStatus(); syncStatus = SyncedSyncStatus();
} else { } else {
if (electrumClient.uri != null) { if (electrumClient.uri != null) {
electrumClient.connectToUri(electrumClient.uri!).then((_) { await electrumClient.connectToUri(electrumClient.uri!);
startSync(); startSync();
});
} }
} }
} }
@ -242,11 +241,10 @@ abstract class ElectrumWalletBase
[unspent.bitcoinAddressRecord as BitcoinSilentPaymentAddressRecord])); [unspent.bitcoinAddressRecord as BitcoinSilentPaymentAddressRecord]));
final existingTxInfo = transactionHistory.transactions[txid]; final existingTxInfo = transactionHistory.transactions[txid];
if (existingTxInfo != null) { final txAlreadyExisted = existingTxInfo != null;
final addressRecord =
walletAddresses.silentAddresses.firstWhere((addr) => addr.address == tx.to);
addressRecord.txCount += 1;
// Updating tx after re-scanned
if (txAlreadyExisted) {
existingTxInfo.amount = tx.amount; existingTxInfo.amount = tx.amount;
existingTxInfo.confirmations = tx.confirmations; existingTxInfo.confirmations = tx.confirmations;
existingTxInfo.height = tx.height; existingTxInfo.height = tx.height;
@ -276,6 +274,10 @@ abstract class ElectrumWalletBase
transactionHistory.addOne(existingTxInfo); transactionHistory.addOne(existingTxInfo);
} }
} else { } else {
final addressRecord =
walletAddresses.silentAddresses.firstWhere((addr) => addr.address == tx.to);
addressRecord.txCount += 1;
transactionHistory.addMany(message); transactionHistory.addMany(message);
} }
@ -1726,7 +1728,7 @@ Future<void> startRefresh(ScanData scanData) async {
try { try {
final electrumClient = await getElectrumConnection(); final electrumClient = await getElectrumConnection();
// TODO: hardcoded values, if timed out decrease amount of blocks per request? // TODO: hardcoded values, if timed out decrease amount of blocks per request?
final scanningBlockCount = final scanningBlockCount =
scanData.isSingleScan ? 1 : (scanData.network == BitcoinNetwork.testnet ? 25 : 10); scanData.isSingleScan ? 1 : (scanData.network == BitcoinNetwork.testnet ? 25 : 10);
@ -1798,6 +1800,7 @@ Future<void> startRefresh(ScanData scanData) async {
network: scanData.network, network: scanData.network,
silentPaymentTweak: t_k, silentPaymentTweak: t_k,
type: SegwitAddresType.p2tr, type: SegwitAddresType.p2tr,
txCount: 1,
); );
int? amount; int? amount;