rainbow-me / rainbowkit

The best way to connect a wallet 🌈 🧰
https://rainbowkit.com
MIT License
2.45k stars 673 forks source link

[bug] Cannot use getInjectedConnector/hasInjectedProvider externally #2249

Closed haowang1013 closed 3 days ago

haowang1013 commented 3 days ago

Is there an existing issue for this?

RainbowKit Version

2.2.0

wagmi Version

2.13.0

Current Behavior

Hi,

I need to integrate the immutable passport wallet into our app and based on existing wallets in the repo it should be as easy as the following

import { getInjectedConnector, hasInjectedProvider } from '@rainbow-me/rainbowkit/dist/wallets/getInjectedConnector'

export const passportWallet = (): Wallet => ({
    id: 'immutable-passport',
    name: 'Immutable Passport',
    rdns: 'com.immutable.wallet',
    iconUrl: '',
    iconBackground: '#fff',
    installed: hasInjectedProvider({ flag: 'isPassport' } as any),
    createConnector: getInjectedConnector({ flag: 'isPassport' } as any),
})

The problem is that it doesn't really work in React because getInjectedConnector/hasInjectedProvider are not exported:

Module not found: Error: Package path ./dist/wallets/getInjectedConnector is not exported from package xxx\node_modules\@rainbow-me\rainbowkit (see exports field in xxx\node_modules\@rainbow-me\rainbowkit\package.json)

Expected Behavior

I should be able to use getInjectedConnector/hasInjectedProvider to implement a custom injected wallet externally. Is there any particular reason these 2 are not exposed?

Steps To Reproduce

No response

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

No response

Anything else?

No response

DanielSinclair commented 3 days ago

These are internal functions because their behavior may change. There is quite a bit of complexity in how we choose which provider to pick. I'd recommend just implementing this behavior yourself, similar to the following example from Web3Auth that creates a RainbowKit connector to interact with their modal. I assume you wouldn't need hasInjectedProvider. https://github.com/Web3Auth/web3auth-pnp-examples/blob/37f002032d6781efec82e8fffc4357438ffa022d/web-modal-sdk/wagmi-examples/rainbowkit-modal-example/src/RainbowWeb3authConnector.tsx#L42