diff --git a/src/@utils/web3.ts b/src/@utils/web3.ts index 2cf977222..849301cd8 100644 --- a/src/@utils/web3.ts +++ b/src/@utils/web3.ts @@ -41,7 +41,6 @@ export function accountTruncate(account: string): string { } export async function addCustomNetwork( - web3Provider: any, network: EthereumListsChain ): Promise { // Always add explorer URL from ocean.js first, as it's null sometimes @@ -59,13 +58,13 @@ export async function addCustomNetwork( blockExplorerUrls } try { - await web3Provider.request({ + await window?.ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: newNetworkData.chainId }] }) } catch (switchError) { if (switchError.code === 4902) { - await web3Provider.request( + await (window?.ethereum.request as any)( { method: 'wallet_addEthereumChain', params: [newNetworkData] @@ -96,7 +95,6 @@ export async function addCustomNetwork( } export async function addTokenToWallet( - web3Provider: any, address: string, symbol: string, logo?: string @@ -110,7 +108,7 @@ export async function addTokenToWallet( options: { address, symbol, image, decimals: 18 } } - web3Provider.sendAsync( + ;(window?.ethereum.request as any)( { method: 'wallet_watchAsset', params: tokenMetadata, @@ -136,7 +134,7 @@ export async function getTokenBalance( accountId: string, decimals: number, tokenAddress: string, - web3Provider: any + web3Provider: ethers.providers.Provider ): Promise { try { const token = new ethers.Contract(tokenAddress, erc20ABI, web3Provider) diff --git a/src/components/@shared/AddToken/index.tsx b/src/components/@shared/AddToken/index.tsx index dccb2d2ba..73cf00550 100644 --- a/src/components/@shared/AddToken/index.tsx +++ b/src/components/@shared/AddToken/index.tsx @@ -4,7 +4,6 @@ import { addTokenToWallet } from '@utils/web3' import Button from '@shared/atoms/Button' import OceanLogo from '@images/logo.svg' import styles from './index.module.css' -import { useProvider } from 'wagmi' const cx = classNames.bind(styles) @@ -23,8 +22,6 @@ export default function AddToken({ className, minimal }: AddTokenProps): ReactElement { - const web3Provider = useProvider() - const styleClasses = cx({ button: true, minimal, @@ -32,9 +29,9 @@ export default function AddToken({ }) async function handleAddToken() { - if (!web3Provider) return + if (!window?.ethereum) return - await addTokenToWallet(web3Provider, address, symbol) + await addTokenToWallet(address, symbol) } return ( diff --git a/src/components/@shared/WalletNetworkSwitcher/index.tsx b/src/components/@shared/WalletNetworkSwitcher/index.tsx index 65e3775b7..82f8719b4 100644 --- a/src/components/@shared/WalletNetworkSwitcher/index.tsx +++ b/src/components/@shared/WalletNetworkSwitcher/index.tsx @@ -7,11 +7,10 @@ import useNetworkMetadata, { getNetworkDisplayName } from '@hooks/useNetworkMetadata' import { useAsset } from '@context/Asset' -import { useNetwork, useProvider } from 'wagmi' +import { useNetwork } from 'wagmi' export default function WalletNetworkSwitcher(): ReactElement { const { chain } = useNetwork() - const web3Provider = useProvider() const { asset } = useAsset() const { networksList } = useNetworkMetadata() @@ -29,7 +28,7 @@ export default function WalletNetworkSwitcher(): ReactElement { const networkNode = await networksList.find( (data) => data.chainId === asset.chainId ) - addCustomNetwork(web3Provider, networkNode) + addCustomNetwork(networkNode) } return ( diff --git a/src/components/Publish/AvailableNetworks/Network.tsx b/src/components/Publish/AvailableNetworks/Network.tsx index a3fef68f3..13622a873 100644 --- a/src/components/Publish/AvailableNetworks/Network.tsx +++ b/src/components/Publish/AvailableNetworks/Network.tsx @@ -4,7 +4,6 @@ import styles from './Network.module.css' import Button from '@shared/atoms/Button' import useNetworkMetadata from '@hooks/useNetworkMetadata' import { addCustomNetwork } from '@utils/web3' -import { useProvider } from 'wagmi' export default function Network({ chainId @@ -12,11 +11,10 @@ export default function Network({ chainId: number }): ReactElement { const { networksList } = useNetworkMetadata() - const web3Provider = useProvider() function changeNetwork(chainId: number) { const networkNode = networksList.find((data) => data.chainId === chainId) - addCustomNetwork(web3Provider, networkNode) + addCustomNetwork(networkNode) } return (