wevm / wagmi

Reactive primitives for Ethereum apps
https://wagmi.sh
MIT License
5.99k stars 1.07k forks source link

Using Injected, okxwallet or okexwallet can't connect with OKX wallet #3809

Closed leonace924 closed 7 months ago

leonace924 commented 7 months ago

Describe the bug

export const okxConnector = injected({target: 'okxWallet'})

using targeted okx wallet, either okxWallet or oKExWallet is not available to connect with the wallet and return ProviderNotFoundError, while using injected({target: 'metamask'}) is ok to connect with my metamask wallet

Link to Minimal Reproducible Example

No response

Steps To Reproduce

No response

Wagmi Version

2.5.19

Viem Version

2.9.13

TypeScript Version

5.2.2

Check existing issues

Anything else?

No response

glitch-txs commented 7 months ago

OKX supports EIP-6963, you can filter the connector by its id.

leonace924 commented 7 months ago

@glitch-txs , could you give me a advice to implement it correctly? I used injected, but didn't work

This was what I did

injected({
      target() {
        return {
          id: "okxwallet",
          name: "OKX Wallet",
          provider: () => {
            if (typeof window !== "undefined") return

            const isOkxWallet = (ethereum) => {
              return !!ethereum?.isOkxWallet
            }

            if (isOkxWallet(window.ethereum)) {
              return window.ethereum
            }

            if (window.ethereum?.providers)
              return window.ethereum.providers.find(isOkxWallet) ?? null

            return window["okxwallet"] ?? null
          }
        }
      }
    })