Skip to content

Commit

Permalink
Validate token decimals before send (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
qrtp authored Oct 29, 2024
1 parent da80d30 commit e79a4ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unstoppabledomains/ui-components",
"version": "0.0.51-browser-extension.5",
"version": "0.0.51-browser-extension.6",
"private": true,
"description": "An open and reusable suite of Unstoppable Domains management components",
"keywords": [
Expand Down
15 changes: 14 additions & 1 deletion packages/ui-components/src/components/Wallet/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,20 @@ const Send: React.FC<Props> = ({
};

const handleAmountChange = (value: string) => {
setAmount(value);
// validate an asset is selected
if (!accountAsset) {
return;
}

// normalize asset decimals if present
const normalizedValue = accountAsset.balance?.decimals
? `0.${value
.replaceAll('0.', '')
.slice(0, accountAsset.balance.decimals)}`
: value;

// use normalized value
setAmount(normalizedValue);
};

if (isLoading) {
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/src/components/Wallet/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import type {Theme} from '@mui/material/styles';
import {useTheme} from '@mui/material/styles';
import numeral from 'numeral';
import React from 'react';
import {Line} from 'react-chartjs-2';
Expand Down Expand Up @@ -120,8 +119,6 @@ const Token: React.FC<Props> = ({
showGraph,
hideBalance,
}) => {
const theme = useTheme();

const {classes, cx} = useStyles({
palette: isOwner ? WalletPaletteOwner : WalletPalettePublic,
});
Expand Down

0 comments on commit e79a4ed

Please sign in to comment.