metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

WalletConnect - MetaMask redirects to the App Store before transaction can be authorised

Open davidm03 opened this issue 2 years ago • 21 comments

Describe the bug When a user attempts to send a transaction from our dapp using WalletConnect and MetaMask - the MetaMask app will open, the transaction pop-up will appear with all the transaction details pre-filled from our dapp for a very brief period of time (maybe less than 1 second), then the MetaMask app will redirect/open the app store as if the user does not have MetaMask installed. If the user navigates back to the MetaMask app from the app store, the browser tab is open with the metamask.app.link url inserted but the user is not able to get the transaction pop-up to reappear and no response is sent back to our dapp ever.

To Reproduce Difficult to reproduce without access to our dapp but I'll do my best to explain.

  1. From a React Native dapp which uses WalletConnect - connect to your MetaMask wallet via WalletConnect pop-up window.
  2. Once MetaMask wallet is successfully connected and you have been redirected back to your dapp - attempt to call the WalletConnect sendTransaction function (code will be included below) using the same data.
  3. MetaMask mobile app is re-opened, transaction pop-up is displayed briefly before the app will redirect the user to the app store - as if they did not ever have it installed.

The following code is being used to call the sendTransaction function via WalletConnect after a user has connected a MetaMask wallet.

const sendTransaction = async (): Promise<void> => {
    await connector
      .sendTransaction({
        from: connector.accounts[0],
        to: "0xb81c36B5BCdDB20BFECE8F355DC5B212565AF907",
        value: Web3.utils.toHex(0.01 * 1e18),
        type: "native",
      })
      .then((res) => {
        console.log("Transaction Hash => ", res);
      })
      .catch((e) => console.warn(e));
  };

Expected behavior User is redirected to MetaMask to authorise the transaction, transaction pop-up is displayed to the user for authentication, app store should not open as the user already has the app installed, user is able to approve/reject the transaction and should the be redirected back to our dapp and response returned to WalletConnect sendTransaction function.

Smartphone (please complete the following information):

  • Device: iPhone XS
  • OS: iOS 15.4
  • App Version v4.2.2 (834)

davidm03 avatar Mar 18 '22 12:03 davidm03

Update: The issue is only happening on iOS devices and appears to be caused by line 136 within the WalletConnectProvider.js file

const url = formatWalletServiceUrl(walletService);
return (await Linking.canOpenURL(url)) && Linking.openURL(url);

Linking.openURL(url) launches MetaMask via the metamask.app.link URL and triggers the in-app browser, which is then redirecting the user to the app store - even if they have the app installed.

We've came up with a workaround for this issue and deployed a patch to use the connected wallet deeplink to launch the wallet app instead of the wallet service URL previously being generated.

const url = formatWalletServiceUrl(walletService);
return (await Linking.canOpenURL(url)) && Linking.openURL(walletService.mobile.native);

This resolves the issue for now, MetaMask opens correctly without redirected to the app store and the transaction pop-up is displayed correctly.

davidm03 avatar Mar 21 '22 12:03 davidm03

The universal URL should still open MetaMask without prompting the AppStore. Perhaps there is an issue with how they have configured the universal URL when opened with parameters (i.e. sending the sign personal message command via deep link).

Thanks for the quick fix info though. This could be a good alternative if the issue takes long to be resolved.

epshtielsl avatar Mar 28 '22 21:03 epshtielsl

Thanks @davidm03 and @epshtielsl. I'll test the fix and eventually integrate in the app. Thanks again.

andreahaku avatar Mar 29 '22 09:03 andreahaku

Any news about this problem?

rafaelaugustos avatar Apr 11 '22 16:04 rafaelaugustos

Any news about this problem?

yes also hoping for some news. Thanks.

zosim avatar Apr 12 '22 02:04 zosim

Me too. Looks so easy to solve this. Why they're taking so long?

thiagofreirebr avatar Apr 20 '22 16:04 thiagofreirebr

@davidm03 The fix you mentioned above, How can we use that fix when using walletconnect?? I can't find WalletConnectProvider.js in walletConnect.

joharzmn avatar Apr 21 '22 00:04 joharzmn

Did you try the latest version of the app (5.0.x) as most of the deep links related issue should be solved with it. Please let me know. Thanks!

andreahaku avatar Apr 25 '22 12:04 andreahaku

I still have the issue on iOS. Metamask deep link doesn't work. It still going to App Store.

fablanglet avatar May 03 '22 07:05 fablanglet

I still have the issue on iOS. Metamask deep link doesn't work. It still going to App Store.

Did you check the solution suggested here? https://github.com/MetaMask/metamask-mobile/issues/3965#issuecomment-1110690454

andreahaku avatar May 03 '22 10:05 andreahaku

@davidm03 The fix you mentioned above, How can we use that fix when using walletconnect?? I can't find WalletConnectProvider.js in walletConnect.

The file I mentioned can be found within node_modules > @walletconnect > react-native-dapp > providers > WalletConnectProvider.js

We used the patch package library to create a patch to apply this fix on every npm install and ensure it's not overridden.

davidm03 avatar May 03 '22 15:05 davidm03

I still have the issue on iOS. Metamask deep link doesn't work. It still going to App Store.

The same.

y0unghe avatar May 05 '22 09:05 y0unghe

@andreahaku i'm using 5.0.1 and still have the same issue in IOS Safari.

You can try it here https://cowswap.staging.gnosisdev.com (approving a token for example).

I use web3-react which delegates to @walletconnect/ethereum-provider . Any hint on how to debug/solve the issue? We are not the ones creating the deep links, I assume Wallet Connect is.

anxolin avatar May 05 '22 18:05 anxolin

I have same problem in my React Native app, but it is not happen in all apps

rafaelaugustos avatar Jun 12 '22 01:06 rafaelaugustos

Not sure if related but https://metamask.app.link/dapp/Google.com from iOS safari opens App Store while clicking the same link in any “inapp browser” (like Telegram or WhatsApp) does work

fopina avatar Jun 17 '22 07:06 fopina

Having the same issue on iOS. Wallet Connect opens the App Store even if MetaMask is installed + Wallet is setup.

antinomy-studio avatar Jun 28 '22 13:06 antinomy-studio

The solution for me was to ensure the web3 provider send request (RPC API) was the first network request after a user action.

I've deployed an example here forked from web3-react/example-next (v8) which consistently reproduces the issue when the checkbox is ticked on iOS by making a random async request first instead. Example diff here: https://github.com/xaun/web3-react/commit/694f7913ecc77191ff410c077881cd70e7b0f50e

I'm guessing this is something to do with mobile devices blocking redirections (deeplinks/universal links/or what not) that are not detected as derived from a user action.. something along the lines maybe? I'de love to know exactly why this behaviour occurs, as it's been a bit of a journey to figure out this "gotcha".

@davidm03 what invokes your sendTransaction method? Is there any async behaviour before it?

xaun avatar Jul 04 '22 05:07 xaun

The solution for me was to ensure the web3 provider send request (RPC API) was the first network request after a user action.

I've deployed an example here forked from web3-react/example-next (v8) which consistently reproduces the issue when the checkbox is ticked on iOS by making a random async request first instead. Example diff here: xaun/web3-react@694f791

I'm guessing this is something to do with mobile devices blocking redirections (deeplinks/universal links/or what not) that are not detected as derived from a user action.. something along the lines maybe? I'de love to know exactly why this behaviour occurs, as it's been a bit of a journey to figure out this "gotcha".

@davidm03 what invokes your sendTransaction method? Is there any async behaviour before it?

@xaun Very interesting solution + theory, thanks for sharing. As for my sendTransaction method - there is no async behaviour before it and it is invoked directly from a simple button onPress (onPress={sendTransaction} ).

davidm03 avatar Jul 06 '22 10:07 davidm03

Still happening for me...so frustrating.

LifeWithArt1 avatar Sep 03 '22 19:09 LifeWithArt1

Still an issue for me. I'm using Rainbow kit.

It also happens when you use Uniswap or AAVE and try to sign in with WalletConnect. Crazy it's still broken!

grp06 avatar Sep 12 '22 15:09 grp06

Also don't updated your Metamask on iOS to the latest version that was released recently or it'll completely stop working. The code example I gave above doesn't work anymore, nor does connecting with well known sites like Uniswap (noting they're using the same underlying web3-react lib).

xaun avatar Sep 14 '22 03:09 xaun

The solution for me was to ensure the web3 provider send request (RPC API) was the first network request after a user action.

I've deployed an example here forked from web3-react/example-next (v8) which consistently reproduces the issue when the checkbox is ticked on iOS by making a random async request first instead. Example diff here: xaun/web3-react@694f791

I'm guessing this is something to do with mobile devices blocking redirections (deeplinks/universal links/or what not) that are not detected as derived from a user action.. something along the lines maybe? I'de love to know exactly why this behaviour occurs, as it's been a bit of a journey to figure out this "gotcha".

@davidm03 what invokes your sendTransaction method? Is there any async behaviour before it?

For some reason this works for me for both spawnBug set or unset. But my app still redirects to appstore even when spawnBug is false. Any idea?

niraj-khatiwada avatar Sep 25 '22 14:09 niraj-khatiwada

This has frustrated me forever, but today I stumbled on a weird fix. I have no idea why it works, but it has for me every time.

When I initiate a transaction and am told to sign in my wallet, Im then automatically redirected to the App Store, to the MetaMask Page.

In the App Store, next to the MetaMask logo is a back arrow. (Not the one to go back to MetaMask, the one to go back to App Store home page) Tap dat.

Then, use the top left arrow to go back to MetaMask: for me, the place to sign is right there waiting.

Hope this works for others, I have no idea how or why it does for me.

Tdweller avatar Oct 01 '22 03:10 Tdweller

This has frustrated me forever, but today I stumbled on a weird fix. I have no idea why it works, but it has for me every time.

When I initiate a transaction and am told to sign in my wallet, Im then automatically redirected to the App Store, to the MetaMask Page.

In the App Store, next to the MetaMask logo is a back arrow. (Not the one to go back to MetaMask, the one to go back to App Store home page) Tap dat.

Then, use the top left arrow to go back to MetaMask: for me, the place to sign is right there waiting.

Hope this works for others, I have no idea how or why it does for me.

If the metamask is not in quit state, the transaction is already pending in metamask. Its just the redirection was gone to Appstore.

codeforreal1 avatar Oct 01 '22 05:10 codeforreal1

I had the same issue on my iPhone. Fixed it by long-pressing the MetaMask symbol when in the WalletConnect menu. You get a dropdown list whereafter you can select “Open with MetaMask”.

sra-fiberswitch avatar Nov 06 '22 09:11 sra-fiberswitch

Having the same issue on iOS. The latest Metamask version. Wallet Connect opens the App Store even if MetaMask is installed. So frustrating

p/s: Other wallets worked fine (Coin98, Trust, GNosis...)

JstKuLam avatar Nov 14 '22 07:11 JstKuLam

Unfortunately, I also ran into this problem. Is there a solution now?

SunnyCheung-cp avatar Dec 07 '22 09:12 SunnyCheung-cp

We just release an update of the app (v5.12.0 and up) that should help fix this issue. It's rolling out now on Android and iOS. Please let me know if this solves or not. Thanks

andreahaku avatar Dec 07 '22 11:12 andreahaku

@andreahaku Thanks, I just tried it with v5.12.0, unfortunately the result didn't change In addition, let me provide that the connection method I am currently using is walletconnect v2.0, don't know if this will make a difference

https://user-images.githubusercontent.com/105030733/206341425-9986adb5-d1d8-490b-88f2-e2515b561db3.mp4

SunnyCheung-cp avatar Dec 08 '22 02:12 SunnyCheung-cp

@SunnyCheung-cp we don't support WC v2.0 for now. We only support WC v1

andreahaku avatar Dec 08 '22 09:12 andreahaku