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: Permit Simulation should include decimals in fiat calculation and show tooltip if shortened #26523

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
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 @@ -4,7 +4,6 @@ import { NameType } from '@metamask/name-controller';

import { calcTokenAmount } from '../../../../../../../../shared/lib/transactions-controller-utils';
import { parseTypedDataMessage } from '../../../../../../../../shared/modules/transaction.utils';
import { Numeric } from '../../../../../../../../shared/modules/Numeric';
import Name from '../../../../../../../components/app/name/name';
import {
ConfirmInfoRow,
Expand Down Expand Up @@ -48,7 +47,8 @@ const PermitSimulation: React.FC<{

const fiatValue = useMemo(() => {
if (exchangeRate && value) {
return exchangeRate.times(new Numeric(value, 10)).toNumber();
const tokenAmount = calcTokenAmount(value, tokenDecimals);
return exchangeRate.times(tokenAmount).toNumber();
}
return undefined;
}, [exchangeRate, value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { Text } from '../../../../components/component-library';
import { SizeNumber } from '../../../../components/component-library/box/box.types';
import Tooltip from '../../../../components/ui/tooltip';
import { useFiatFormatter } from '../../../../hooks/useFiatFormatter';
import { useHideFiatForTestnet } from '../../../../hooks/useHideFiatForTestnet';
import { FIAT_UNAVAILABLE, FiatAmount } from './types';
Expand Down Expand Up @@ -51,10 +52,17 @@ export const IndividualFiatDisplay: React.FC<{
return <FiatNotAvailableDisplay />;
}
const absFiat = Math.abs(fiatAmount);
const fiatDisplayValue = fiatFormatter(absFiat, { shorten });

return (
return shorten ? (
<Tooltip position="bottom" title={fiatDisplayValue} interactive>
<Text {...textStyle} data-testid="individual-fiat-display">
{fiatDisplayValue}
</Text>
</Tooltip>
) : (
<Text {...textStyle} data-testid="individual-fiat-display">
{fiatFormatter(absFiat, { shorten })}
{fiatDisplayValue}
</Text>
);
};
Expand Down