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

added maximumSignificantDigits to 4 for amount #278

Merged
merged 3 commits into from
May 19, 2022
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { arrayDistinctBy } from 'src/utils/array.util';
import { getTokenInfo } from 'src/utils/contract.util';
import { GUpx } from 'src/utils/style.util';
import { Logger } from 'src/utils/logger';
import { floorNumber } from 'src/utils/math.utils';
import { includesCaseInsensitive } from 'src/utils/string.util';
import { isAddress } from 'src/utils/web3.utils';
import styled from 'styled-components';
Expand Down Expand Up @@ -83,7 +82,6 @@ type TokenBadgeProp = {
token?: TokenModel;
amount?: number | false;
usdValue?: number | false;
decimalsCount?: number;
};

const TokenAmountBadge = React.memo(
Expand All @@ -99,13 +97,15 @@ const TokenAmountBadge = React.memo(
},
amount,
usdValue,
decimalsCount,
}: TokenBadgeProp) => {
const copyCode = useCopyToClipboard();
const label = useMemo(() => {
let temp = '';
if (amount !== false && amount !== undefined) {
temp += `${floorNumber(amount ?? 0, decimalsCount).toLocaleString()} `;
const amountFormat = new Intl.NumberFormat('en-US', {
maximumFractionDigits: 4,
}).format(amount);
temp += `${amountFormat} `;
}
temp += `${token.symbol}`;
if (usdValue) {
Expand Down Expand Up @@ -151,7 +151,6 @@ type Props = {
formik?: FormikContextType<any>;
compact?: boolean;
tooltip?: ReactNode;
maxDecimals?: number;
disabled?: boolean;
wide?: boolean;
tokenEditable?: boolean;
Expand All @@ -174,7 +173,6 @@ function AmountFieldInput({
formik,
tooltip,
compact = false,
maxDecimals,
disabled = false,
wide = false,
tokenEditable = false,
Expand All @@ -185,7 +183,6 @@ function AmountFieldInput({
}: Props) {
let mounted = true;
const { networkId } = getNetwork();
const [decimalsCount, setDecimalsCount] = useState(maxDecimals);
const [tokens, setTokens] = useState<TokenModel[]>([]);
const [searchTerm, setSearchTerm] = useState<string>();
const [amount, setAmount] = useState<number | undefined>(value?.parsedAmount);
Expand Down Expand Up @@ -235,13 +232,6 @@ function AmountFieldInput({
}
}, [searchTerm, availableTokens, _hasFocused]);

useEffect(() => {
if (!isEdit) {
if (value?.parsedAmount && (!maxDecimals || maxDecimals > 0))
setDecimalsCount(maxDecimals ?? 4);
}
}, [maxDecimals, isEdit, value?.parsedAmount]);

useEffect(() => {
setAmount(value?.parsedAmount ?? 0);
setToken(value?.token);
Expand Down Expand Up @@ -328,7 +318,7 @@ function AmountFieldInput({
disabled={!token ? true : disabled}
/>
) : (
floorNumber(amount, decimalsCount).toLocaleString()
Intl.NumberFormat('en-US', { maximumFractionDigits: 4 }).format(amount)
))}
</AmountTokenWrapperStyled>
</FieldInput>
Expand All @@ -349,7 +339,6 @@ function AmountFieldInput({
token={token}
amount={tagOnly && amount}
usdValue={showUsd && value?.usdValue}
decimalsCount={decimalsCount}
/>
) : (
<AutoCompleteWrapperStyled wide={wide}>
Expand Down