WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.3k stars 645 forks source link

Mobile browser dapp wallet connect redirects to link.trustwallet.com/wc instead of trust wallet (only in ios not in android) #576

Closed satishrapid closed 1 year ago

satishrapid commented 3 years ago

Facing troubles with TrustWallet WalletConnect integration on iOS only.

Steps to reporduce: 1)add ethereum wallet in trust wallet 2)Open web dApp in Chrome/Safari on mobile iOS directly (same device as TrustWallet) 3)connect dapp with mobile wallet connect and do send transaction.

Expected behavior: trust wallet should open for confirm the transaction

Actual behavior: app redirect to ###https://link.trustwallet.com/wc

Additional context trust wallet: 6.3

Screenshot 2021-08-09 213105

Screenshot 2021-08-09 213136

pasevin commented 3 years ago

Any progress on this? Just encountered same issue.

chadyj commented 3 years ago

I couldn't reproduce this. It worked as expected.

Using Trust Wallet 6.4 and https://example.walletconnect.org

Issue reported on Trust Wallet https://github.com/trustwallet/wallet-core/issues/1565

pasevin commented 3 years ago

Hmm that is strange. It's working with the example site as you said.

pasevin commented 3 years ago

The only difference I can see with my integration and the example one is that on the example it only asks to connect and that's it. Meanwhile on my integration as soon as you connect, you have to sign as well. Just between the connect and sign actions the page redirection happens.

For now I just remove WALLETCONNECT_DEEPLINK_CHOICE from localstorage as soon as user leaves the page to confirm the connection:

$doc.on('visibilitychange', () => {
    if (document.visibilityState === 'hidden') {
        window.localStorage.removeItem('WALLETCONNECT_DEEPLINK_CHOICE');
    }
});
chadyj commented 3 years ago

[[ Reported and deleted phishing comments ]]

fridaythethirteen commented 2 years ago

It is still happening on android chrome for example site https://example.walletconnect.org as well, any updates on the fix?

pasevin commented 2 years ago

Yep, this is not fixed at all... still needs hacking

fridaythethirteen commented 2 years ago

Yep, this is not fixed at all... still needs hacking

@pasevin Can you share the hack around this ?

pasevin commented 2 years ago

Yep, this is not fixed at all... still needs hacking

@pasevin Can you share the hack around this ?

You have to remove local storage item on iOS.


function iOS() {
    return (
        [
                  'iPad Simulator',
          'iPhone Simulator',
          'iPod Simulator',
          'iPad',
          'iPhone',
          'iPod',
        ].includes(navigator.platform) ||
        // iPad on iOS 13 detection
        (navigator.userAgent.includes('Mac') && 'ontouchend' in document)
    );
}

document.addEventListener("visibilitychange", function() {
    if (document.visibilityState === 'hidden' && iOS()) {
        window.localStorage.removeItem('WALLETCONNECT_DEEPLINK_CHOICE');
    }
});
sorrentinopasquale commented 2 years ago

Same issue, very annoying. Any update? We need to remove the local storage variable but then the app is not working smoothly since we need to tell the user to open the app.

ubinatus commented 2 years ago

Had the same issue. It's just on iOS AFAIK. @pasevin hack works great! However the app won't be capable to redirect to the TrustWallet app unless you tell the user to do so (it's expected!). Another workaround is to force the WALLETCONNECT_DEEPLINK_CHOICE to target the TrustWallet deep link app and not the https://link.trustwallet.com/wc

Sharing what I ended up doing the following (code is on Typescript but the idea is there):

  const handleWalletConnectDeepLink = () => {
    const deepLink = window.localStorage.getItem(
      'WALLETCONNECT_DEEPLINK_CHOICE'
    )
    if (deepLink) {
      try {
        const _deepLink: { name: string; href: string } = JSON.parse(deepLink)
        if (_deepLink.href === 'https://link.trustwallet.com/wc') {
          window.localStorage.setItem(
            'WALLETCONNECT_DEEPLINK_CHOICE',
            JSON.stringify({ name: 'Trust Wallet', href: 'trust://' })
          )
        }
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
      } catch (err: any) {
        console.log('TrustWallet force redirect err', err)
      }
    }
  }

In my case, I'm calling handleWalletConnectDeepLink not only on document visibilitychange event but also as soon as the user connects his wallet through WalletConnect. The workaround above checks if the stored WALLETCONNECT_DEEPLINK_CHOICE is linking to TrustWallet and forces the href prop to be the one of the app.

In a nutshell, a wallet connected through WalletConnect to TrustWallet (on iOS) sets the

WALLETCONNECT_DEEPLINK_CHOICE = "{"name":"Trust Wallet","href": "https://link.trustwallet.com/wc"}"

In case we don't want to get redirected to the link.trustwallet page, simply change it to:

WALLETCONNECT_DEEPLINK_CHOICE = "{"name":"Trust Wallet","href": "trust://"}"

trust:// is the deep link for the actual TrustWallet app (https://developer.trustwallet.com/deeplinking#available-domains-links-1)

Important: this works great assuming the user has the TrustWallet app

finessevanes commented 1 year ago

Hey, did @pasevin @fridaythethirteen @sorrentinopasquale, did @ubinatus implementation resolve the issue?