-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: revert detect smart contracts for every evm chains (#7356)
This reverts commit 3e70f29.
- Loading branch information
1 parent
b2c6293
commit 1a36c1f
Showing
13 changed files
with
35 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 16 additions & 17 deletions
33
src/hooks/useIsSmartContractAddress/useIsSmartContractAddress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import type { ChainId } from '@shapeshiftoss/caip' | ||
import { isEvmChainId } from '@shapeshiftoss/chain-adapters' | ||
import { skipToken, useQuery } from '@tanstack/react-query' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useMemo } from 'react' | ||
import { isSmartContractAddress } from 'lib/address/utils' | ||
|
||
export const useIsSmartContractAddress = (address: string, chainId: ChainId) => { | ||
export const useIsSmartContractAddress = (address: string) => { | ||
// Lowercase the address to ensure proper caching | ||
const userAddress = useMemo(() => address.toLowerCase(), [address]) | ||
|
||
const query = useQuery({ | ||
queryKey: [ | ||
'isSmartContractAddress', | ||
{ | ||
userAddress, | ||
chainId, | ||
}, | ||
], | ||
queryFn: | ||
isEvmChainId(chainId) && Boolean(userAddress.length) | ||
? () => isSmartContractAddress(userAddress, chainId) | ||
: skipToken, | ||
}) | ||
const queryParams = useMemo(() => { | ||
return { | ||
queryKey: [ | ||
'isSmartContractAddress', | ||
{ | ||
userAddress, | ||
}, | ||
], | ||
queryFn: () => isSmartContractAddress(userAddress), | ||
enabled: Boolean(userAddress.length), | ||
} | ||
}, [userAddress]) | ||
|
||
const query = useQuery(queryParams) | ||
|
||
return query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import type { ChainId } from '@shapeshiftoss/caip' | ||
import { isEvmChainId } from '@shapeshiftoss/chain-adapters' | ||
import { isAddress } from 'viem' | ||
import { getEthersProvider } from 'lib/ethersProviderSingleton' | ||
|
||
export const isEthAddress = (address: string): boolean => /^0x[0-9A-Fa-f]{40}$/.test(address) | ||
|
||
export const isSmartContractAddress = async ( | ||
address: string, | ||
chainId: ChainId, | ||
): Promise<boolean> => { | ||
export const isSmartContractAddress = async (address: string): Promise<boolean> => { | ||
if (!isAddress(address)) return false | ||
if (!isEvmChainId(chainId)) return false | ||
const bytecode = await getEthersProvider(chainId).getCode(address) | ||
const bytecode = await getEthersProvider().getCode(address) | ||
return bytecode !== '0x' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters