Skip to content

Commit

Permalink
fix: wait for tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Nov 17, 2022
1 parent ff1b131 commit 653156b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/web3/store/transactionsSlice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitUntil } from 'async-wait-until';
import { TimeoutError, waitUntil } from 'async-wait-until';
import { ethers, providers } from 'ethers';
import { Draft, produce } from 'immer';

Expand Down Expand Up @@ -119,14 +119,27 @@ export function createTransactionsSlice<T extends BaseTx>({
txData.chainId
] as providers.JsonRpcBatchProvider;

const tx = await waitUntil<{
tx: ethers.providers.TransactionResponse;
}>(async () => {
return { tx: await provider.getTransaction(txData.hash) };
});

if (tx.tx) {
await get().waitForTxReceipt(tx.tx, txData.hash, provider);
try {
const tx = await waitUntil<{
tx: ethers.providers.TransactionResponse;
}>(
async () => {
return { tx: await provider.getTransaction(txData.hash) };
},
{ timeout: 10000 }
);
if (tx.tx) {
await get().waitForTxReceipt(tx.tx, txData.hash, provider);
}
} catch (e) {
if (e instanceof TimeoutError) {
const tx = await provider.getTransaction(txData.hash);
if (tx) {
await get().waitForTxReceipt(tx, txData.hash, provider);
}
} else {
console.error(e);
}
}
} else {
// TODO: no transaction in waiting pool
Expand Down

0 comments on commit 653156b

Please sign in to comment.