Skip to content

Commit

Permalink
Make fiat conversions accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jul 25, 2023
1 parent 663525f commit 78509ed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app/components/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TokenPriceInfo } from '../../../coin-gecko/api'
import { ContractCreatorInfo } from './ContractCreatorInfo'
import { ContractVerificationIcon } from '../ContractVerificationIcon'
import { TokenLink } from '../Tokens/TokenLink'
import BigNumber from 'bignumber.js'

export const StyledAvatarContainer = styled('dt')(({ theme }) => ({
'&&': {
Expand Down Expand Up @@ -154,7 +155,7 @@ export const Account: FC<AccountProps> = ({ account, token, isLoading, tokenPric
<dd>
<FiatMoneyAmountBox>
{t('common.fiatValueInUSD', {
value: parseFloat(balance) * tokenFiatValue,
value: new BigNumber(balance).multipliedBy(tokenFiatValue).toFixed(),
formatParams: {
value: {
currency: 'USD',
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/TransactionDetailPage/CurrentFiatValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Tooltip from '@mui/material/Tooltip'
import { CoinGeckoReferral } from '../../components/CoinGeckoReferral'
import HelpIcon from '@mui/icons-material/Help'
import { TokenPriceInfo } from '../../../coin-gecko/api'
import BigNumber from 'bignumber.js'

type CurrentFiatValueProps = Pick<TokenPriceInfo, 'price' | 'hasUsedCoinGecko'> & {
amount: string
Expand All @@ -17,7 +18,7 @@ export const CurrentFiatValue: FC<CurrentFiatValueProps> = ({ amount, price, has
<FiatMoneyAmountBox>
<Box sx={{ display: 'inline-flex', alignItems: 'center' }}>
{t('common.fiatValueInUSD', {
value: parseFloat(amount) * price,
value: new BigNumber(amount).multipliedBy(price).toFixed(),
formatParams: {
value: {
currency: 'USD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('CurrentFiatValue', () => {
price={0.55555}
/>,
)
expect(screen.getByText('$555,550,000,055,555,000,000,000,000,000,000,000,000.00')).toBeInTheDocument()
expect(screen.getByText('$555,550,000,055,555,000,005,555,500,000,555,550,000.06')).toBeInTheDocument()
expect(screen.getByText('CoinGecko')).toBeInTheDocument()
})
})
4 changes: 2 additions & 2 deletions src/locales/__tests__/i18n-formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('formatting fiat currency with i18n', () => {
const { result } = renderHook(() => {
const { t } = useTranslation()
return t('does_not_exist.use_default', '{{value, currency}}', {
value: 123.456789,
value: '111222333444555666777888999.111222333444555666',
formatParams: {
value: {
currency: 'USD',
Expand All @@ -38,7 +38,7 @@ test('formatting fiat currency with i18n', () => {
}) as string
})

expect(result.current).toBe('$123.46')
expect(result.current).toBe('$111,222,333,444,555,666,777,888,999.11')
})

test('formatting block sizes with i18n', () => {
Expand Down

0 comments on commit 78509ed

Please sign in to comment.