check and update ui if xmr/wow data found during re/scan

This commit is contained in:
julian 2023-01-02 16:43:39 -06:00
parent 66e9f87c0f
commit b3ff38adb7
2 changed files with 86 additions and 0 deletions

View file

@ -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<void> _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<void> _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) {

View file

@ -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<void> _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<void> _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() {