blocknative / web3-onboard

Client library to onboard users to web3 apps
https://onboard.blocknative.com/
MIT License
813 stars 474 forks source link

Add chain method if chain is not available #2235

Closed vanxh closed 3 weeks ago

vanxh commented 3 weeks ago

Current Behavior

if a user don't has the chain in their wallet that we passed to setChain method then it errors. we should automatically prompt the user to add the chain to their wallet / have a method in library to add chain to a user's wallet.

Expected Behavior

When we call setChain with a chain that is not available in user's wallet then it should prompt the user to add the network to their wallet and then switch to that chain.

Steps To Reproduce

          const { setChain } = useOnboard();
          ...
          await setChain({
            chainId: '0x38',
            token: 'BSC',
            wallet: connectedWallet.value?.label,
            label: 'Binance Smart Chain'
          })

What package is effected by this issue?

@web3-onboard/vue

Is this a build or a runtime issue?

N/A

Package Version

2.8.0

Node Version

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Anything else?

It will make it a good user experience to automatically prompt the user to add the network if the chain is not available in user's wallet so it prevents any errors.

Sanity Check