From b3ff38adb74b9525e6a8d2f964f44609e1664d8b Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 2 Jan 2023 16:43:39 -0600 Subject: [PATCH] check and update ui if xmr/wow data found during re/scan --- lib/services/coins/monero/monero_wallet.dart | 43 +++++++++++++++++++ .../coins/wownero/wownero_wallet.dart | 43 +++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/lib/services/coins/monero/monero_wallet.dart b/lib/services/coins/monero/monero_wallet.dart index 96fb2ee7f..d9c6ae42b 100644 --- a/lib/services/coins/monero/monero_wallet.dart +++ b/lib/services/coins/monero/monero_wallet.dart @@ -1119,6 +1119,7 @@ class MoneroWallet extends CoinServiceAPI { print("============================="); print("New Block! :: $walletName"); print("============================="); + _refreshTxDataHelper(); } void onNewTransaction() { @@ -1136,6 +1137,48 @@ class MoneroWallet extends CoinServiceAPI { ); } + bool _txRefreshLock = false; + int _lastCheckedHeight = -1; + int _txCount = 0; + + Future _refreshTxDataHelper() async { + if (_txRefreshLock) return; + _txRefreshLock = true; + + final syncStatus = walletBase?.syncStatus; + + if (syncStatus != null && syncStatus is SyncingSyncStatus) { + final int blocksLeft = syncStatus.blocksLeft; + final tenKChange = blocksLeft ~/ 10000; + + // only refresh transactions periodically during a sync + if (_lastCheckedHeight == -1 || tenKChange < _lastCheckedHeight) { + _lastCheckedHeight = tenKChange; + await _refreshTxData(); + } + } else { + await _refreshTxData(); + } + + _txRefreshLock = false; + } + + Future _refreshTxData() async { + final txnData = await _fetchTransactionData(); + final count = txnData.getAllTransactions().length; + + if (count > _txCount) { + _txCount = count; + _transactionData = Future(() => txnData); + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "New transaction data found in $walletId $walletName!", + walletId, + ), + ); + } + } + void syncStatusChanged() async { final syncStatus = walletBase?.syncStatus; if (syncStatus != null) { diff --git a/lib/services/coins/wownero/wownero_wallet.dart b/lib/services/coins/wownero/wownero_wallet.dart index 1f9a3dd96..7abd64f48 100644 --- a/lib/services/coins/wownero/wownero_wallet.dart +++ b/lib/services/coins/wownero/wownero_wallet.dart @@ -1163,6 +1163,49 @@ class WowneroWallet extends CoinServiceAPI { print("============================="); print("New Wownero Block! :: $walletName"); print("============================="); + _refreshTxDataHelper(); + } + + bool _txRefreshLock = false; + int _lastCheckedHeight = -1; + int _txCount = 0; + + Future _refreshTxDataHelper() async { + if (_txRefreshLock) return; + _txRefreshLock = true; + + final syncStatus = walletBase?.syncStatus; + + if (syncStatus != null && syncStatus is SyncingSyncStatus) { + final int blocksLeft = syncStatus.blocksLeft; + final tenKChange = blocksLeft ~/ 10000; + + // only refresh transactions periodically during a sync + if (_lastCheckedHeight == -1 || tenKChange < _lastCheckedHeight) { + _lastCheckedHeight = tenKChange; + await _refreshTxData(); + } + } else { + await _refreshTxData(); + } + + _txRefreshLock = false; + } + + Future _refreshTxData() async { + final txnData = await _fetchTransactionData(); + final count = txnData.getAllTransactions().length; + + if (count > _txCount) { + _txCount = count; + _transactionData = Future(() => txnData); + GlobalEventBus.instance.fire( + UpdatedInBackgroundEvent( + "New transaction data found in $walletId $walletName!", + walletId, + ), + ); + } } void onNewTransaction() {