mirror of https://github.com/m2049r/xmrwallet.git
dont update on every single block (#776)
This commit is contained in:
parent
d801a50962
commit
303b3aa354
|
@ -108,28 +108,33 @@ public class WalletService extends Service {
|
||||||
Timber.d("unconfirmedMoneyReceived() %d @ %s", amount, txId);
|
Timber.d("unconfirmedMoneyReceived() %d @ %s", amount, txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastTxCount = 0;
|
private long lastBlockTime = 0;
|
||||||
|
private int lastTxCount = 0;
|
||||||
|
|
||||||
public void newBlock(long height) {
|
public void newBlock(long height) {
|
||||||
final Wallet wallet = getWallet();
|
final Wallet wallet = getWallet();
|
||||||
if (wallet == null) throw new IllegalStateException("No wallet!");
|
if (wallet == null) throw new IllegalStateException("No wallet!");
|
||||||
Timber.d("newBlock() @ %d with observer %s", height, observer);
|
// don't flood with an update for every block ...
|
||||||
if (observer != null) {
|
if (lastBlockTime < System.currentTimeMillis() - 2000) {
|
||||||
boolean fullRefresh = false;
|
lastBlockTime = System.currentTimeMillis();
|
||||||
updateDaemonState(wallet, wallet.isSynchronized() ? height : 0);
|
Timber.d("newBlock() @ %d with observer %s", height, observer);
|
||||||
if (!wallet.isSynchronized()) {
|
if (observer != null) {
|
||||||
updated = true;
|
boolean fullRefresh = false;
|
||||||
// we want to see our transactions as they come in
|
updateDaemonState(wallet, wallet.isSynchronized() ? height : 0);
|
||||||
wallet.getHistory().refresh();
|
if (!wallet.isSynchronized()) {
|
||||||
int txCount = wallet.getHistory().getCount();
|
updated = true;
|
||||||
if (txCount > lastTxCount) {
|
// we want to see our transactions as they come in
|
||||||
// update the transaction list only if we have more than before
|
wallet.getHistory().refresh();
|
||||||
lastTxCount = txCount;
|
int txCount = wallet.getHistory().getCount();
|
||||||
fullRefresh = true;
|
if (txCount > lastTxCount) {
|
||||||
|
// update the transaction list only if we have more than before
|
||||||
|
lastTxCount = txCount;
|
||||||
|
fullRefresh = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (observer != null)
|
||||||
|
observer.onRefreshed(wallet, fullRefresh);
|
||||||
}
|
}
|
||||||
if (observer != null)
|
|
||||||
observer.onRefreshed(wallet, fullRefresh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue