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(DApps): Refactoring wallet connect service and bring BrowserConnect inline with WC #16730

Draft
wants to merge 2 commits into
base: 14996-add-siwe-to-sign-in-via-wallet-connect
Choose a base branch
from

Conversation

alexjba
Copy link
Contributor

@alexjba alexjba commented Nov 7, 2024

What does the PR do

Closes: #16044 #15936 #15711

Needs status-go PR: status-im/status-go#6051

This is the final PR in the dapps refactoring. At this point the WalletConnect and BrowserConnect is using the same UI and the same qml processing.

  1. 417ce05 - Unify dapp sessions between Wallet Connect and Browser Connect
  2. e74fe00 - Unify dapp signing between WalletConnect and Browser Connect

Next step for later: Refactor the test_DAppsWorkflow.qml. Currently it's testing everything E2E. But now we have the component separation needed to test everything in isolation.

Affected areas

Wallet Connect
Browser Connect

Architecture compliance

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 Nov 7, 2024

Jenkins Builds

Click to see older builds (12)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ e74fe00 #1 2024-11-07 09:32:09 ~6 min tests/nim 📄log
✔️ e74fe00 #1 2024-11-07 09:32:13 ~6 min macos/aarch64 🍎dmg
e74fe00 #1 2024-11-07 09:35:42 ~10 min tests/ui 📄log
✔️ e74fe00 #1 2024-11-07 09:44:29 ~19 min linux/x86_64 📦tgz
✔️ e74fe00 #1 2024-11-07 09:44:40 ~19 min macos/x86_64 🍎dmg
✔️ e74fe00 #1 2024-11-07 09:47:15 ~22 min linux-nix/x86_64 📦tgz
✔️ e74fe00 #1 2024-11-07 09:53:38 ~28 min windows/x86_64 💿exe
e74fe00 #2 2024-11-07 10:04:05 ~9 min tests/ui 📄log
✔️ e74fe00 #2 2024-11-07 12:18:26 ~4 min macos/aarch64 🍎dmg
e74fe00 #2 2024-11-07 12:20:24 ~6 min windows/x86_64 📄log
✔️ e74fe00 #2 2024-11-07 12:20:50 ~7 min tests/nim 📄log
e74fe00 #3 2024-11-07 12:23:54 ~10 min tests/ui 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ b6aae86 #3 2024-11-07 12:31:19 ~4 min macos/aarch64 🍎dmg
b6aae86 #3 2024-11-07 12:31:23 ~4 min linux-nix/x86_64 📄log
✔️ b6aae86 #3 2024-11-07 12:33:33 ~7 min tests/nim 📄log
b6aae86 #4 2024-11-07 12:36:59 ~10 min tests/ui 📄log
✔️ b6aae86 #3 2024-11-07 12:44:13 ~17 min linux/x86_64 📦tgz
✔️ b6aae86 #3 2024-11-07 12:44:33 ~18 min macos/x86_64 🍎dmg
✔️ b6aae86 #3 2024-11-07 12:51:14 ~24 min windows/x86_64 💿exe
✔️ 698cbee #4 2024-11-08 14:52:41 ~4 min macos/aarch64 🍎dmg
✔️ 698cbee #4 2024-11-08 14:55:30 ~7 min tests/nim 📄log
698cbee #5 2024-11-08 14:57:24 ~9 min tests/ui 📄log
✔️ 698cbee #4 2024-11-08 15:03:17 ~15 min macos/x86_64 🍎dmg
✔️ 698cbee #4 2024-11-08 15:04:15 ~16 min linux/x86_64 📦tgz
✔️ 698cbee #4 2024-11-08 15:05:30 ~17 min linux-nix/x86_64 📦tgz

@@ -21,6 +21,8 @@ type ConnectorGrantDAppPermissionSignal* = ref object of Signal
url*: string
name*: string
iconUrl*: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These arguments were missing from the integration. We need to know in the UI on what account a dapp is connected and on what chains.

proc dappValidatesTransaction*(self: Controller, requestId: string, payload: string) {.signal.}
proc dappGrantDAppPermission*(self: Controller, payload: string) {.signal.}
proc dappRevokeDAppPermission*(self: Controller, payload: string) {.signal.}
proc connectRequested*(self: Controller, requestId: string, payload: string) {.signal.}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added request-response pair for the API. This is needed in the UI because it's reacting only on the response. From this point on the nim requests can be done asynchronous.

@@ -137,4 +137,17 @@ QtObject:

except Exception as e:
error "recallDAppPermissionFinishedRpc failed: ", err=e.msg
return false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no way to fetch all the dapps from persistence.

@@ -69,8 +69,8 @@ DappsComboBox {
signal disconnectRequested(string connectionId)
signal pairingRequested(string uri)
signal pairingValidationRequested(string uri)
signal connectionAccepted(var pairingId, var chainIds, string selectedAccount)
signal connectionDeclined(var pairingId)
signal connectionAccepted(string pairingId, var chainIds, string selectedAccount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to keep things inline and the pairing ids and topics to be strings in all signals

@@ -138,37 +138,37 @@ Item {
id: dappsWorkflow
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 this file I've only renamed the WalletConnectService to DAppsService

}
}
*/
function parse(event, hexToDec = (hex) => { return parseInt(hex, 16) }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now all the session request parsing happens in this singletone component. There's also a storybook page where we can paste any WC/BC session request to investigate the resulted object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code moved from the request handler. I've split the stateful implementation and the parsing. This component provides just the parsing.

@@ -48,30 +46,11 @@ QObject {
/// maps to Constants.TransactionEstimatedTime values
property int estimatedTimeCategory: 0

function resolveDappInfoFromSession(session) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed. The dapp metadata is known in advanced. This is now provided by the DAppsModel and we don't need to always do asynchronous calls to the sdk to get this kind of info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This component will parse the session request and validated based on app data (accountsModel, networksModel)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

QML entry point for BrowserConnect calls.

@alexjba alexjba force-pushed the feat/enable_Wallet_connect branch 2 times, most recently from ae0a35f to b4e22be Compare November 7, 2024 10:38
Base automatically changed from feat/enable_Wallet_connect to 14996-add-siwe-to-sign-in-via-wallet-connect November 7, 2024 12:13
@alexjba alexjba force-pushed the 14996-add-siwe-to-sign-in-via-wallet-connect branch from 8efad11 to 4636f80 Compare November 7, 2024 19:06
New component introduced (DAppsModel) to provide a common model for WC and BC. The WCDappsProvider and BCDappsProvider components are responsible to fill the model from different sources
This PR is refactoring the dapps service to avoid code duplication between SDKs and also to avoid overlapping requests/responses.
It brings Browser Connect inline with Wallet Connect in terms of session management and sign transactions.

New architecture:

WalletConnectService becomes DAppsService. Its responsibility is to provide dapp access to the app. This is the component currently used by the UI
What does it do:
1. Provide dapp APIs line connect, disconnect, session requests etc
2. Spawn app notifications on dapp events
3. Timeout requests if the dapp does not respons

DAppsRequestHandler becomes DAppsModule. This component is consumed by the DAppService. Its responsibility is to aggregate all the building blocks for the dapps, but does not control any of the dapp features or consume the SDKs requests.
What does it do:
1. Aggregate all the building blocks for dapps (currently known as plugins)

DAppConnectionsPlugin - This component provides the session management features line connect, disconnect and provide a model with the connected dapps.
SignRequestPlugin - This component provides the sign request management. It receives the sign request from the dapp, translates it to what Status understands and manages the lifecycle of the request.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the sign logic from the dappsRequestHandler to be reused for both SDKs

return { obj: null, code: SessionRequest.RuntimeError }
}

updateFeesOnPreparedData(request)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@saledjenic minor changes to the new fees while resolving the conflicts. It's split in 2 parts. updateFeesOnPreparedData - Updating the preparedData for the user whenever the fees are null

updateFeesParamsToPassedObj - updates the fees for the modal

}

request.setExpired()
d.unsubscribeForFeeUpdates(request.topic, request.requestId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

another change is here, where we unsubscribe for fee updates if the request has expired.
cc @saledjenic

@@ -7,7 +7,7 @@ SequentialAnimation {

property var target: null
property color fromColor: Theme.palette.directColor1
property color toColor: Theme.palette.baseColor5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@saledjenic updated this when resolving the merge conflict. I don't see any difference for the Theme.palette.directColor1 and now it also works for other colors like danger1

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.

2 participants