Skip to content

Commit

Permalink
fix: tx wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Nov 17, 2022
1 parent a3abcdf commit ff1b131
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@web3-react/core": "^8.0.33-beta.0",
"@web3-react/metamask": "^8.0.26-beta.0",
"@web3-react/types": "^8.0.19-beta.0",
"@web3-react/walletconnect": "^8.0.34-beta.0"
"@web3-react/walletconnect": "^8.0.34-beta.0",
"async-wait-until": "^2.0.12"
}
}
15 changes: 9 additions & 6 deletions src/web3/store/transactionsSlice.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitUntil } from 'async-wait-until';
import { ethers, providers } from 'ethers';
import { Draft, produce } from 'immer';

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

const tx = await provider.getTransaction(txData.hash);
if (tx) {
await get().waitForTxReceipt(tx, txData.hash, provider);
} else {
const tx2 = await provider.getTransaction(txData.hash);
await get().waitForTxReceipt(tx2, txData.hash, provider);
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);
}
} else {
// TODO: no transaction in waiting pool
Expand Down

0 comments on commit ff1b131

Please sign in to comment.