Skip to content

Commit

Permalink
fix: sanitize <TradeAmountInput /> precision (#7126)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Jun 13, 2024
1 parent 55958e2 commit 3e08ec9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 765 deletions.
237 changes: 0 additions & 237 deletions src/components/DeFi/components/Allocation.tsx

This file was deleted.

9 changes: 7 additions & 2 deletions src/components/DeFi/components/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { useLocaleFormatter } from 'hooks/useLocaleFormatter/useLocaleFormatter'
import { useToggle } from 'hooks/useToggle/useToggle'
import { bnOrZero } from 'lib/bignumber/bignumber'
import { allowedDecimalSeparators } from 'state/slices/preferencesSlice/preferencesSlice'
import { selectAssetById } from 'state/slices/selectors'
import { useAppSelector } from 'state/store'
import { colors } from 'theme/colors'

import { Balance } from './Balance'
Expand Down Expand Up @@ -49,7 +51,7 @@ const CryptoInput = (props: InputProps) => {

export type AssetInputProps = {
accountId?: AccountId | undefined
assetId?: AssetId
assetId: AssetId
assetSymbol: string
assetIcon: string
onChange?: (value: string, isFiat?: boolean) => void
Expand Down Expand Up @@ -108,6 +110,8 @@ export const AssetInput: React.FC<AssetInputProps> = ({
const handleBlur = useCallback(() => setIsFocused(false), [])
const handleFocus = useCallback(() => setIsFocused(true), [])

const asset = useAppSelector(state => selectAssetById(state, assetId))

// Lower the decimal places when the integer is greater than 8 significant digits for better UI
const cryptoAmountIntegerCount = bnOrZero(bnOrZero(cryptoAmount).toFixed(0)).precision(true)
const formattedCryptoAmount = bnOrZero(cryptoAmountIntegerCount).isLessThanOrEqualTo(8)
Expand Down Expand Up @@ -164,6 +168,7 @@ export const AssetInput: React.FC<AssetInputProps> = ({
<Stack spacing={0} flex={1} alignItems='flex-end'>
<Skeleton isLoaded={!showInputSkeleton} width='full'>
<NumberFormat
decimalScale={isFiat ? undefined : asset?.precision}
customInput={CryptoInput}
isNumericString={true}
disabled={isReadOnly}
Expand Down Expand Up @@ -224,7 +229,7 @@ export const AssetInput: React.FC<AssetInputProps> = ({
)}
</Stack>
)}
{handleAccountIdChange && assetId && (
{handleAccountIdChange && (
<AccountDropdown
{...(accountId ? { defaultAccountId: accountId } : {})}
assetId={assetId}
Expand Down
71 changes: 0 additions & 71 deletions src/components/FeeExplainer/components/FeeInput.tsx

This file was deleted.

6 changes: 5 additions & 1 deletion src/components/Modals/Send/views/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const Details = () => {
[asset?.symbol, translate],
)

if (!(asset && !isNil(amountCryptoPrecision) && !isNil(fiatAmount) && fiatSymbol)) {
if (!(assetId && asset && !isNil(amountCryptoPrecision) && !isNil(fiatAmount) && fiatSymbol)) {
return null
}

Expand Down Expand Up @@ -254,6 +254,8 @@ export const Details = () => {
</Box>
{fieldName === SendFormFields.AmountCryptoPrecision && (
<TokenRow
isFiat={false}
assetId={assetId}
control={control}
fieldName={SendFormFields.AmountCryptoPrecision}
onInputChange={handleInputChange}
Expand All @@ -265,6 +267,8 @@ export const Details = () => {
)}
{fieldName === SendFormFields.FiatAmount && (
<TokenRow
isFiat
assetId={assetId}
control={control}
fieldName={SendFormFields.FiatAmount}
onInputChange={handleInputChange}
Expand Down
Loading

0 comments on commit 3e08ec9

Please sign in to comment.