diff --git a/package.json b/package.json index c8342d31f..1e61c1220 100644 --- a/package.json +++ b/package.json @@ -20,18 +20,18 @@ "test:e2e": "playwright test" }, "dependencies": { - "@lidofinance/analytics-matomo": "^0.47.0", - "@lidofinance/api-metrics": "^0.47.0", - "@lidofinance/api-rpc": "^0.47.0", - "@lidofinance/eth-api-providers": "^0.47.0", - "@lidofinance/eth-providers": "^0.47.0", + "@lidofinance/analytics-matomo": "^0.48.0", + "@lidofinance/api-metrics": "^0.48.0", + "@lidofinance/api-rpc": "^0.48.0", + "@lidofinance/eth-api-providers": "^0.48.0", + "@lidofinance/eth-providers": "^0.48.0", "@lidofinance/lido-ethereum-sdk": "4.1.0", "@lidofinance/lido-ui": "^3.26.0", - "@lidofinance/next-api-wrapper": "^0.47.0", - "@lidofinance/next-ip-rate-limit": "^0.47.0", - "@lidofinance/next-pages": "^0.47.0", - "@lidofinance/rpc": "^0.47.0", - "@lidofinance/satanizer": "^0.47.0", + "@lidofinance/next-api-wrapper": "^0.48.0", + "@lidofinance/next-ip-rate-limit": "^0.48.0", + "@lidofinance/next-pages": "^0.48.0", + "@lidofinance/rpc": "^0.48.0", + "@lidofinance/satanizer": "^0.48.0", "@reef-knot/types": "^4.0.0", "@tanstack/react-query": "^5.51.21", "copy-to-clipboard": "^3.3.1", diff --git a/shared/components/token-to-wallet/token-to-wallet.tsx b/shared/components/token-to-wallet/token-to-wallet.tsx index bad2f4d24..a7cb21982 100644 --- a/shared/components/token-to-wallet/token-to-wallet.tsx +++ b/shared/components/token-to-wallet/token-to-wallet.tsx @@ -1,10 +1,10 @@ -import { ToastInfo, Tooltip } from '@lidofinance/lido-ui'; +import { usePublicClient, useWalletClient, useWatchAsset } from 'wagmi'; +import { type Address, type PublicClient, getContract } from 'viem'; + +import { ToastError, ToastInfo, Tooltip } from '@lidofinance/lido-ui'; import { TokenToWalletStyle } from './styles'; -import { Component } from 'types'; -import { useWalletClient, useWatchAsset } from 'wagmi'; -import { Address, getContract } from 'viem'; -import { useConnectorInfo } from 'reef-knot/core-react'; +import type { Component } from 'types'; export type TokenToWalletComponent = Component<'button', { address?: string }>; @@ -26,20 +26,18 @@ const ERC20_METADATA_ABI = [ ] as const; export const TokenToWallet: TokenToWalletComponent = ({ address, ...rest }) => { - const { watchAssetAsync } = useWatchAsset(); - const { isInjected } = useConnectorInfo(); + const { watchAssetAsync } = useWatchAsset({ mutation: { retry: false } }); + const client = usePublicClient(); const { data: walletClient } = useWalletClient(); - if (!walletClient || !address || !isInjected) return null; + if (!walletClient || !address) return null; const onClickHandler = async () => { - if (!address) return; - try { const tokenContract = getContract({ abi: ERC20_METADATA_ABI, address: address as Address, - client: walletClient, + client: client as PublicClient, }); const [decimals, symbol] = await Promise.all([ @@ -51,10 +49,38 @@ export const TokenToWallet: TokenToWalletComponent = ({ address, ...rest }) => { type: 'ERC20', options: { address, decimals, symbol }, }); - if (!result) return; - ToastInfo('Tokens were successfully added to your wallet', {}); + if (result) { + ToastInfo(`${symbol} token was successfully added to your wallet`); + } else { + ToastInfo( + `Request to watch ${symbol} token was rejected by your wallet`, + ); + } } catch (error) { + // Associating error code to UI messages + if (error && typeof error === 'object' && 'code' in error) { + if ( + error?.code === -32602 // Trust + ) { + ToastInfo('Token is already added'); + } else if ( + error?.code === 4001 || // Metamask, coin98, okx + error?.code === -32603 // Bitget + ) { + ToastInfo(`Request to watch token was rejected by your wallet`); + } else if ( + error?.code === -1 || // LL and Safe through WC + error?.code === -32601 // LL in Discover + ) { + ToastError('The wallet does not support adding a token'); + } else { + ToastError( + 'An error occurred while adding token to wallet\nThe wallet might not support adding a token', + ); + } + } + console.warn('[TokenToWallet] error adding token to wallet', error); } }; diff --git a/yarn.lock b/yarn.lock index b1b868da8..19fcc1225 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2280,20 +2280,20 @@ bignumber.js "^9.1.2" rxjs "^7.8.1" -"@lidofinance/analytics-matomo@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/analytics-matomo/-/analytics-matomo-0.47.0.tgz#3c0c608048b1b41eadfff08daac5ea454ddd3616" - integrity sha512-/cn5y0R85EzVDZI1ShUizsToWnpMXs7jMGRu8yRrX4iN3pMLgYJzqawKbZf2rwDyyNfHZpUOs4ZYyTRZUMslIg== +"@lidofinance/analytics-matomo@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/analytics-matomo/-/analytics-matomo-0.48.0.tgz#0a4ad9dd4af1d49cdf5f9206b1dde9c08216fff0" + integrity sha512-HJBmnXFeQp2PuE8/rghhXy6PbykdSd7g5qqDKuPg5l97rbqbtdFJU2lZuwmPs+PMNquhcdn+yUyEXC4gRSC2Hw== -"@lidofinance/api-metrics@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/api-metrics/-/api-metrics-0.47.0.tgz#285b941e588ad33cc1032ed7e7080977b7444dec" - integrity sha512-lyxLAji9uCQgAa2N++y5XrC99iEf7oaBC4sHDQEoKjed1Tt30AAEjm8Wuko1MfwPscSCeeBc4u/jKAK4KuAcbA== +"@lidofinance/api-metrics@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/api-metrics/-/api-metrics-0.48.0.tgz#48ee6bfaafa4ba0ec4da2daa460bc3b7b5e76419" + integrity sha512-iHOh+BuvKO7f+L8bpPg+R3bXRcHGeKMPZpSp6WitQ8/1QZ19adAeWQryJaM+h1faoIYVUONs6IMxUoquM3OoRg== -"@lidofinance/api-rpc@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/api-rpc/-/api-rpc-0.47.0.tgz#2367eec1c8363516bde48b632a6fbe32aec33a1e" - integrity sha512-6xx2O89OhWAxaob+SqXEX2xtrumG4MCUrclooCIvAhz64Lp3Wa0Hzt2lgJyFMhJxpDPMj3LmYNbuB15lwEQKwg== +"@lidofinance/api-rpc@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/api-rpc/-/api-rpc-0.48.0.tgz#f97e99cdffaacae64f994b928d568e14f7b6e2d6" + integrity sha512-+DVlDKNAKLkYdwn3KHb8TCeM2jRyhy2RIEn9AvTMWfS6csicSfi8dTn4J1F8FHlz6LXoiE1eJ7l3nb29NtbGgg== "@lidofinance/eslint-config@^0.34.0": version "0.34.0" @@ -2302,15 +2302,15 @@ dependencies: typescript "^4.7" -"@lidofinance/eth-api-providers@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/eth-api-providers/-/eth-api-providers-0.47.0.tgz#c5a5ce843de4347277db2f046a07c804b1a5f454" - integrity sha512-thuuF9CGcXQD1FAP1LY3wQHvpNElrGEvQPPmeF1kfE7KuaQKv6DpNZxdP+QnLnxxLtXRn8RD92y8wSbWAzy/EA== +"@lidofinance/eth-api-providers@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/eth-api-providers/-/eth-api-providers-0.48.0.tgz#e60e1c8cf17ad7d1f18a1a32627d4d555d357c7c" + integrity sha512-PfJFVCXumdBvwXR8fDCsb361+ILw7MP0T2Pk7epMVEP9Xr7Q4rl208Sr3l1H5hFX+aKrofZwJO5I7/MycxCz1g== -"@lidofinance/eth-providers@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/eth-providers/-/eth-providers-0.47.0.tgz#186d6e2695c9470cc171d111dac352da5106e681" - integrity sha512-dF8eUUnK35CNCVa3Z++INtlxlRlYKGx2//eLz7nyFkqwPoOGI0PmVW0qgGiGY9TrGAqkJuXlERszclH8eunYCw== +"@lidofinance/eth-providers@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/eth-providers/-/eth-providers-0.48.0.tgz#217279cc8433968531283b985617b981d59a8393" + integrity sha512-ItzIN9psHu8stf8MTAmNaXmKyaVnsYzQ10zdvdX6TM56TcFRlxidTnR5UVeOObtr1Bm/pz61GYCOZkUI6q3aAw== "@lidofinance/lido-ethereum-sdk@4.1.0": version "4.1.0" @@ -2349,36 +2349,36 @@ ua-parser-js "^1.0.35" use-callback-ref "1.2.5" -"@lidofinance/next-api-wrapper@^0.47.0", "@lidofinance/next-api-wrapper@~0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/next-api-wrapper/-/next-api-wrapper-0.47.0.tgz#8452659d8f5a75fb1e6a91d814397797a2113a69" - integrity sha512-td1ckCuqguXQ4imQ6smnekh72gT1C9ku9Cl9P4Mo0Cd70NYTv0QIGoY1swARHOrAdTGhxyE0H5l7vMOdcGSgFQ== +"@lidofinance/next-api-wrapper@^0.48.0", "@lidofinance/next-api-wrapper@~0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/next-api-wrapper/-/next-api-wrapper-0.48.0.tgz#0da8d18e05110d241303b06055239c6f2f874a93" + integrity sha512-zj1goZYUi58DiCTmvjhnc42SmPjOkaHeGdCXQXYExAyM7HstIDrz/Eh2KODowXI2w0vRZiBFEHWSa8ahDDmHGw== -"@lidofinance/next-ip-rate-limit@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/next-ip-rate-limit/-/next-ip-rate-limit-0.47.0.tgz#73e2eef3b91e32b2356dbc2c0b27269a55132f46" - integrity sha512-BFmz50orMcQYItPOaNBEaz/Cx8TYljvhfdIfrdShjyX8HO+ohfesMJlSdEHmHLiC/J7gEoDdiZXRl63HO5+WDg== +"@lidofinance/next-ip-rate-limit@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/next-ip-rate-limit/-/next-ip-rate-limit-0.48.0.tgz#c94a0bfe8b7976d899bac8461faeb6bf40617bda" + integrity sha512-JIEJY7TL5swzwL9LOhtM9Sk1WjiLCgx9y0EtItcphiR2AQF7MCaf9XMQujgX2sQVOy747VrfFZY6AA7ZMKLdUg== dependencies: - "@lidofinance/next-api-wrapper" "~0.47.0" + "@lidofinance/next-api-wrapper" "~0.48.0" -"@lidofinance/next-pages@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/next-pages/-/next-pages-0.47.0.tgz#3f4551209a4aec0e43dfee36ec20b18bdc473576" - integrity sha512-UewzyshAQqxHx7I/xTnZIM8Gv7zoa0VfkRmDUDLwY8Xk3A1bHqaf5uRqF+yJu3aQZVvFrNSVe7DTTsavlzINzQ== +"@lidofinance/next-pages@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/next-pages/-/next-pages-0.48.0.tgz#94f6da226e28dff2595b916a4ed1e93ee72be316" + integrity sha512-JbTB4m6O5MdLvCOC/MW9ttGngQ9A1FKyIY7mMiPHUeBhhZB8A1dCGX8qrcjPrCB8qqsmSphjniX5fFWk1AR5Kg== dependencies: memory-cache "^0.2.0" -"@lidofinance/rpc@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/rpc/-/rpc-0.47.0.tgz#8721e2ac492ab8a5590d17d988546bd89bca7537" - integrity sha512-niepeZ5nTr3QQwZMW0j6c0i8z8KZSmjW1GKDIXcC0ro51rMgGu3gQ7iuXiQ2HnTYEb/fCHTH/Migz4ldPAhtjg== +"@lidofinance/rpc@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/rpc/-/rpc-0.48.0.tgz#436615fc88ff545f8ed4254a11a56313780dfc4f" + integrity sha512-wv+KRYYIUbLx3kh8t1/W5D5c2mVn5uabB9cZ1s5V0BiWrofjdXddcZd+dw5WzHZAQSe72zx8iChv1zieiVJKWQ== dependencies: isomorphic-fetch "^3.0.0" -"@lidofinance/satanizer@^0.47.0": - version "0.47.0" - resolved "https://registry.yarnpkg.com/@lidofinance/satanizer/-/satanizer-0.47.0.tgz#e6d6af704a7a111bca1bdea70e89f1089b646bff" - integrity sha512-oB62ld2W0XKxC3YFvRd2ZzAh5MY28ZLs01Jo9Cp8HOFvWvxnF5GrThm8Op3D/urq+cCmZODiUiMI9BMZuymDog== +"@lidofinance/satanizer@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@lidofinance/satanizer/-/satanizer-0.48.0.tgz#518d1f6574a6a2f38dc80b6dbc3636829eaa95aa" + integrity sha512-wQ36dV9/C/aliykg1cOeJoCl7yc72bJ8+zekzsIrIu3VExI2eV8rk79HWYNHoGcnhJPPRCGonnJh+0Zx3OF5Gw== "@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0": version "1.1.2"