1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-01-05 03:15:07 +01:00

actually catch transaction errors

This commit is contained in:
Matthias Kretschmann 2020-01-13 22:07:48 +01:00
parent fa7bb17f07
commit ae398a8d2b
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -37,22 +37,29 @@ export default function Web3Donation({ address }: { address: string }) {
text: getTransactionMessage().waitingForUser text: getTransactionMessage().waitingForUser
}) })
const tx = await signer.sendTransaction({ try {
to: address, const tx = await signer.sendTransaction({
value: parseEther(amount.toString()) // ETH -> Wei to: address,
}) value: parseEther(amount.toString()) // ETH -> Wei
setTransactionHash(tx.hash) })
setMessage({ setTransactionHash(tx.hash)
status: 'loading', setMessage({
text: getTransactionMessage().waitingConfirmation status: 'loading',
}) text: getTransactionMessage().waitingConfirmation
})
await tx.wait() await tx.wait()
setMessage({ setMessage({
status: 'success', status: 'success',
text: getTransactionMessage().success text: getTransactionMessage().success
}) })
} catch (error) {
setMessage({
status: 'error',
text: error.message
})
}
} }
return ( return (