Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
fix: only use 2 decimals for fiat (#3935)
Browse files Browse the repository at this point in the history
* fix: only use 2 decimals for fiat

* fix: test

* fix: don't format tokens as currency
  • Loading branch information
iamacook authored Jun 8, 2022
1 parent a38298f commit 1d040c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/logic/safe/utils/mocks/getChainsConfigMock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainListResponse } from '@gnosis.pm/safe-react-gateway-sdk'
import mockData from './remoteConfig.json'

export const mockGetChainsConfigResponse = mockData as ChainListResponse
export const mockGetChainsConfigResponse = mockData as unknown as ChainListResponse
12 changes: 6 additions & 6 deletions src/logic/tokens/utils/__tests__/formatAmount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,32 @@ describe('formatCurrency', () => {
// then
expect(result).toBe(expectedResult)
})
it('Given a number in format XXXXX.XXX returns a number of format XX,XXX.XXX', () => {
it('Given a number in format XXXXX.XXX returns a number of format XX,XXX.XX', () => {
// given
const input = 19797.899
const expectedResult = '19,797.899 EUR'
const expectedResult = '19,797.90 EUR'

// when
const result = formatCurrency(input.toString(), 'EUR')

// then
expect(result).toBe(expectedResult)
})
it('Given a number in format XXXXXXXX.XXX returns a number of format XX,XXX,XXX.XXX', () => {
it('Given a number in format XXXXXXXX.XXX returns a number of format XX,XXX,XXX.XX', () => {
// given
const input = 19797899.479
const expectedResult = '19,797,899.479 EUR'
const expectedResult = '19,797,899.48 EUR'

// when
const result = formatCurrency(input.toString(), 'EUR')

// then
expect(result).toBe(expectedResult)
})
it('Given a number in format XXXXXXXXXXX.XXX returns a number of format XX,XXX,XXX,XXX.XXX', () => {
it('Given a number in format XXXXXXXXXXX.XXX returns a number of format XX,XXX,XXX,XXX.XX', () => {
// given
const input = 19797899479.999
const expectedResult = '19,797,899,479.999 EUR'
const expectedResult = '19,797,899,480.00 EUR'

// when
const result = formatCurrency(input.toString(), 'EUR')
Expand Down
3 changes: 2 additions & 1 deletion src/logic/tokens/utils/formatAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export const formatAmount = (number: string): string => {
return numberFloat
}

// Note: we can't use Intl.NumberFormat's 'currency' style as it doesn't support all fiats
const currencyFormatter = new Intl.NumberFormat(LOCALE, {
minimumFractionDigits: 2,
maximumFractionDigits: 8,
maximumFractionDigits: 2,
})

export const formatCurrency = (amount: string, currencySelected: string): string => {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/safe/components/Balances/dataFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { List } from 'immutable'
import { formatCurrency } from 'src/logic/tokens/utils/formatAmount'
import { formatAmount, formatCurrency } from 'src/logic/tokens/utils/formatAmount'
import { TableColumn } from 'src/components/Table/types.d'
import { Token } from 'src/logic/tokens/store/model/token'
export const BALANCE_TABLE_ASSET_ID = 'asset'
Expand All @@ -26,7 +26,7 @@ export const getBalanceData = (safeTokens: List<Token>, currencySelected: string
symbol: token.symbol,
},
assetOrder: token.name,
[BALANCE_TABLE_BALANCE_ID]: formatCurrency(tokenBalance?.toString() || '0', token.symbol),
[BALANCE_TABLE_BALANCE_ID]: `${formatAmount(tokenBalance?.toString() || '0')} ${token.symbol}`,
balanceOrder: Number(tokenBalance),
[BALANCE_TABLE_VALUE_ID]: formatCurrency(fiatBalance?.toString() || '0', currencySelected),
valueOrder: Number(tokenBalance),
Expand Down

0 comments on commit 1d040c1

Please sign in to comment.