wagmi: bug: No prompt to connect with TrustWallet with custom InjectedProvider getProvider

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

1.4.2

Current Behavior

We need to have support for 3 wallets in our dApp: Metamask, Trust Wallet and WalletConnect SDK.

Metamask and WalletConnect both work perfectly, but Trust Wallet eventually stopped working for us, and we have no idea what caused that issue.

In our main codebase, the return data from useConnect({connector: trustWalletCustomConnector}) is stuck at ‘Loading…’

In the reproduction example on Codesandbox it just has no effect, no loading, nothing happens.

@jxom, could you please advice on the best way to integrate multiple Injected Connectors (Metamask and Trust Wallet).

As can be seen from the video (uploaded on YouTube because its size is too large for GitHub assets storage): https://youtu.be/VF3Rva-sj6g, window.trustwallet is injected in my browser, but no prompt window to it is initiated.

Could someone please help me figure that out? I really appreciate your help!

Maybe I’m specifying the InjectedConnector incorrectly? Please help me.

import { WagmiConfig, configureChains, createConfig } from "wagmi";
import { WalletConnectConnector } from "wagmi/connectors/walletConnect";
import { MetaMaskConnector } from "wagmi/connectors/metaMask";
import { InjectedConnector } from "wagmi/connectors/injected";
import { goerli } from "wagmi/chains";
import { publicProvider } from "wagmi/providers/public";
import ConnectAccount from "./ConnectAccount";

const { chains, publicClient, webSocketPublicClient } = configureChains(
  [goerli],
  [publicProvider()]
);

export const metamaskConnector = new MetaMaskConnector({
  chains,
  options: {
    UNSTABLE_shimOnConnectSelectAccount: true,
    shimDisconnect: true
  }
});

export const walletConnectConnector = new WalletConnectConnector({
  chains,
  options: {
    projectId: "2a42e5f44eaac002e60ba61a895028f6",
    metadata: {
      name: "Seedify",
      description: "Seedworld is a UGC based Gaming Metaverse.",
      url: document.URL,
      icons: ["https://seedworld.io/favicon.ico"]
    }
  }
});

export const trustWalletConnector = new InjectedConnector({
  chains,
  options: {
    name: "trustwallet",
    shimDisconnect: true,
    getProvider: () =>
      typeof window !== "undefined" ? window.trustwallet : undefined
  }
});
/*new TrustWalletConnector({
  chains,
});*/

const config = createConfig({
  publicClient,
  webSocketPublicClient,
  connectors: [trustWalletConnector, metamaskConnector]
});

export default function App() {
  return (
    <WagmiConfig config={config}>
      <div className="App">
        <ConnectAccount />
      </div>
    </WagmiConfig>
  );
}
import { useAccount, useConnect } from "wagmi";
import { metamaskConnector, trustWalletConnector } from "./App";

export default function ConnectAccount() {
  const { isLoading, address, isConnected } = useAccount();
  const { connect } = useConnect();

  return (
    <>
      <button
        onClick={() => {
          connect({
            connector: trustWalletConnector
          });
        }}
      >
        {isLoading ? "Is loading..." : "Connect your Trust Wallet"}
      </button>

      <button
        onClick={() => {
          connect({
            connector: metamaskConnector
          });
        }}
      >
        {isLoading ? "Is loading..." : "Connect your Metamask Wallet"}
      </button>
      {isConnected ? <span>{address}</span> : <></>}
    </>
  );
}

Expected Behavior

It should prompt Trust Wallet to connect to the dApp.

Steps To Reproduce

  1. Visit https://codesandbox.io/s/strange-morning-lmml82?file=/src/ConnectAccount.js
  2. Click on “Connect with Trust Wallet” button

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

https://codesandbox.io/s/strange-morning-lmml82?file=/src/App.js

Anything else?

🙏🙏🙏

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

dang Seedify 😄 worked on my end btw, just blocked on the wallet side because it’s an iframe image

I’m glad it worked! 😃 I’m as @glitch.txs Best for the launch! 🙌

@glitch-txs, you’re genius!!

It worked for me after reinstalling my TW. Now I can connect with all 3 options: TW, MM and WC.

Thank you so much for your help!! Have a great weekend!

Could you please share you Discord handle? I’m @web3panda on Discord.

@glitch-txs, thank you so much for your help!!!

Indeed, when I paste window.trustwallet.request({method:'eth_accounts'}).then((res) => console.log(res)) in the DevTools console, I get an empty array. That’s very strange.

image

I’m getting no errors, just useConnect returning isLoading: true for that connector.

I’ll clone your codebase and try running it on my local to see if I’ll get a prompt for my Trust Wallet.

Your assumption about reinstalling Trust Wallet may be correct. I’ll try that too. Maybe that’s a problem with my TW extension.

Works fine on my end so I assume might be browser related? or maybe try reinstalling the wallet? image

I pasted your code here https://github.com/glitch-txs/wagmi-test/blob/main/src/pages/_app.tsx

Something I can think of, if you paste this on your browser console do you get an empty array? await window.trustwallet.request({method:'eth_accounts'}) Do you get any errors on console?

Also about the codebase feel free to reach out to me on twitter or discord if you have any questions

@milaabl that old codebase is mine haha sorry about that x)

I’ll try to reproduce this on a project

Yes I have both MM and TW