11import { ComethWallet } from '@cometh/connect-sdk'
22import {
3+ Account ,
34 Address ,
45 Chain ,
6+ Client ,
7+ createClient ,
8+ createPublicClient ,
59 GetBlockNumberReturnType ,
610 Hash ,
11+ Hex ,
12+ http ,
13+ Log ,
714 parseAbiItem ,
815 PublicClient ,
916 TransactionReceipt ,
@@ -13,11 +20,11 @@ import {
1320import { sleep } from '../utils/utils'
1421
1522const _catchSuccessEvent = async (
16- client : PublicClient < Transport , Chain > ,
23+ client : PublicClient ,
1724 address : Address ,
1825 safeTxHash : Hash ,
1926 currentBlockNumber : GetBlockNumberReturnType
20- ) : Promise < any > => {
27+ ) : Promise < Log > => {
2128 const successTransactionLogs = await client . getLogs ( {
2229 address,
2330 event : parseAbiItem (
@@ -30,15 +37,15 @@ const _catchSuccessEvent = async (
3037 ( e ) => e . args . txHash == safeTxHash
3138 )
3239
33- return filteredTransactionEvent
40+ return filteredTransactionEvent as Log
3441}
3542
3643const _catchFailureEvent = async (
37- client : PublicClient < Transport , Chain > ,
44+ client : PublicClient ,
3845 address : Address ,
3946 safeTxHash : Hash ,
4047 currentBlockNumber : GetBlockNumberReturnType
41- ) : Promise < any > => {
48+ ) : Promise < Log > => {
4249 const successTransactionLogs = await client . getLogs ( {
4350 address,
4451 event : parseAbiItem (
@@ -51,17 +58,20 @@ const _catchFailureEvent = async (
5158 ( e ) => e . args . txHash == safeTxHash
5259 )
5360
54- return filteredTransactionEvent
61+ return filteredTransactionEvent as Log
5562}
5663
57- export const getTransaction = async ( {
64+ export const getTransaction = async <
65+ TChain extends Chain | undefined ,
66+ TAccount extends Account | undefined
67+ > ( {
5868 client,
5969 wallet,
6070 safeTxHash,
6171 relayId,
6272 timeout = 60 * 1000
6373} : {
64- client : any
74+ client : Client < Transport , TChain , TAccount >
6575 wallet : ComethWallet
6676 safeTxHash : Hash
6777 relayId ?: string
@@ -70,7 +80,12 @@ export const getTransaction = async ({
7080 const startDate = Date . now ( )
7181 const timeoutLimit = new Date ( startDate + timeout ) . getTime ( )
7282
73- const currentBlockNumber = await client . getBlockNumber ( )
83+ const publicClient = createPublicClient ( {
84+ chain : client . chain ,
85+ transport : http ( client . transport . rpcUrl )
86+ } ) as PublicClient
87+
88+ const currentBlockNumber = await publicClient . getBlockNumber ( )
7489 const from = wallet . getAddress ( ) as Address
7590
7691 let txSuccessEvent
@@ -79,13 +94,13 @@ export const getTransaction = async ({
7994 while ( ! txSuccessEvent && ! txFailureEvent && Date . now ( ) < timeoutLimit ) {
8095 await sleep ( 3000 )
8196 txSuccessEvent = await _catchSuccessEvent (
82- client ,
97+ publicClient ,
8398 from ,
8499 safeTxHash ,
85100 currentBlockNumber
86101 )
87102 txFailureEvent = await _catchFailureEvent (
88- client ,
103+ publicClient ,
89104 from ,
90105 safeTxHash ,
91106 currentBlockNumber
@@ -99,8 +114,8 @@ export const getTransaction = async ({
99114
100115 while ( txResponse === null ) {
101116 try {
102- txResponse = await client . getTransactionReceipt ( {
103- hash : transactionHash
117+ txResponse = await publicClient . getTransactionReceipt ( {
118+ hash : transactionHash as Hex
104119 } )
105120 } catch {
106121 // Do nothing
0 commit comments