@@ -3,11 +3,13 @@ import { SignatureLike } from '@ethersproject/bytes';
33import { JsonRpcProvider , TransactionResponse } from '@ethersproject/providers' ;
44import { BigNumber , PopulatedTransaction , utils } from 'ethers' ;
55import React , { ReactElement , useEffect , useState } from 'react' ;
6+ import { useIsContractAddress } from 'src/hooks/useIsContractAddress' ;
67import { useRootStore } from 'src/store/root' ;
78import { wagmiConfig } from 'src/ui-config/wagmiConfig' ;
89import { hexToAscii } from 'src/utils/utils' ;
910import { UserRejectedRequestError } from 'viem' ;
1011import { useAccount , useConnect , useSwitchChain , useWatchAsset } from 'wagmi' ;
12+ import { useShallow } from 'zustand/shallow' ;
1113
1214import { Web3Context } from '../hooks/useWeb3Context' ;
1315import { getEthersProvider } from './adapters/EthersAdapter' ;
@@ -47,7 +49,9 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
4749
4850 const [ readOnlyModeAddress , setReadOnlyModeAddress ] = useState < string | undefined > ( ) ;
4951 const [ switchNetworkError , setSwitchNetworkError ] = useState < Error > ( ) ;
50- const setAccount = useRootStore ( ( store ) => store . setAccount ) ;
52+ const [ setAccount , setConnectedAccountIsContract ] = useRootStore (
53+ useShallow ( ( store ) => [ store . setAccount , store . setConnectedAccountIsContract ] )
54+ ) ;
5155
5256 const account = address ;
5357 const readOnlyMode = utils . isAddress ( readOnlyModeAddress || '' ) ;
@@ -56,6 +60,8 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
5660 currentAccount = readOnlyModeAddress ;
5761 }
5862
63+ const { data : isContractAddress } = useIsContractAddress ( account || '' , chainId ) ;
64+
5965 useEffect ( ( ) => {
6066 if ( didInit ) {
6167 return ;
@@ -179,6 +185,17 @@ export const Web3ContextProvider: React.FC<{ children: ReactElement }> = ({ chil
179185 }
180186 } , [ readOnlyModeAddress , setAccount ] ) ;
181187
188+ useEffect ( ( ) => {
189+ if ( ! account ) {
190+ setConnectedAccountIsContract ( false ) ;
191+ return ;
192+ }
193+
194+ if ( isContractAddress ) {
195+ setConnectedAccountIsContract ( true ) ;
196+ }
197+ } , [ isContractAddress , setConnectedAccountIsContract , account ] ) ;
198+
182199 return (
183200 < Web3Context . Provider
184201 value = { {
0 commit comments