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

draft: Remove the business logic from UI components #16387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexjba
Copy link
Contributor

@alexjba alexjba commented Sep 24, 2024

What does the PR do

Separation of concerns

  1. Issue: The UI components depend on the WalletConnectService and also on its dependencies like DAppsRequestHAndler. As a result the UI components have a hard dependency on the WalletConnect specifics and are incompatible with BC. This results in duplication of logic.
  2. Issue: The UI components operate on WalletConnect specific JSON object. E.g. session objects, session proposal etc. As a result the UI is built around the WalletConnect message format.
  3. Issue: The UI components operate on ListModel items received through functions and stored internally. Any change in the model would result in a crash.
  • Solution: Remove the WalletConnectService dependency from DAppsWorkflow. The DAppsWorkflow now operates with models, signals and functions. This is the first step in the broader refactoring. Moving the logic into the service itself will allow us to further refactor the WC and BC.

How does it work now:

  1. Dependencies - The UI components have a dependency on models. SessionRequestsModel and DAppsModel.
  2. Pairing - The pairing is initiated in the UI. On user input a pairingValidationRequested signal is emitted and the result is received as a function pairingValidated. If the url is valid the UI requests a pairingRequested. When the WalletConnectService is refactored we can go further and request only pairingRequested and to receive a pairingResult call as a function with the result. In the current implementation on pairingRequested we'll receive a connectDApp request.
  3. Connecting dApps - The flow is initiated with connectDApp function. This call currently contains all the needed info as args. In the next step it could be replaced with a ConnectionRequests model. The connectDApp call triggered a connection popup if we're not currently showing one to the user. If we're currently showing one it will be queued (corner case). The connection can be accepted with connectionAccepted and rejected with connectionDeclined. Once the connection is accepted we're expecting a result connectionSuccessful or connectionFailed. The connectionSuccessful also expects a new id for the established connection.
  4. Signing - The signing flow orbits around the SessionRequestsModel. Each item from the model will generate a popup showing the sign details to the user. Sign can be accepted or rejected using signRequestAccepted or signRequestRejected. No response is currently expected. The model is expected to remove the sign request item.

Next steps:
WC service refactoring to bring in a separation of concerns and to make it interoperable with WC and BC. This should result in flow simplification and remove the duplication of logic.

Affected areas

Architecture compliance

  • I am familiar with the application architecture and agreed good practices.
    My PR is consistent with this document: Architecture guidelines

Screenshot of functionality (including design for comparison)

  • I've checked the design and this PR matches it

@status-im-auto
Copy link
Member

status-im-auto commented Sep 24, 2024

Jenkins Builds

Click to see older builds (62)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ dcace41 #1 2024-09-24 09:38:43 ~6 min macos/aarch64 🍎dmg
✔️ dcace41 #1 2024-09-24 09:39:34 ~7 min tests/nim 📄log
dcace41 #1 2024-09-24 09:42:53 ~10 min tests/ui 📄log
✔️ dcace41 #1 2024-09-24 09:46:57 ~14 min linux-nix/x86_64 📦tgz
✔️ dcace41 #1 2024-09-24 09:49:12 ~16 min macos/x86_64 🍎dmg
✔️ dcace41 #1 2024-09-24 09:50:42 ~18 min linux/x86_64 📦tgz
✔️ dcace41 #1 2024-09-24 09:55:39 ~23 min windows/x86_64 💿exe
5d1af60 #2 2024-09-25 08:19:11 ~3 min macos/aarch64 📄log
✔️ 5d1af60 #2 2024-09-25 08:22:54 ~7 min tests/nim 📄log
5d1af60 #2 2024-09-25 08:23:18 ~7 min macos/x86_64 📄log
5d1af60 #2 2024-09-25 08:23:26 ~7 min linux-nix/x86_64 📄log
5d1af60 #2 2024-09-25 08:25:27 ~9 min tests/ui 📄log
5d1af60 #2 2024-09-25 08:29:07 ~13 min linux/x86_64 📄log
✔️ 5d1af60 #2 2024-09-25 08:34:50 ~18 min windows/x86_64 💿exe
✔️ f9b9efb #3 2024-09-25 08:46:46 ~4 min macos/aarch64 🍎dmg
✔️ f9b9efb #3 2024-09-25 08:49:13 ~6 min tests/nim 📄log
✔️ f9b9efb #3 2024-09-25 08:50:42 ~8 min macos/x86_64 🍎dmg
f9b9efb #3 2024-09-25 08:51:56 ~9 min tests/ui 📄log
✔️ f9b9efb #3 2024-09-25 08:55:25 ~13 min linux-nix/x86_64 📦tgz
✔️ f9b9efb #3 2024-09-25 08:59:11 ~16 min linux/x86_64 📦tgz
✔️ f9b9efb #3 2024-09-25 09:00:53 ~18 min windows/x86_64 💿exe
✔️ 88329fb #4 2024-09-25 11:51:41 ~4 min macos/aarch64 🍎dmg
✔️ 88329fb #4 2024-09-25 11:54:07 ~6 min tests/nim 📄log
✔️ 88329fb #4 2024-09-25 11:56:39 ~9 min macos/x86_64 🍎dmg
88329fb #4 2024-09-25 11:56:58 ~9 min tests/ui 📄log
✔️ 88329fb #4 2024-09-25 12:00:01 ~12 min linux-nix/x86_64 📦tgz
✔️ 88329fb #4 2024-09-25 12:03:45 ~16 min linux/x86_64 📦tgz
✔️ 88329fb #4 2024-09-25 12:06:13 ~18 min windows/x86_64 💿exe
✔️ cdfb9eb #5 2024-09-25 14:43:09 ~4 min macos/aarch64 🍎dmg
✔️ cdfb9eb #5 2024-09-25 14:45:25 ~6 min tests/nim 📄log
✔️ cdfb9eb #5 2024-09-25 14:47:50 ~9 min macos/x86_64 🍎dmg
cdfb9eb #5 2024-09-25 14:48:14 ~9 min tests/ui 📄log
✔️ cdfb9eb #5 2024-09-25 14:51:35 ~12 min linux-nix/x86_64 📦tgz
✔️ cdfb9eb #5 2024-09-25 14:55:48 ~17 min linux/x86_64 📦tgz
✔️ cdfb9eb #5 2024-09-25 14:58:43 ~19 min windows/x86_64 💿exe
✔️ 2ec49fc #6 2024-09-26 10:30:48 ~4 min macos/aarch64 🍎dmg
✔️ 2ec49fc #6 2024-09-26 10:33:14 ~6 min tests/nim 📄log
✔️ 2ec49fc #6 2024-09-26 10:35:29 ~9 min macos/x86_64 🍎dmg
2ec49fc #6 2024-09-26 10:35:48 ~9 min tests/ui 📄log
✔️ 2ec49fc #6 2024-09-26 10:38:18 ~12 min linux-nix/x86_64 📦tgz
✔️ 2ec49fc #6 2024-09-26 10:42:33 ~16 min linux/x86_64 📦tgz
✔️ 2ec49fc #6 2024-09-26 10:46:03 ~19 min windows/x86_64 💿exe
✔️ 40085b5 #7 2024-09-26 11:46:52 ~7 min tests/nim 📄log
✔️ 40085b5 #7 2024-09-26 11:47:58 ~8 min macos/aarch64 🍎dmg
40085b5 #7 2024-09-26 11:49:14 ~9 min tests/ui 📄log
✔️ 40085b5 #7 2024-09-26 11:51:46 ~12 min macos/x86_64 🍎dmg
✔️ 40085b5 #7 2024-09-26 11:55:34 ~16 min linux/x86_64 📦tgz
✔️ 40085b5 #7 2024-09-26 11:56:43 ~17 min linux-nix/x86_64 📦tgz
✔️ 40085b5 #7 2024-09-26 11:58:28 ~18 min windows/x86_64 💿exe
✔️ e96cde4 #8 2024-10-02 09:21:26 ~4 min macos/aarch64 🍎dmg
✔️ e96cde4 #8 2024-10-02 09:23:31 ~6 min tests/nim 📄log
e96cde4 #8 2024-10-02 09:25:55 ~9 min tests/ui 📄log
✔️ e96cde4 #8 2024-10-02 09:28:41 ~12 min macos/x86_64 🍎dmg
✔️ e96cde4 #8 2024-10-02 09:29:54 ~13 min linux/x86_64 📦tgz
✔️ e96cde4 #8 2024-10-02 09:35:45 ~19 min windows/x86_64 💿exe
✔️ 0a26f8d #9 2024-10-03 07:03:02 ~5 min macos/aarch64 🍎dmg
✔️ 0a26f8d #9 2024-10-03 07:04:30 ~6 min tests/nim 📄log
0a26f8d #9 2024-10-03 07:07:16 ~9 min tests/ui 📄log
✔️ 0a26f8d #9 2024-10-03 07:07:27 ~9 min macos/x86_64 🍎dmg
✔️ 0a26f8d #1 2024-10-03 07:13:16 ~15 min linux-nix/x86_64 📦tgz
✔️ 0a26f8d #9 2024-10-03 07:13:27 ~15 min linux/x86_64 📦tgz
✔️ 0a26f8d #9 2024-10-03 07:17:42 ~19 min windows/x86_64 💿exe
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ c85a031 #10 2024-10-03 13:52:20 ~4 min macos/aarch64 🍎dmg
✔️ c85a031 #10 2024-10-03 13:54:28 ~6 min tests/nim 📄log
✔️ c85a031 #10 2024-10-03 13:57:25 ~9 min macos/x86_64 🍎dmg
✔️ c85a031 #2 2024-10-03 13:59:35 ~11 min linux-nix/x86_64 📦tgz
c85a031 #10 2024-10-03 13:59:40 ~11 min tests/ui 📄log
✔️ c85a031 #10 2024-10-03 14:04:23 ~16 min linux/x86_64 📦tgz
✔️ c85a031 #10 2024-10-03 14:08:49 ~20 min windows/x86_64 💿exe
c85a031 #11 2024-10-03 18:30:54 ~7 min tests/ui 📄log
c85a031 #12 2024-10-03 18:42:55 ~7 min tests/ui 📄log
✔️ fde39e6 #12 2024-10-03 19:19:32 ~6 min macos/aarch64 🍎dmg
✔️ fde39e6 #12 2024-10-03 19:19:50 ~6 min tests/nim 📄log
fde39e6 #14 2024-10-03 19:23:39 ~10 min tests/ui 📄log
✔️ fde39e6 #12 2024-10-03 19:24:59 ~12 min macos/x86_64 🍎dmg
✔️ fde39e6 #4 2024-10-03 19:28:45 ~15 min linux-nix/x86_64 📦tgz
✔️ fde39e6 #12 2024-10-03 19:29:30 ~16 min linux/x86_64 📦tgz
✔️ fde39e6 #12 2024-10-03 19:32:05 ~19 min windows/x86_64 💿exe

@alexjba alexjba force-pushed the feat/wc-handle-sign-timeout branch 3 times, most recently from 2ec49fc to 40085b5 Compare September 26, 2024 11:39
Makefile Outdated
@@ -628,6 +628,7 @@ $(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop
-no-copy-copyright-files \
-qmldir=ui -qmlimport=$(QT5_QMLDIR) \
-bundle-non-qt-libs \
-exclude-libs="libnss3.so,libnssutil3.so,libgmodule-2.0.so.0,libgthread-2.0.so.0" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yakimant This seems to fix the app crash on initialisation. But I still have issues with missing resources for QtWebEngineView.

const session = { url, name, iconUrl }
root.wcService.connectorDAppsProvider.addSession(JSON.stringify(session))

root.wcService.connectorDAppsProvider.addSession(url, name, iconUrl)
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexjba account param is missing here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It could be that's the reason, or maybe something else, but after I locally added the address I still was not able to connect to https://rarible.com vai browser connect (checked, the entry was in the db, but no connection was made on the dapp's side neither in the Stauts app).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will have a look

@saledjenic
Copy link
Contributor

In general, you've definitely made nice improvements here.


I made a data flow map of how I see BC and WC in the Status app working together and would like to discuss it. Please have a look.

BC_WC data flow

Basically, a dapp is a dapp, and we don't defer daps in the UI how they were connected (via WC or BC).
Also, all WC connections are coming from the wallet connect SDK and there is no other way to interact with those dapps except via WcSDK. On the other hand, all requests from the dapps connected via Status Browser Plugin are coming from the statusgo side and no other way to interact with those dapps except via statusgo. Because of that, we know where the request comes from and where we should send the response. Having that in mind we can simplify implementation in a way:

  • connector_dapps and wallet_connect_dapps tables can be merged into a single one with just a flag to know if the dapp was connected via BC or WC (or maybe better some enum instead of bool flag in case we support some other method in future)
  • we need only WC-related implementation on the qml side (look now how many functions that do the same/almost the same things we have on the qml side, just search the qml for functions like getTxObject, isTransactionMethod, prepareData, executeSessionRequest, extractMethodData...).
  • we need to map all BC requests to the form that will be recognized by WC implementation in the Stauts app, which is the same form WalletConnect is using.

@alexjba wdyt about that idea?

Copy link
Member

@micieslak micieslak left a comment

Choose a reason for hiding this comment

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

Looks good in general, that's nice that DAppsWorkflow is UI-only now.

What is missing for from my perspective (I had no earlier experience with that topic) is description of the DAppsWorkflow API - what's the expected structure of the models, what are the parameters of signals/methods, what's the expected flow of signals/method calls.

It would be nice to have also subcomponents in their own storybook pages, instantiated with some simple, synthetic data. Maybe even DAppsWorkflow could have SB page which is fully mocked. I think it would clearly show what's the intended flow/order of actions.

@alexjba alexjba force-pushed the feat/wc-handle-sign-timeout branch 2 times, most recently from e96cde4 to 0a26f8d Compare October 3, 2024 06:57
@status-im-auto
Copy link
Member

This commit brings a separation of concerns for the UI components involved in dApp interactions.

Issue: The UI components depend on the WalletConnectService and also on its dependencies like DAppsRequestHAndler. As a result the UI components have a hard dependency on the WalletConnect specifics and are incompatible with BC. This results in duplication of logic.
Issue: The UI components operate on WalletConnect specific JSON object. E.g. session objects, session proposal etc. As a result the UI is built around the WalletConnect message format.
Issue: The UI components operate on ListModel items received through functions and stored internally. Any change in the model would result in a crash.
Solution: Remove the WalletConnectService dependency from DAppsWorkflow. The DAppsWorkflow now operates with models, signals and functions. This is the first step in the broader refactoring. Moving the logic into the service itself will allow us to further refactor the WC and BC.

How does it work now:

Dependencies - The UI components have a dependency on models. SessionRequestsModel and DAppsModel.
Pairing - The pairing is initiated in the UI. On user input a pairingValidationRequested signal is emitted and the result is received as a function pairingValidated. If the url is valid the UI requests a pairingRequested. When the WalletConnectService is refactored we can go further and request only pairingRequested and to receive a pairingResult call as a function with the result. In the current implementation on pairingRequested we'll receive a connectDApp request.
Connecting dApps - The flow is initiated with connectDApp function. This call currently contains all the needed info as args. In the next step it could be replaced with a ConnectionRequests model. The connectDApp call triggered a connection popup if we're not currently showing one to the user. If we're currently showing one it will be queued (corner case). The connection can be accepted with connectionAccepted and rejected with connectionDeclined. Once the connection is accepted we're expecting a result connectionSuccessful or connectionFailed. The connectionSuccessful also expects a new id for the established connection.
Signing - The signing flow orbits around the SessionRequestsModel. Each item from the model will generate a popup showing the sign details to the user. Sign can be accepted or rejected using signRequestAccepted or signRequestRejected. No response is currently expected. The model is expected to remove the sign request item.
@alexjba alexjba force-pushed the feat/wc-handle-sign-timeout branch from c85a031 to 05ec6a4 Compare October 3, 2024 19:12
@alexjba alexjba force-pushed the feat/wc-handle-sign-timeout branch from 05ec6a4 to fde39e6 Compare October 3, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants