unionlabs / union

The trust-minimized, zero-knowledge bridging protocol, designed for censorship resistance, extremely high security, and usage in decentralized finance.
https://union.build
Apache License 2.0
375 stars 30 forks source link

Use global wagmi config instead of initiating new viem clients #2190

Closed o-az closed 4 months ago

o-az commented 5 months ago

https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/routes/transfer/(components)/transfer-form.svelte#L254-L263

we should use the existing evm wagmi config in https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/lib/wallet/evm/config.ts#L40 which uses wagmi/core which handles many things including keeping everything evm-side in sync. Under the hood it uses tanstack query to handle external state.

https://wagmi.sh/core/getting-started

switch chain:

https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/routes/transfer/(components)/transfer-form.svelte#L269 use this instead: https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/lib/wallet/evm/config.ts#L226 but first include the chains here (bera v2 is also supported https://github.com/wevm/viem/blob/main/src/chains/index.ts): https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/lib/wallet/evm/config.ts#L41

wallet client:

https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/routes/transfer/(components)/transfer-form.svelte#L259-L263 use this instead: https://wagmi.sh/core/api/actions/getWalletClient

public client:

https://github.com/unionlabs/union/blob/7a9a914ba928c23cefc439ded97b7356350ad272/app/src/routes/transfer/(components)/transfer-form.svelte#L254-L257 use this instead: https://wagmi.sh/core/api/actions/getPublicClient

o-az commented 5 months ago

this way it also automatically handles switching chains and this won't be necessary CleanShot 2024-06-20 at 02 15 15