Skip to content

Commit

Permalink
Merge pull request #2265 from get10101/chore/wait-for-current-context…
Browse files Browse the repository at this point in the history
…-on-catchup-dialog

chore: Wait for current context to get available when showing recover dlc dialog
  • Loading branch information
holzeis authored Mar 18, 2024
2 parents 1ce3059 + 169ad6b commit 0342b24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
5 changes: 4 additions & 1 deletion mobile/lib/common/recover_dlc_change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RecoverDlcChangeNotifier extends ChangeNotifier implements Subscriber {
late TaskStatus taskStatus;

@override
void notify(bridge.Event event) {
void notify(bridge.Event event) async {
if (event is bridge.Event_BackgroundNotification) {
if (event.field0 is! bridge.BackgroundTask_RecoverDlc) {
// ignoring other kinds of background tasks
Expand All @@ -23,6 +23,9 @@ class RecoverDlcChangeNotifier extends ChangeNotifier implements Subscriber {
taskStatus = recoverDlc.taskStatus;

if (taskStatus == TaskStatus.pending) {
while (shellNavigatorKey.currentContext == null) {
await Future.delayed(const Duration(milliseconds: 100)); // Adjust delay as needed
}
// initialize dialog for the pending task
showDialog(
context: shellNavigatorKey.currentContext!,
Expand Down
30 changes: 16 additions & 14 deletions mobile/lib/features/trade/submit_order_change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,23 @@ class SubmitOrderChangeNotifier extends ChangeNotifier implements Subscriber {
if (event is bridge.Event_OrderUpdateNotification) {
Order order = Order.fromApi(event.field0);

switch (order.state) {
case OrderState.open:
case OrderState.filling:
return;
case OrderState.filled:
_pendingOrder!.state = PendingOrderState.orderFilled;
break;
case OrderState.failed:
case OrderState.rejected:
_pendingOrder!.state = PendingOrderState.orderFailed;
break;
if (pendingOrder != null) {
switch (order.state) {
case OrderState.open:
case OrderState.filling:
return;
case OrderState.filled:
_pendingOrder!.state = PendingOrderState.orderFilled;
break;
case OrderState.failed:
case OrderState.rejected:
_pendingOrder!.state = PendingOrderState.orderFailed;
break;
}
_pendingOrder!.failureReason = order.failureReason;

notifyListeners();
}
_pendingOrder!.failureReason = order.failureReason;

notifyListeners();
} else {
logger.w("Received unexpected event: ${event.toString()}");
}
Expand Down
5 changes: 5 additions & 0 deletions mobile/native/src/ln_dlc/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ impl Node {
expiry_timestamp,
)
.context("Failed to update position after DLC creation")?;

// In case of a restart.
event::publish(&EventInternal::BackgroundNotification(
BackgroundTask::RecoverDlc(TaskStatus::Success),
));
}
// If there is no order in `Filling` we must be rolling over.
None => {
Expand Down

0 comments on commit 0342b24

Please sign in to comment.