Skip to content

Commit

Permalink
fix: validation when empty address and address error message fixed (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropereiradev authored May 29, 2024
1 parent bec6738 commit 5431179
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions examples/react-app/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5431179

Please sign in to comment.