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

feat: Rework task status dialog #2502

Merged
merged 32 commits into from
May 7, 2024
Merged

Conversation

holzeis
Copy link
Contributor

@holzeis holzeis commented May 4, 2024

I simplified a lot in this patch and addressed almost all shortcomings I noticed.

  • Dialogs will not overlap in case another dialog is already shown.
  • Errors will transported via the TaskStatus.failed type allowing us to also show errors on rollover, etc.
  • Errors are also reported if some intermediate protocol step fails.
  • Aligned background task handling to reduce the amount of boilerplate code required to add a new background task.
  • Simplified the dialog content. It will only show a text, but no margin, fee or pnl anymore. I opted to remove that in favor of simplicity and re-usability.
  • No use of global keys to access the current context.
  • Dialogs can now also be shown on the settings screen.
  • The trade dialog is created through an async trade task event (equal to an expired or liquidated order). Note, it is still created optimistically assuming we will immediately find a match or fail. Changing that though will be very easy now.
  • Removed the confetti in favor of a more clean success dialog. (There is still room for improvement though)
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-05-04.at.13.23.10.mp4

fixes #2381
fixes #2089
fixes #1995

@holzeis holzeis requested review from bonomat and luckysori May 4, 2024 11:25
@holzeis holzeis self-assigned this May 4, 2024
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from 44893d5 to cd406c2 Compare May 4, 2024 11:27
holzeis added 15 commits May 4, 2024 13:35
This will allow us to have root context, which can manage dialogs.
First step towards aggregating all dialogs to a single root context (xxi screen)
… notifier initialization

I don't know anymore why this was added in the first place, but it doesn't make much sense anymore.
Before we showed the trade dialog optimistically assuming we will get a dlc offer instantly, even though this is coming asynchronously.

 Although there was no issue with this yet, I think moving this to the xxi screen as well makes sense, because we might end up with orders not getting immediately matched.

 Also gets rid of a redundant show dialog.
This simplifies the handling of background tasks. Next we will adapt the async order change notifier to fit into the background task pattern. This will eventually allow us to prevent multiple dialogs to be shown at once.
This patch simplifies a lot of the logic that has grown historically. The key changes are the following:

- The AsyncTrade does not differentiate between manual or other order reasons.
- The TaskStatus.failed enum transports any error that happens during the trade. Replacing the `submitOrderError` and `failureReason`.
- The `PendingOrder` has been removed in favor of the `TaskStatus`. This gives us a little bit less information for the dialog, but this is in alignment with simplifying the task dialog in general.
- If the protocol fails at any point during the trade, the error will be reported to the task dialog. Before we had only a few scenarios where an error was actually reported back to the UI, depending on the dialog to time out. Note, if the protocol fails on the coordinator side the dialog would still have to time out since we do not yet send a `TradeError` message in that case.
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from cd406c2 to 891fc3f Compare May 4, 2024 11:35
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from 891fc3f to 3f06a74 Compare May 4, 2024 11:48
It feels more logical to show the new task event event if the previous event was of a different type.
Copy link
Contributor

@bonomat bonomat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much appreciated :)

Disclaimer: I didn't review the flutter code 🙈

holzeis added 2 commits May 6, 2024 08:25
This will allow us to clearly differentiate between a reopen/resize and a rollover protocol.

We need this in order to be able to add the order id to all trade related messages.

BREAKING change due to a changed protocol message
@holzeis
Copy link
Contributor Author

holzeis commented May 6, 2024

@bonomat @luckysori I've additionally addressed the issue that errors on the coordinator side are not reported back to the app, thus the dialog timing out. These errors are now reported back to the app. This is still done using the websocket, we should probably also think about refactoring the TadeError and RolloverError websocket messages to p2p protocol messages.

The last changes also wraps all dlc renew protocol steps into dedicated Rollover messages so we can distinguish properly between a reopen | resize and a rollover.

Additionally I've added the order_id to all trade messages (finally fixing #2136) and the order_reason to the settle messages so we can differentiate between a regular settlement and irregular settlements like liquidation and expired positions.

Please have a look, this is not just a frontend change.

@holzeis holzeis requested a review from bonomat May 6, 2024 14:35
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from 5bc7cd3 to ffb49d2 Compare May 6, 2024 18:26
Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. The scope is a bit out of control, so it's hard to review thoroughly, but I think the changes should not be very risky.

mobile/lib/common/xxi_screen.dart Outdated Show resolved Hide resolved
mobile/lib/common/xxi_screen.dart Outdated Show resolved Hide resolved
mobile/native/src/dlc/node.rs Outdated Show resolved Hide resolved
mobile/assets/error.gif Outdated Show resolved Hide resolved
Comment on lines 69 to 70
// update the active task to the last event received on the stack.
activeTask = task;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm not sure. I think it's just weird to receive a different DLC message when you are in the middle of another protocol.

Maybe we should not be bubbling up events that don't make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general that should never happen except for the following two scenarios.

  1. The user did not close the dialog and another event happens. I think in this case its fine to simple overwrite the current active task. (Note, the active task will only be set to null if the dialog is closed.
  2. The user reconnects in the middle of the protocol, that would trigger a RecoverDlc background task, which will change the task type. However the change is only maginal as only the text will be changed, stating that we lost connection and trying to recover.

All other scenarios would be bugs and I think it would be better to show them so they can be fixed instead of hiding them.

coordinator/src/emergency_kit.rs Outdated Show resolved Hide resolved
crates/xxi-node/src/message_handler.rs Outdated Show resolved Hide resolved
mobile/native/src/orderbook.rs Outdated Show resolved Hide resolved
mobile/native/src/trade/order/handler.rs Outdated Show resolved Hide resolved
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from ffb49d2 to e6a5e7c Compare May 7, 2024 10:33
holzeis added 6 commits May 7, 2024 13:10
This will allow us to uniquely identify the affected order

BREAKING change due to a change protocol message.
This is useful during development when we reload the dart files to automatically re-render the dialog. However, the logic is only intended to get executed when there is an actual event, so this will fail if we reload manually. Adding this catch makes development a bit easier.
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from e6a5e7c to 4fe862b Compare May 7, 2024 11:10
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch 2 times, most recently from 4f93e32 to 9de0610 Compare May 7, 2024 12:41
holzeis added 2 commits May 7, 2024 14:53
Note, the app could have crashed after the coordinator not being online for while since the round value grew indefinitely.
@holzeis holzeis force-pushed the chore/rework-trade-and-recover-dialog branch from 9de0610 to 67f7592 Compare May 7, 2024 12:53
@holzeis holzeis added this pull request to the merge queue May 7, 2024
Merged via the queue into main with commit f0f2710 May 7, 2024
22 checks passed
@holzeis holzeis deleted the chore/rework-trade-and-recover-dialog branch May 7, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants