From ae398a8d2b3af4789c832b4ea1e6370caf3c084c Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 13 Jan 2020 22:07:48 +0100 Subject: [PATCH] actually catch transaction errors --- .../molecules/Web3Donation/index.tsx | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/components/molecules/Web3Donation/index.tsx b/src/components/molecules/Web3Donation/index.tsx index 0c28741b..514649d3 100644 --- a/src/components/molecules/Web3Donation/index.tsx +++ b/src/components/molecules/Web3Donation/index.tsx @@ -37,22 +37,29 @@ export default function Web3Donation({ address }: { address: string }) { text: getTransactionMessage().waitingForUser }) - const tx = await signer.sendTransaction({ - to: address, - value: parseEther(amount.toString()) // ETH -> Wei - }) - setTransactionHash(tx.hash) - setMessage({ - status: 'loading', - text: getTransactionMessage().waitingConfirmation - }) + try { + const tx = await signer.sendTransaction({ + to: address, + value: parseEther(amount.toString()) // ETH -> Wei + }) + setTransactionHash(tx.hash) + setMessage({ + status: 'loading', + text: getTransactionMessage().waitingConfirmation + }) - await tx.wait() + await tx.wait() - setMessage({ - status: 'success', - text: getTransactionMessage().success - }) + setMessage({ + status: 'success', + text: getTransactionMessage().success + }) + } catch (error) { + setMessage({ + status: 'error', + text: error.message + }) + } } return (