This commit is contained in:
M
2020-11-03 18:57:36 +02:00
parent 5524efb44d
commit 76581505a0
3 changed files with 45 additions and 70 deletions
+20 -34
View File
@@ -95,7 +95,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
address = subaddress.address;
_setListeners();
await transactionHistory.update();
print('walletInfo.isRecovery ${walletInfo.isRecovery}');
if (walletInfo.isRecovery) {
monero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
@@ -233,8 +233,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
void _setListeners() {
_listener?.stop();
_listener = monero_wallet.setListeners(
_onNewBlock, _onNeedToRefresh, _onNewTransaction);
_listener = monero_wallet.setListeners(_onNewBlock);
_listener.start();
}
@@ -293,43 +292,30 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
int _getUnlockedBalance() =>
monero_wallet.getUnlockedBalance(accountIndex: account.id);
void _onNewBlock(int height, int blocksLeft, double ptc) =>
syncStatus = SyncingSyncStatus(blocksLeft, ptc);
int _lastAutosaveTimestamp = 0;
final int _autosaveInterval = 60000;
Future _onNeedToRefresh() async {
if (syncStatus is FailedSyncStatus) {
Future<void> _autoSave() async {
final nowTimestamp = DateTime.now().millisecondsSinceEpoch;
final sum = _lastAutosaveTimestamp + _autosaveInterval;
if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) {
return;
}
if (walletInfo.isRecovery) {
_askForUpdateTransactionHistory();
_askForUpdateBalance();
}
final currentHeight = getCurrentHeight();
final nodeHeight = monero_wallet.getNodeHeightSync();
if (nodeHeight - currentHeight < moneroBlockSize) {
syncStatus = SyncedSyncStatus();
if (walletInfo.isRecovery) {
await setAsRecovered();
}
}
// if (walletInfo.isRecovery &&
// (nodeHeight - currentHeight < moneroBlockSize)) {
// await setAsRecovered();
// }
if (currentHeight - _cachedRefreshHeight > moneroBlockSize) {
_cachedRefreshHeight = currentHeight;
await save();
}
_lastAutosaveTimestamp = nowTimestamp + _autosaveInterval;
await save();
}
void _onNewTransaction() {
_askForUpdateBalance();
void _onNewBlock(int height, int blocksLeft, double ptc) async {
_askForUpdateTransactionHistory();
_askForUpdateBalance();
if (blocksLeft < moneroBlockSize) {
syncStatus = SyncedSyncStatus();
await _autoSave();
} else {
syncStatus = SyncingSyncStatus(blocksLeft, ptc);
}
}
}