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(wallet) integrate Wallet Connect sign APIs #12716

Merged
merged 1 commit into from
Nov 15, 2023
Merged

Conversation

stefandunca
Copy link
Contributor

@stefandunca stefandunca commented Nov 13, 2023

Closes #12637

The current WebView-QML communication is at a prototype stage to show that the integration works. The current work to make it robust is subsequent with this work package: #12639

Bump status-go to #4279

Extend SDK

  • simple SDK event handling in QML
  • support session request response APIs
  • pairing management

@status-im-auto
Copy link
Member

status-im-auto commented Nov 13, 2023

Jenkins Builds

Click to see older builds (19)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ b6c766d #1 2023-11-13 16:59:49 ~5 min tests/nim 📄log
✔️ b6c766d #1 2023-11-13 17:01:23 ~7 min macos/aarch64 🍎dmg
✔️ b6c766d #1 2023-11-13 17:06:13 ~12 min tests/ui 📄log
✔️ b6c766d #1 2023-11-13 17:07:01 ~13 min macos/x86_64 🍎dmg
✔️ b6c766d #1 2023-11-13 17:10:58 ~17 min linux/x86_64 📦tgz
✖️ b6c766d #1 2023-11-13 17:16:49 ~22 min tests/e2e 📄log
✔️ b6c766d #1 2023-11-13 17:30:15 ~36 min windows/x86_64 💿exe
✔️ 6360bbd #3 2023-11-13 19:06:39 ~5 min tests/nim 📄log
✔️ 6360bbd #3 2023-11-13 19:09:22 ~7 min macos/aarch64 🍎dmg
✔️ 6360bbd #3 2023-11-13 19:12:26 ~10 min macos/x86_64 🍎dmg
✔️ 6360bbd #3 2023-11-13 19:14:15 ~12 min tests/ui 📄log
✔️ 6360bbd #3 2023-11-13 19:18:28 ~17 min linux/x86_64 📦tgz
✔️ 6360bbd #3 2023-11-13 19:35:29 ~33 min windows/x86_64 💿exe
✖️ 6360bbd #3 2023-11-13 19:58:12 ~56 min tests/e2e 📄log
✔️ 7236701 #5 2023-11-14 18:29:25 ~7 min tests/nim 📄log
✔️ 7236701 #5 2023-11-14 18:32:35 ~10 min macos/x86_64 🍎dmg
✔️ 7236701 #5 2023-11-14 18:35:28 ~13 min tests/ui 📄log
✔️ 7236701 #5 2023-11-14 18:37:39 ~15 min linux/x86_64 📦tgz
✖️ 7236701 #5 2023-11-14 18:40:28 ~18 min tests/e2e 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 47f546c #6 2023-11-15 14:25:10 ~5 min macos/aarch64 🍎dmg
✔️ 47f546c #6 2023-11-15 14:26:35 ~7 min tests/nim 📄log
✔️ 47f546c #6 2023-11-15 14:27:47 ~8 min macos/x86_64 🍎dmg
✔️ 47f546c #6 2023-11-15 14:34:03 ~14 min tests/ui 📄log
✔️ 47f546c #6 2023-11-15 14:34:10 ~14 min linux/x86_64 📦tgz
✔️ 47f546c #6 2023-11-15 14:52:04 ~32 min tests/e2e 📄log
✔️ 1024a4d #9 2023-11-15 14:59:27 ~5 min macos/aarch64 🍎dmg
✔️ 1024a4d #9 2023-11-15 15:02:28 ~8 min macos/x86_64 🍎dmg
✔️ 1024a4d #9 2023-11-15 15:04:14 ~9 min tests/ui 📄log
✔️ 1024a4d #9 2023-11-15 15:08:51 ~14 min linux/x86_64 📦tgz
✔️ 1024a4d #10 2023-11-15 15:20:30 ~6 min tests/nim 📄log
✔️ 1024a4d #9 2023-11-15 15:28:02 ~33 min tests/e2e 📄log

@stefandunca stefandunca force-pushed the wc_sign_api-12637 branch 3 times, most recently from 6360bbd to 7236701 Compare November 14, 2023 18:18
@stefandunca stefandunca marked this pull request as ready for review November 14, 2023 18:21
@stefandunca stefandunca changed the base branch from master to wc_pair_api-12551 November 14, 2023 18:21
}
}
)
eventsTimer.start()
Copy link
Contributor

@saledjenic saledjenic Nov 15, 2023

Choose a reason for hiding this comment

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

@stefandunca I don't see that we ever stop this timer, probably that was your intention to check every 100ms for a change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. We start it after pairing and never stop until the WalletConnectSDK is unloaded. When we add a un-pair/disconnect we will stop the timer then.

function requestSdkAsync(jsCode) {
root.runJavaScript(jsCode,
function(result) {
timer.restart()
Copy link
Contributor

@saledjenic saledjenic Nov 15, 2023

Choose a reason for hiding this comment

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

@stefandunca why don't we create and call for example "handleResponse(result)" function from here instead of running the timer? Guess that the result here is the same as wcResult used in onTriggered slot of the timer? The same question is for the same part in requestSdk function.

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 due to the polling mechanism that we use to track the result of async operations running inside WebView. The handler here is returning after the async operation was started and timer will check regularly for the answer then stop. I'm working to improve this part and make it more robust. Still, the only option we have now is to communicate between QML runtime and WebView runtime without creating a client/server approach which is unsafe.

function startListeningForEvents() {
const jsCode = "
try {
async function processWCEvents() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@stefandunca why is this async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a recommended way of running calls without blocking the WebView runtime thread. For this specific call, it is optional; however, I plan to improve on this with my current work, which will enhance the robustness of the webview-qml communication.

disconnect: function (topic) {
return window.wc.core.pairing.disconnect({ topic: topic});
},

registerForSessionRequest: function (callback) {
window.wc.web3wallet.on("session_request", callback);
Copy link
Contributor

Choose a reason for hiding this comment

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

@stefandunca is it safe to call many many times this? Like does web3wallet handle multiple listeners for the same event with or without overwriting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

registerForSessionRequest is called only once after SDK is initialized. Will improve though, with my current work.

}
window.wcEventError"

root.runJavaScript(jsCode,
Copy link
Contributor

Choose a reason for hiding this comment

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

@stefandunca why is it not enough to call jsCode only once and then check in a loop (using a timer) for window.wcEventResult instead of calling registerForSessionRequest every time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call startListeningForEvents which executes registerForSessionRequest is called only once after the SDK initializes.

Copy link
Contributor

@IvanBelyakoff IvanBelyakoff left a comment

Choose a reason for hiding this comment

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

Great job, Stefan!

@@ -24,7 +25,7 @@ window.wc = {
metadata: {
name: "Status",
description: "Status Wallet",
url: "https://status.app",
url: "http://localhost",
Copy link
Contributor

Choose a reason for hiding this comment

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

It is temporary or leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a fix for MacOS DMG sand-boxing generating a warning that the status.app is not allowed by the signing. We don't do a request to any domain so we just silence the warning.

Base automatically changed from wc_pair_api-12551 to master November 15, 2023 14:51
@status-im-auto
Copy link
Member

Bump status-go that brings the sign APIs support for send transaction
and personal sign

Extend SDK

- simple SDK event handling in QML
- support session request response APIs
- pairing management

Closes #12637
@stefandunca stefandunca merged commit 783a755 into master Nov 15, 2023
7 of 9 checks passed
@stefandunca stefandunca deleted the wc_sign_api-12637 branch November 15, 2023 16:21
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.

Implement WalletConnect Sign API (stub UI)
4 participants