Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: solve amount validation bug #654

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions source/pages/Send/SendEth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useSelector } from 'react-redux';

import { isValidEthereumAddress } from '@pollum-io/sysweb3-utils';

import errorIcon from 'assets/icons/errorIcon.svg';
import successIcon from 'assets/icons/successIcon.svg';
import { Card, Layout, Button } from 'components/index';
import { useUtils } from 'hooks/index';
import { useController } from 'hooks/useController';
Expand Down Expand Up @@ -64,9 +66,23 @@ export const SendEth = () => {
const validAddress = isValidEthereumAddress(value);
setIsValidAddress(validAddress);
} else if (name === 'amount') {
const balance = selectedAsset
? selectedAsset.balance
: Number(activeAccount?.balances.ethereum);

const validAmount =
value <= Number(activeAccount?.balances.ethereum) && value > 0;
setIsValidAmount(validAmount);
Number(value) > 0 && parseFloat(value) <= parseFloat(balance);

const isValidForSelectedAsset = selectedAsset
? selectedAsset.isNft || (!selectedAsset.isNft && validAmount)
: validAmount;

if (isValidForSelectedAsset) {
setIsValidAmount(true);
} else {
setIsValidAmount(false);
console.warn('Insufficient funds or invalid amount');
}
} else {
setIsValidAddress(null);
}
Expand Down Expand Up @@ -276,14 +292,10 @@ export const SendEth = () => {
/>
{isValidAddress !== null && (
<img
src={
isValidAddress === true
? '/assets/icons/successIcon.svg'
: '/assets/icons/errorIcon.svg'
}
alt={isValidAddress === true ? 'Success' : 'Error'}
src={isValidAddress ? successIcon : errorIcon}
alt={isValidAddress ? 'Success' : 'Error'}
className={`absolute right-8 ${
isValidAmount === true ? 'top-[12.5px]' : 'top-[11.5px]'
isValidAmount ? 'top-[12.5px]' : 'top-[11.5px]'
}`}
/>
)}
Expand Down Expand Up @@ -407,18 +419,14 @@ export const SendEth = () => {
}

if (
Boolean(
selectedAsset &&
selectedAsset.isNft &&
Number(value) > 0
) ||
Boolean(
selectedAsset &&
!selectedAsset.isNft &&
parseFloat(value) <=
parseFloat(selectedAsset.balance) &&
Number(value) > 0
)
(selectedAsset &&
selectedAsset.isNft &&
Number(value) > 0) ||
(selectedAsset &&
!selectedAsset.isNft &&
parseFloat(value) <=
parseFloat(selectedAsset.balance) &&
Number(value) > 0)
) {
return Promise.resolve();
}
Expand Down
Loading