Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Wait for current context to get available when showing recover dlc dialog #2265

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading