11import { useEffect , useMemo , useState } from 'react'
22import styled from 'styled-components'
33import { DebounceInput } from 'react-debounce-input'
4- import { JsonRpcBatchProvider } from '@ethersproject/providers '
4+ import { erc20Abi } from 'viem '
55import { ChevronDown as BaseChevronDown } from '@/src/components/assets/ChevronDown'
66import { Magnifier as BaseMagnifier } from '@/src/components/assets/Magnifier'
77import { Dropdown as BaseDropdown , DropdownPosition } from '@/src/components/dropdown'
@@ -11,9 +11,8 @@ import { Chains, ChainsValues } from '@/src/constants/config/types'
1111import { Token } from '@/types/token'
1212import { useBridgedTokens } from '@/src/providers/tokenListProvider'
1313import { getToChainId } from '@/src/utils/tools'
14- import { ERC165__factory , HomeOmniMediator__factory } from '@/types/typechain'
15- import { getNetworkConfig } from '@/src/constants/config/chains'
16- import { contracts } from '@/src/constants/config/contracts'
14+ import { homeOmniBridgeContract } from '@/src/constants/config/contracts'
15+ import { gnosisBatchClient , mainnetBatchClient } from '@/src/constants/config/rpc-providers'
1716import { isAddress } from 'viem'
1817
1918const Wrapper = styled ( BaseDropdown ) `
@@ -202,20 +201,29 @@ const Dropdown: React.FC<Props> = ({
202201 setIsLoading ( true )
203202
204203 const isFromGnosis = chainId == Chains . gnosis
205- const erc20 = ERC165__factory . connect (
206- value ,
207- new JsonRpcBatchProvider ( getNetworkConfig ( chainId ) ?. rpcUrl ) ,
208- )
209- const omni = HomeOmniMediator__factory . connect (
210- contracts . OmniBridge . address [ Chains . gnosis ] ,
211- new JsonRpcBatchProvider ( getNetworkConfig ( Chains . gnosis ) ?. rpcUrl ) ,
212- )
204+ const fromChainClient = isFromGnosis ? gnosisBatchClient : mainnetBatchClient
213205
214206 Promise . all ( [
215- erc20 . name ( ) ,
216- erc20 . symbol ( ) ,
217- erc20 . decimals ( ) ,
218- isFromGnosis ? omni . foreignTokenAddress ( value ) : omni . homeTokenAddress ( value ) ,
207+ fromChainClient . readContract ( {
208+ address : value as `0x${string } `,
209+ abi : erc20Abi ,
210+ functionName : 'name' ,
211+ } ) ,
212+ fromChainClient . readContract ( {
213+ address : value as `0x${string } `,
214+ abi : erc20Abi ,
215+ functionName : 'symbol' ,
216+ } ) ,
217+ fromChainClient . readContract ( {
218+ address : value as `0x${string } `,
219+ abi : erc20Abi ,
220+ functionName : 'decimals' ,
221+ } ) ,
222+ gnosisBatchClient . readContract ( {
223+ ...homeOmniBridgeContract ,
224+ functionName : isFromGnosis ? 'foreignTokenAddress' : 'homeTokenAddress' ,
225+ args : [ value as `0x${string } `] ,
226+ } ) ,
219227 ] )
220228 . then ( ( [ name , symbol , decimals , _address ] ) => {
221229 if ( ! name || ! symbol || ! decimals || ! _address ) return
0 commit comments