alephium / alephium-frontend

A monorepo containing all things frontend on Alephium.
Other
11 stars 9 forks source link

Automatically switch apps when dApp asks for signing #55

Open nop33 opened 8 months ago

nop33 commented 8 months ago

Subtasks

Android

iOS

Description

  1. When connecting to the Uniswap dApp through WalletConnect in a mobile browser and trying to make a swap, Metamask, Rainbow, and Argent, all pop up to sign the request from the dApp (the user doesn't have to manually switch apps).
  2. When the request is signed or rejected, the browser app is brought back to focus. EDIT: On iOS 17 this is not the case anymore.

Related issues

Related to alephium/alephium-frontend#95

Related resources

mvaivre commented 8 months ago

That would be much better than the in-browser wallet IMO, as you can keep the browser state independent from the app state.

diomark commented 8 months ago

You're mentioning a second issue that I know I was experiencing but didn't report - that after signing, you stay in the wallet. (it really should popup wallet to sign, then go back to browser after)

MaudSimon commented 8 months ago

Adding a feedback on this issue as I think it's relevant for prioritization: "this ONE issue though means I keep using kiwi browser (with extention wallet loaded) for dapps instead of the mobile wallet as it works smoother".

diomark commented 8 months ago

The main issue is that when you sign something from chrome/mobile, nothing happens.. you have to know to switch manually to wallet and confirm the signing request that's there - and once you do, manually switch back..

It should popup the wallet on signing request and go back to the dapp/chrome tab when done signing

nop33 commented 8 months ago

Thanks for the feedback both of you. We'll prioritise the task accordingly!

nop33 commented 7 months ago

Regarding (3) on Android.

The WalletConnect docs say:

To receive signing request in your Wallet, you'll need to initialize Kotlin SDK with the Redirect object where you pass a deep link that redirects to your wallet when it comes to receiving signing request from Dapp.

val redirect = "kotlin-wallet-wc://request" //should be unique for your wallet

Instead of the Kotlin SDK we are using the @walletconnect/sign-client package. When initializing the SignClient we can pass a redirect object that can have 2 props: native and/or universal. This is what Rainbow and Metamask use respectively:

// Rainbow
redirect: {
  native: 'rainbow://wc',
  universal: 'https://rnbwapp.com/wc'
}

// Metamask
redirect: {
  native: 'metamask://',
  universal: 'https://metamask.app.link/'
}

As expected, the custom schemes are also part of the respective AndroidManifest.xml files:

They also register wc as a custom scheme, like we do.

I tried registering the alephium scheme, but I haven't managed to make it work yet. I can verify that the alephium scheme is correctly registered because the app comes to focus when I run

bunx uri-scheme open alephium:// --android

It also works if I run

adb shell am start -W -a android.intent.action.VIEW -d "alephium://" org.alephium.wallet

In the Kotlin example mentioned in the WalletConnect docs, I see that the redirect prop they use is:

kotlin-web3wallet:/request

The interesting thing about this is:

  1. It uses a single /
  2. kotlin-web3wallet is not registered as a scheme in the AndroidManifest file, but it is mentioned in:
    1. https://github.com/WalletConnect/WalletConnectKotlinV2/blob/master/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletNavGraph.kt#L147
    2. https://github.com/WalletConnect/WalletConnectKotlinV2/blob/master/sample/wallet/src/main/res/navigation/nav_graph.xml#L18-L20
mvaivre commented 7 months ago

Wonderful research!

I'd go with the simplest option: "Simply display a success message that says "Success, you can go back to your browser" and not try to automatically switch to the mobile browser".

This has many advantages:

This flow is used in many payments apps btw, like twint in CH.

WDYT? We can talk more about that tmr.

nop33 commented 7 months ago

I agree. That will take care of tasks (2) and (4) for both Android and iOS.

We still need to figure out (1) for iOS and and (3) for both Android and iOS.

nop33 commented 7 months ago

This article makes me think that the redirect might need to be set on the dApp side as well... https://medium.com/@felipe.aga/how-to-use-walletconnect-with-react-native-ffe76d88566

nop33 commented 7 months ago

To solve the point (1) for iOS, I've been working on registering our mobile wallet app to the WalletConnect Explorer, but I am stuck at this step. "Alephium" is not listed in the supported chains:

Click here to see screenshots image ![image](https://github.com/alephium/alephium-frontend/assets/1579899/aa39e89b-0d76-43ee-b6ab-944c693199f4)

Maybe we need to register our chain?

If you don't see your chain listed in this list, then you will need to create an issue in GitHub to to get the process started. You can do so by clicking here. Once your chain is added to this list, wallets & dapps will be able to indicate support for your chain via WalletConnect's Cloud. https://docs.walletconnect.com/advanced/multichain/overview

nop33 commented 5 months ago

@mvaivre I moved this to the following release. However, there doesn't seem to be a high demand for the remaining subtasks (iOS-related). Besides, as the commend above mentions, we need to first register our app with WC Cloud. I propose we de-prioritize this task until it's really needed by our community (basically remove it from our milestones for now and focus on other tasks).

nop33 commented 5 months ago

ping @mvaivre

nop33 commented 3 weeks ago

We need to re-prioritize this issue due to popular demand.