WalletConnect / web3modal

A single Web3 provider solution for all Wallets
https://web3modal.com
Apache License 2.0
4.69k stars 1.3k forks source link

Beta.4-5 breaking changes & full wagmi support #702

Closed xzilja closed 1 year ago

xzilja commented 1 year ago

Hi everyone, we have released beta.4 which under the hood gets rid of our custom react hooks and controllers and instead provides full support for https://wagmi.sh

Wagmi is a great library that we were already using before, but were not able to provide full integration for until now.

React

Please follow updated documentation to see how to set up web3modal with wagmi.

Once integrated, you will need to replace all @web3modal/react hooks with ones from wagmi. See Wagmi Documentation for all available options. In general this should bring you way more stability and allow to use other wagmi compatible libraries like lens-use for example.

HTML / JS

Similar to how react no longer has hooks, vanilla no longer uses controllers. Instead you can import and use core functions like getAccount / watchAccount / getSigner etc. from @wagmi/core package. See updated example for new integration steps.

We are working with wagmi team to document @wagmi/core lib, but meanwhile feel free to ask questions here and use your editors intelisens / typescript autocompletion to see what is available.

Feel free to use this issue for further questions.

M4cs commented 1 year ago

modalConnectors() is not working with the connectors argument in createClient for wagmi. When trying to do so it's getting a type error. See below:

yarn run v1.22.19
$ next build
info  - Linting and checking validity of types .Failed to compile.

./pages/_app.tsx:22:3
Type error: Type '(WalletConnectConnector | InjectedConnector | CoinbaseWalletConnector)[]' is not assignable to type '(() => Connector<any, any, any>[]) | Connector<any, any, any>[] | undefined'.
  Type '(WalletConnectConnector | InjectedConnector | CoinbaseWalletConnector)[]' is not assignable to type 'Connector<any, any, any>[]'.
    Type 'WalletConnectConnector | InjectedConnector | CoinbaseWalletConnector' is not assignable to type 'Connector<any, any, any>'.
      Type 'WalletConnectConnector' is not assignable to type 'Connector<any, any, any>'.
        Property 'onAccountsChanged' is protected but type 'WalletConnectConnector' is not a class derived from 'Connector<Provider, Options, Signer>'.

  20 | const wagmiClient = createClient({
  21 |   autoConnect: true,
> 22 |   connectors: modalConnectors({ appName: "pwa-secret", chains }),
     |   ^
  23 |   provider,
  24 | });
  25 | 
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
1 ❯                                                                                                                                                                       pwa-secret-app -> main ? !

Anyway around this?

nhardy commented 1 year ago

I've noticed that this can break in subtle ways if the version of @wagmi/core depended on by wagmi is mismatched when compared to the version used by @web3modal/ethereum and can't be deduped by npm. Wondering if this could be resolved by adding @wagmi/core to peerDependencies instead of it being a direct dependency?

xzilja commented 1 year ago

@nhardy will look into this πŸ‘ @M4cs Could you update wagmi to lates version (if you haven't done so already). There were some breaking changes there and we are using their latest wagmi/core lib

xzilja commented 1 year ago

Inconsistencies between versions will be solved in upcoming beta.5 ^

timefordroids commented 1 year ago

I guess there are some breaking changes which were not reflected in docs, because I have the following errors:

export 'walletConnectProvider' (imported as 'walletConnectProvider') was not found in '@web3modal/ethereum' (possible exports: Web3ModalEthereum)

export 'modalConnectors' (imported as 'modalConnectors') was not found in '@web3modal/ethereum' (possible exports: Web3ModalEthereum)

export 'EthereumClient' (imported as 'EthereumClient') was not found in '@web3modal/ethereum' (possible exports: Web3ModalEthereum)
xzilja commented 1 year ago

@timefordroids (possible exports: Web3ModalEthereum) this looks like you might be still using an older version i.e. you don't have access to new imports, but do have access to older ones.

Make sure all packages are on beta.5 (fastest way to ensure this is to delete your .lock file and node_modules and just re-install everything fresh)

timefordroids commented 1 year ago

All the packages were installed in a first-time. That's what I have in yarn.lock

"@web3modal/core@npm:2.0.0-fbf9251":
  version: 2.0.0-fbf9251
  resolution: "@web3modal/core@npm:2.0.0-fbf9251"
  dependencies:
    valtio: 1.7.0
  peerDependencies:
    "@web3modal/ethereum": "*"
  peerDependenciesMeta:
    "@web3modal/ethereum":
      optional: true
  checksum: b23314261129c8d76b26d27805f4658892cf3fbecc0f179a6989dad9bf31a4dd3f4dc51ac007e8b6859fca14499dc70f90ae3a63c7f980fb2ff36e3dc2d8f728
  languageName: node
  linkType: hard

"@web3modal/ethereum@npm:^2.0.0-beta.5":
  version: 2.0.0-fbf9251
  resolution: "@web3modal/ethereum@npm:2.0.0-fbf9251"
  dependencies:
    "@coinbase/wallet-sdk": 3.5.2
    "@walletconnect/ethereum-provider": 1.8.0
  peerDependencies:
    "@wagmi/core": ">=0.5.x"
    "@web3modal/core": "*"
  checksum: 4e76813c390ea9c0c8117f8bdd88621713a1d5df4c57157944a7cf48865715622c31356f32844a60902a9b4c2b14879ac93666fe2b33677a507218e0d657a113
  languageName: node
  linkType: hard

"@web3modal/react@npm:^2.0.0-beta.5":
  version: 2.0.0-fbf9251
  resolution: "@web3modal/react@npm:2.0.0-fbf9251"
  dependencies:
    "@web3modal/core": 2.0.0-fbf9251
    "@web3modal/ui": 2.0.0-fbf9251
  peerDependencies:
    react: ">=17.x"
    react-dom: ">=17.x"
  checksum: 8fee528e925f9e4bfeec39c2ced7c516b4e527557fcc6d1e6256a6e7c48bb436b5713ab6b1ffd048f035d44115596384fe7e233365c0bbfdc4a4cee6868c5e8f
  languageName: node
  linkType: hard
xzilja commented 1 year ago

@timefordroids Hmm that core version looks incorrect, should also be beta.5 not 2.0.0-fbf9251

timefordroids commented 1 year ago

Just added the exact version of core (2.0.0-beta.5) to package.json and it works now. Thank you.

xzilja commented 1 year ago

@timefordroids nice, although, you can probably remove it now as core package is part of react one.

inartin commented 1 year ago

edited looks like beta 5 fixed my issue

M4cs commented 1 year ago

@nhardy will look into this πŸ‘ @M4cs Could you update wagmi to lates version (if you haven't done so already). There were some breaking changes there and we are using their latest wagmi/core lib

Fwiw using wagmi@0.8.3 fixed my issue with beta 4 but beta 5 with newest wagmi works πŸ‘

xzilja commented 1 year ago

Yep, any wagmi 0.8.x version should be working starting with beta 5 πŸ‘Œ

xzilja commented 1 year ago

Closing this in favour of beta.6 issue https://github.com/WalletConnect/web3modal/issues/729

archae0pteryx commented 1 year ago

FWIW, following the latest docs, i am still not finding the walletConnectProvider export from @web3modal/ethereum. Neither with beta.5 or beta.7

xzilja commented 1 year ago

@archae0pteryx Should definetely be there on beta.7

We use it in all our examples i.e here it is in react https://github.com/WalletConnect/web3modal/blob/V2/examples/react/src/pages/_app.tsx#L1

Above example deploys here https://web3modal-dev.pages.dev