Skip to content

Commit

Permalink
Fix background polling on swap pages
Browse files Browse the repository at this point in the history
- Regression: Replace function reference with function call
- Remove async logic
- Hide loader for background refreshes
  • Loading branch information
erdemyerebasmaz committed Apr 8, 2024
1 parent 0966b6d commit 521e025
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/bloc/rev_swap_in_progress/rev_swap_in_progress_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class RevSwapsInProgressBloc extends Cubit<RevSwapsInProgressState> {

pollReverseSwapsInProgress() async {
_log.info("Started polling for reverse swaps in progress.");
await _refreshInProgressReverseSwaps().whenComplete(() => _startPolling());
await _refreshInProgressReverseSwaps(showLoader: true).whenComplete(() => _startPolling());
}

late Timer timer;

void _startPolling() {
timer = Timer.periodic(const Duration(seconds: 30), (_) async => _refreshInProgressReverseSwaps);
timer = Timer.periodic(const Duration(seconds: 30), (_) => _refreshInProgressReverseSwaps());
}

Future<void> _refreshInProgressReverseSwaps() async {
Future<void> _refreshInProgressReverseSwaps({bool showLoader = false}) async {
try {
_log.info("Refreshing reverse swaps in progress.");
_emitState(state.copyWith(isLoading: true));
_emitState(state.copyWith(isLoading: showLoader));
final reverseSwapsInProgress = await _breezSDK.inProgressOnchainPayments();
_logReverseSwapsInProgress(reverseSwapsInProgress);
_emitState(state.copyWith(
Expand Down
8 changes: 4 additions & 4 deletions lib/bloc/swap_in_progress/swap_in_progress_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class SwapInProgressBloc extends Cubit<SwapInProgressState> {

pollSwapInAddress() async {
_log.info("Started polling for swap in address.");
await _refreshAddresses().whenComplete(() => _startPolling());
await _refreshAddresses(showLoader: true).whenComplete(() => _startPolling());
}

late Timer timer;

void _startPolling() {
timer = Timer.periodic(const Duration(seconds: 30), (_) async => _refreshAddresses);
timer = Timer.periodic(const Duration(seconds: 30), (_) => _refreshAddresses());
}

Future<void> _refreshAddresses() async {
Future<void> _refreshAddresses({bool showLoader = false}) async {
try {
_log.info("Refreshing swap in address.");
_emitState(state.copyWith(isLoading: true));
_emitState(state.copyWith(isLoading: showLoader));
SwapInfo? inProgress = (await _breezSDK.inProgressSwap());
// Reset unused if there's a swap in progress
_emitState(state.copyWith(inProgress: inProgress, unused: inProgress != null ? null : state.unused));
Expand Down

0 comments on commit 521e025

Please sign in to comment.