xdevguild / nextjs-dapp-template

Open source Next.js app template for the MultiversX blockchain. Including Shadcn UI and Tailwind.
https://multiversx-nextjs-dapp.netlify.app
MIT License
47 stars 16 forks source link

Expose result of await transactionWatcher.awaitCompleted(tx); to callback #15

Closed janniksam closed 1 year ago

janniksam commented 2 years ago

In many cases its necessary to know, if a transaction is failing or not.

We already call it here: sendTxOperations#L27

const transactionWatcher = new TransactionWatcher(apiNetworkProvider);
await transactionWatcher.awaitCompleted(tx);
setTransaction(tx);
cb?.({ transaction: tx, pending: false });

To be able to deal with the transactions status at a higher level I would suggest something like this:

const transactionWatcher = new TransactionWatcher(apiNetworkProvider);
const txResult = await transactionWatcher.awaitCompleted(tx);
setTransaction(tx);
cb?.({ transaction: tx, pending: false; result: txResult });
juliancwirko commented 2 years ago

Good point. It may need more work, like global states handling responses from smart contracts, etc. I added it to the todo list: https://github.com/orgs/xdevguild/projects/1. I'll get back to it shortly

juliancwirko commented 1 year ago

useTransaction and useScTransaction now return txResult

const { pending, triggerTx, transaction, txResult, error } = useTransaction({ cb });