Skip to content

Commit

Permalink
fix iOS check chanels on start
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Feb 17, 2022
1 parent 01f593e commit 664123b
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions lib/handlers/check_channel_connection_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,45 @@ class CheckChannelConnection {
BuildContext context,
AccountBloc accountBloc,
) {
startSubscription(accountBloc, context);
ServiceInjector().device.eventStream.distinct().listen((event) {
switch (event) {
case NotificationType.RESUME:
_subscription = accountBloc.accountStream
.map((acc) => acc.readyForPayments)
.distinct()
.listen((ready) {
if (ready) {
_readyForPayments();
_notReadyTimer?.cancel();
} else {
_notReadyTimer = Timer(Duration(seconds: 30), () {
_notReadyForPayments(context);
});
}
});
cancelSubscription();
startSubscription(accountBloc, context);
break;
case NotificationType.PAUSE:
_flushbar?.dismiss();
_flushbar = null;
_subscription?.cancel();
_notReadyTimer?.cancel();
cancelSubscription();
break;
}
});
}

void startSubscription(AccountBloc accountBloc, BuildContext context) {
_subscription = accountBloc.accountStream
.map((acc) => acc.readyForPayments)
.distinct()
.listen((ready) {
if (ready) {
_readyForPayments();
_notReadyTimer?.cancel();
} else {
_notReadyTimer = Timer(Duration(seconds: 30), () {
_notReadyForPayments(context);
});
}
});
}

void cancelSubscription() {
_flushbar?.dismiss();
_flushbar = null;
_subscription?.cancel();
_subscription = null;
_notReadyTimer?.cancel();
_notReadyTimer = null;
}

void _readyForPayments() {
log.info("Account is ready for payments");
_flushbar?.dismiss();
Expand Down

0 comments on commit 664123b

Please sign in to comment.