Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onTx status callbacks #65

Merged
merged 16 commits into from
Aug 2, 2022
Merged

feat: add onTx status callbacks #65

merged 16 commits into from
Aug 2, 2022

Conversation

kristiehuang
Copy link
Contributor

@kristiehuang kristiehuang commented Jul 25, 2022

Adding onTxSubmit/Success/Fail callbacks

onTxSubmit onTxSuccess onTxFail
Screen Shot 2022-07-25 at 7 17 49 PM Screen Shot 2022-07-26 at 10 59 55 AM Screen Shot 2022-07-26 at 11 21 55 AM

@vercel
Copy link

vercel bot commented Jul 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
widgets ✅ Ready (Inspect) Visit Preview Jul 29, 2022 at 7:45PM (UTC)

@vercel vercel bot temporarily deployed to Preview July 25, 2022 23:21 Inactive
@vercel vercel bot temporarily deployed to Preview July 25, 2022 23:22 Inactive
@vercel vercel bot temporarily deployed to Preview July 25, 2022 23:37 Inactive
@vercel vercel bot temporarily deployed to Preview July 26, 2022 15:24 Inactive
// completed trade's impact is reflected in future fetched trades.
setOldestValidBlock(receipt.blockNumber)
})
.catch((e) => onTxFail?.(e, transaction.hash))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a transaction is cancelled by the user, it gets caught here. Does that count as a tx failing?

@kristiehuang kristiehuang marked this pull request as ready for review July 26, 2022 15:38
@kristiehuang
Copy link
Contributor Author

one thing I'm not sure about is all the different cases in which txs might fail -- too low gas, cancelled, contract execution error, etc -- and how to test them?

@vercel vercel bot temporarily deployed to Preview July 26, 2022 15:44 Inactive
@vercel vercel bot temporarily deployed to Preview July 26, 2022 16:10 Inactive
@@ -129,12 +132,13 @@ export default function useSendSwapTransaction(
throw new Error(t`Transaction rejected.`)
} else {
// otherwise, the error was unexpected and we need to convey that
console.error(`Swap failed`, error, address, calldata, value)
console.error(`Swap failed`, error, calldata, value)
onTxFail?.(error, error?.transactionHash)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessarily an ethereum tx fail issue -- it would throw here if we haven't formed a valid tx and therefore can't submit it

should we still call onTxFail here?

// completed trade's impact is reflected in future fetched trades.
setOldestValidBlock(receipt.blockNumber)
})
.catch((e) => onTxFail?.(e, transaction.hash)) // Do we run onTxFail on tx cancelled?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessarily an ethereum tx fail — the ethers library throws an error on cancelled tx, which is what we're catching here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should call onTxFail in this case. @akarys92 thoughts?

(aside-in the cancellation case we wouldn't have a transaction.hash here)

@vercel vercel bot temporarily deployed to Preview July 27, 2022 16:43 Inactive
})
oldTxs.current = pendingTransactions
}
}, [pendingTransactions, onTxSubmit])
Copy link
Contributor Author

@kristiehuang kristiehuang Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pendingTransactions is just txs[our current active chainId]

using pendingTransactions as opposed to txs from const txs = useAtomValue(transactionsAtom) to mirror how onReceipt is used https://github.com/Uniswap/widgets/blob/main/src/hooks/transactions/updater.tsx#L75

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you update the variable names new... and old... for clarity? currentPendingTransactions, oldPendingTransactions, etc.

@vercel vercel bot temporarily deployed to Preview July 27, 2022 18:17 Inactive

throw new Error(t`Swap failed: ${swapErrorToUserReadableMessage(error)}`)
console.error(`Swap failed`, error, calldata, value)
throw new Error(t`Swap failed: ${swapErrorToUserReadableMessage(error)}`) // FIXME: this prints to console as [object Object]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate small PR here to fix this
#66

})
oldTxs.current = pendingTransactions
}
}, [pendingTransactions, onTxSubmit])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you update the variable names new... and old... for clarity? currentPendingTransactions, oldPendingTransactions, etc.

src/hooks/transactions/index.tsx Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview July 29, 2022 19:45 Inactive
@kristiehuang kristiehuang merged commit 0d08050 into main Aug 2, 2022
@kristiehuang kristiehuang deleted the feat/onTx-callbacks branch August 2, 2022 18:15
@github-actions
Copy link

github-actions bot commented Aug 9, 2022

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants