wagmi icon indicating copy to clipboard operation
wagmi copied to clipboard

Coinbase Wallet enableMobileWalletLinking showing Coinbase Wallet open app website

Open marcusmolchany opened this issue 1 year ago • 2 comments

Describe the bug

I am trying to use wagmi in a react-native-webview to login to my Expo app using Coinbase Wallet mobile. The webview shows the npm create wagmin@latest site on a next app from vercel. I've included the option enableMobileWalletLinking: true, because we do not want our login page to open up inside of Coinbase Wallet's dapp browser, instead we want to Wallet Link to connect, sign a message, and then stay within our Expo app.

Currently, when we choose Coinbase Wallet as our connection option, we get redirected to Coinbase Wallet, are shown the connect sheet in the Coinbase Wallet app, and then when we return to our app showing the webview, the webview has changed to show a Coinbase Wallet website that forwards us to the iOS App Store.

screenshot
IMG_19ACE33CC395-1

Link to Minimal Reproducible Example

https://stackblitz.com/edit/new-wagmi-wiqtks?file=src%2Fwagmi.ts

Steps To Reproduce

  • Set your VITE_WC_PROJECT_ID
  • Create an Expo app with a react-native-webview
  • set app.json expo.ios.infoPlist.LSApplicationQueriesSchemes to ["cbwallet"]
  • Present the react-native-webview with https://stackblitz.com/edit/new-wagmi-wiqtks?file=src%2Fwagmi.ts and choose "Coinbase Wallet" as the login option

Wagmi Version

2.5.19

Viem Version

2.9.9

TypeScript Version

5.4.4

Check existing issues

Anything else?

No response

marcusmolchany avatar Apr 05 '24 23:04 marcusmolchany

Hi, this could possibly be fixed by forcefully upgrading to 3.9.3 version of cb sdk (wagmi is using 3.9.1 fixed version), but not creating PR as draft PR which upgrades it directly to v4 already exists here: https://github.com/wevm/wagmi/pull/3784

imaksp avatar Apr 19 '24 11:04 imaksp

For anyone experiencing this issue, we got around temporarily by doing:


const coinbaseRedirectUrls = Object.freeze([
  "https://go.cb-w.com/",
  "https://v3eo.app.link/",
]);

export const isCoinbaseRedirectUrl = (url: string): boolean =>
  coinbaseRedirectUrls.some((coinbaseRedirectUrl) =>
    url.startsWith(coinbaseRedirectUrl)
  );

// in our component render function
  return(
        <WebView
          ref={webviewRef}
          source={{ uri: /* your login url */ }}
          onMessage={(event) => {
            // handle postMessage back to react-native-webview
            // with `event.nativeEvent.data)`
          }}
          onNavigationStateChange={(event) => {
            // note: handle coinbase wallet redirect
            if (isCoinbaseRedirectUrl(event.url)) {
              console.log("handling coinbase redirect url", event.url);
              // note: prevent react-native-webview from loading
              // the coinbase redirect url
              webviewRef?.current?.stopLoading();
              // note: use expo Linking to open the coinbase redirect url
              // which will deeplink into the coinbase wallet app
              Linking.openURL(event.url);
              return;
            }
          }}
        />
  );

marcusmolchany avatar Apr 27 '24 15:04 marcusmolchany

Wagmi now uses the v4 of the CB SDK so this should no longer be an issue.

tmm avatar May 21 '24 22:05 tmm

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.

github-actions[bot] avatar Jun 05 '24 00:06 github-actions[bot]