From 54311798472f493a7c98410b41b31bc5a9553f75 Mon Sep 17 00:00:00 2001 From: Pedro Pereira <98242932+pedropereiradev@users.noreply.github.com> Date: Tue, 28 May 2024 22:23:03 -0300 Subject: [PATCH] fix: validation when empty address and address error message fixed (#64) --- examples/react-app/src/components/transfer.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/react-app/src/components/transfer.tsx b/examples/react-app/src/components/transfer.tsx index 564a5af8..5529df92 100644 --- a/examples/react-app/src/components/transfer.tsx +++ b/examples/react-app/src/components/transfer.tsx @@ -23,7 +23,11 @@ export default function Transfer() { const handleTransfer = async () => { setLoading(true); try { - const receiverAddress = Address.fromString(receiver || DEFAULT_ADDRESS); + if (!receiver) { + throw Error('Invalid address'); + } + + const receiverAddress = Address.fromString(receiver); const asset_id = wallet?.provider.getBaseAssetId(); const resp = await wallet?.transfer( @@ -58,13 +62,15 @@ export default function Transfer() { } catch (err) { const error = err as CustomError; console.error(error.message); + setToast({ open: true, type: 'error', - children: `The transfer could not be processed: ${error.message.substring( - 0, - 32, - )}...`, + children: `The transfer could not be processed: ${ + error.message.includes('Invalid B256 Address') + ? 'Invalid address' + : error.message.substring(0, 32) + }...`, }); } finally { setLoading(false);