fix: add (ba)nano periodic refreshes

This commit is contained in:
julian 2023-06-08 14:48:51 -06:00
parent 72bbf81c4c
commit 0af9af1ad2
2 changed files with 38 additions and 0 deletions

View file

@ -304,6 +304,9 @@ class BananoWallet extends CoinServiceAPI
@override
Future<void> exit() async {
_hasCalledExit = true;
timer?.cancel();
timer = null;
stopNetworkAlivePinging();
}
@override
@ -767,6 +770,22 @@ class BananoWallet extends CoinServiceAPI
coin,
),
);
if (shouldAutoSync) {
timer ??= Timer.periodic(const Duration(seconds: 30), (timer) async {
Logging.instance.log(
"Periodic refresh check for $walletId $walletName in object instance: $hashCode",
level: LogLevel.Info);
await refresh();
GlobalEventBus.instance.fire(
UpdatedInBackgroundEvent(
"New data found in $walletId $walletName in background!",
walletId,
),
);
});
}
} catch (e, s) {
Logging.instance.log(
"Failed to refresh banano wallet $walletId: '$walletName': $e\n$s",

View file

@ -310,6 +310,9 @@ class NanoWallet extends CoinServiceAPI
@override
Future<void> exit() async {
_hasCalledExit = true;
timer?.cancel();
timer = null;
stopNetworkAlivePinging();
}
@override
@ -779,6 +782,22 @@ class NanoWallet extends CoinServiceAPI
coin,
),
);
if (shouldAutoSync) {
timer ??= Timer.periodic(const Duration(seconds: 30), (timer) async {
Logging.instance.log(
"Periodic refresh check for $walletId $walletName in object instance: $hashCode",
level: LogLevel.Info);
await refresh();
GlobalEventBus.instance.fire(
UpdatedInBackgroundEvent(
"New data found in $walletId $walletName in background!",
walletId,
),
);
});
}
} catch (e, s) {
Logging.instance.log(
"Failed to refresh nano wallet $walletId: '$walletName': $e\n$s",