-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync dlc channel state with position
This change will do the following things depending on the dlc channel state and position. - DLC Channel in state `Signed` but no position: Create position from `filling` order. - DLC Channel in state `OffChainClosed` and a position exists. Delete the position. - DLC Channel in state `CloseOffered` or `CloseAccepted`: Inform the UI that the dlc channel is recovering. - DLC Channel in state `Offered`, `Accepted` or `Finalized`: Inform the UI that the dlc channel is recovering. - DLC Channel in any other state but with position: Delete position the channel might have been force closed.
- Loading branch information
Showing
10 changed files
with
300 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:f_logs/model/flog/flog.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/bridge_generated/bridge_definitions.dart' as bridge; | ||
import 'package:get_10101/common/application/event_service.dart'; | ||
import 'package:get_10101/common/domain/background_task.dart'; | ||
import 'package:get_10101/common/global_keys.dart'; | ||
import 'package:get_10101/features/trade/order_submission_status_dialog.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class RecoverDlcChangeNotifier extends ChangeNotifier implements Subscriber { | ||
late TaskStatus taskStatus; | ||
|
||
@override | ||
void notify(bridge.Event event) { | ||
if (event is bridge.Event_BackgroundNotification) { | ||
if (event.field0 is! bridge.BackgroundTask_RecoverDlc) { | ||
// ignoring other kinds of background tasks | ||
return; | ||
} | ||
RecoverDlc recoverDlc = RecoverDlc.fromApi(event.field0 as bridge.BackgroundTask_RecoverDlc); | ||
FLog.debug(text: "Received a recover dlc event. Status: ${recoverDlc.taskStatus}"); | ||
|
||
taskStatus = recoverDlc.taskStatus; | ||
|
||
if (taskStatus == TaskStatus.pending) { | ||
// initialize dialog for the pending task | ||
showDialog( | ||
context: shellNavigatorKey.currentContext!, | ||
builder: (context) { | ||
TaskStatus status = context.watch<RecoverDlcChangeNotifier>().taskStatus; | ||
|
||
// todo(holzeis): Reusing the order submission status dialog is not nice, but it's actually suitable for any task execution that has pending, | ||
// failed and success states. We may should consider renaming this dialog for its more generic purpose. | ||
OrderSubmissionStatusDialogType type = OrderSubmissionStatusDialogType.pendingSubmit; | ||
switch (status) { | ||
case TaskStatus.pending: | ||
type = OrderSubmissionStatusDialogType.successfulSubmit; | ||
case TaskStatus.failed: | ||
type = OrderSubmissionStatusDialogType.failedFill; | ||
case TaskStatus.success: | ||
type = OrderSubmissionStatusDialogType.filled; | ||
} | ||
|
||
late Widget content = const Text("Recovering your dlc channel"); | ||
|
||
return OrderSubmissionStatusDialog(title: "Catching up!", type: type, content: content); | ||
}, | ||
); | ||
} else { | ||
// notify dialog about changed task status | ||
notifyListeners(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.