1
- import { getPublicClient } from "@wagmi/core " ;
2
- import { GetTransactionReceiptReturnType , decodeEventLog , getEventSelector } from "viem" ;
1
+ import { GetTransactionReceiptReturnType , createPublicClient , decodeEventLog , getEventSelector , http } from "viem " ;
2
+ import * as chains from "viem/chains " ;
3
3
4
4
import { iArbitrableV2Abi } from "hooks/contracts/generated" ;
5
5
import { isUndefined } from "utils/index" ;
6
6
7
+ /**
8
+ * Gets the chain object for the given chain id.
9
+ * @param chainId - Chain id of the target EVM chain.
10
+ * @returns Viem's chain object.
11
+ */
12
+ const getChain = ( chainId : number ) => {
13
+ for ( const chain of Object . values ( chains ) ) {
14
+ if ( "id" in chain ) {
15
+ if ( chain . id === chainId ) {
16
+ return chain ;
17
+ }
18
+ }
19
+ }
20
+
21
+ throw new Error ( `Chain with id ${ chainId } not found` ) ;
22
+ } ;
23
+
24
+ // Warning : do not import this in any pages except DisputeTemplatePreview, this has a large bundle size.
7
25
export const getDisputeRequestParamsFromTxn = async ( hash : `0x${string } `, chainId : number ) => {
8
26
try {
9
- const publicClient = getPublicClient ( { chainId } ) ;
27
+ const publicClient = createPublicClient ( {
28
+ chain : getChain ( chainId ) ,
29
+ transport : http ( ) ,
30
+ } ) ;
10
31
11
32
const txn : GetTransactionReceiptReturnType = await publicClient . getTransactionReceipt ( {
12
33
hash,
@@ -28,6 +49,8 @@ export const getDisputeRequestParamsFromTxn = async (hash: `0x${string}`, chainI
28
49
_arbitrable : disputeRequestEvent . address ,
29
50
} ;
30
51
} catch ( e ) {
52
+ console . log ( "Error getting txn :" , { e } ) ;
53
+
31
54
return undefined ;
32
55
}
33
56
} ;
0 commit comments