@@ -7,6 +7,7 @@ import L2_ERC721 from "@/assets/abis/L2_ERC721.json"
7
7
import L2_ERC1155 from "@/assets/abis/L2_ERC1155.json"
8
8
import { ChainId , TOEKN_TYPE } from "@/constants"
9
9
import { useWeb3Context } from "@/contexts/Web3ContextProvider"
10
+ import { useAsyncMemo } from "@/hooks"
10
11
import useNFTBridgeStore from "@/stores/nftBridgeStore"
11
12
import { requireEnv } from "@/utils"
12
13
@@ -26,16 +27,19 @@ const NFTBridgeProvider = props => {
26
27
27
28
const isLayer1 = useMemo ( ( ) => checkConnectedChainId ( ChainId . SCROLL_LAYER_1 ) , [ checkConnectedChainId ] )
28
29
29
- const tokenInstance = useMemo ( ( ) => {
30
- const signer = provider ?. getSigner ( 0 )
31
- if ( contract ?. type === TOEKN_TYPE [ 721 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_1 ) ) {
32
- return new ethers . Contract ( contract . l1 as string , L1_ERC721 , signer )
33
- } else if ( contract ?. type === TOEKN_TYPE [ 721 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_2 ) ) {
34
- return new ethers . Contract ( contract . l2 as string , L2_ERC721 , signer )
35
- } else if ( contract ?. type === TOEKN_TYPE [ 1155 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_1 ) ) {
36
- return new ethers . Contract ( contract . l1 as string , L1_ERC1155 , signer )
37
- } else if ( contract ?. type === TOEKN_TYPE [ 1155 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_2 ) ) {
38
- return new ethers . Contract ( contract . l2 as string , L2_ERC1155 , signer )
30
+ const tokenInstance = useAsyncMemo ( async ( ) => {
31
+ if ( provider ) {
32
+ const signer = await provider . getSigner ( 0 )
33
+ if ( contract ?. type === TOEKN_TYPE [ 721 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_1 ) ) {
34
+ return new ethers . Contract ( contract . l1 as string , L1_ERC721 , signer )
35
+ } else if ( contract ?. type === TOEKN_TYPE [ 721 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_2 ) ) {
36
+ return new ethers . Contract ( contract . l2 as string , L2_ERC721 , signer )
37
+ } else if ( contract ?. type === TOEKN_TYPE [ 1155 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_1 ) ) {
38
+ return new ethers . Contract ( contract . l1 as string , L1_ERC1155 , signer )
39
+ } else if ( contract ?. type === TOEKN_TYPE [ 1155 ] && checkConnectedChainId ( ChainId . SCROLL_LAYER_2 ) ) {
40
+ return new ethers . Contract ( contract . l2 as string , L2_ERC1155 , signer )
41
+ }
42
+ return null
39
43
}
40
44
return null
41
45
} , [ provider , checkConnectedChainId , contract ?. type ] )
0 commit comments