From e79a4ed3fb2fecd67a32bc604187e4c520c6b7b5 Mon Sep 17 00:00:00 2001 From: Aaron Quirk Date: Tue, 29 Oct 2024 12:44:20 -0400 Subject: [PATCH] Validate token decimals before send (#219) --- packages/ui-components/package.json | 2 +- .../ui-components/src/components/Wallet/Send.tsx | 15 ++++++++++++++- .../ui-components/src/components/Wallet/Token.tsx | 3 --- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/ui-components/package.json b/packages/ui-components/package.json index 033281b9..846cb84c 100644 --- a/packages/ui-components/package.json +++ b/packages/ui-components/package.json @@ -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": [ diff --git a/packages/ui-components/src/components/Wallet/Send.tsx b/packages/ui-components/src/components/Wallet/Send.tsx index 78efe8a5..81e26b28 100644 --- a/packages/ui-components/src/components/Wallet/Send.tsx +++ b/packages/ui-components/src/components/Wallet/Send.tsx @@ -274,7 +274,20 @@ const Send: React.FC = ({ }; 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) { diff --git a/packages/ui-components/src/components/Wallet/Token.tsx b/packages/ui-components/src/components/Wallet/Token.tsx index 0ff2c3f2..5be267fa 100644 --- a/packages/ui-components/src/components/Wallet/Token.tsx +++ b/packages/ui-components/src/components/Wallet/Token.tsx @@ -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'; @@ -120,8 +119,6 @@ const Token: React.FC = ({ showGraph, hideBalance, }) => { - const theme = useTheme(); - const {classes, cx} = useStyles({ palette: isOwner ? WalletPaletteOwner : WalletPalettePublic, });