Skip to content

Commit 5328c9a

Browse files
committed
use uniform Number formatting methods
1 parent 7fbea3d commit 5328c9a

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

public/locales/en-US/translations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@
848848
"depositors": "Depositors",
849849
"percent_of_supply": "% of Supply",
850850
"value": "Value",
851-
"currency_toggle_help": "Toggle to view values in Native-Currency or USD",
851+
"currency_toggle_help": "Toggle to view values in native-currency or USD",
852852
"currency_toggle_loading": "Loading USD conversion rate...",
853853
"currency_toggle_unavailable": "USD conversion not available for this token"
854854
}

src/containers/Vault/VaultLoans/LoanRow.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'
33
import { Account } from '../../shared/components/Account'
44
import { useLanguage } from '../../shared/hooks'
55
import { useTokenToUSDRate } from '../../shared/hooks/useTokenToUSDRate'
6-
import { localizeNumber } from '../../shared/utils'
6+
import { parseAmount } from '../../shared/NumberFormattingUtils'
77
import {
88
formatRate,
99
formatPaymentInterval,
@@ -78,10 +78,7 @@ export const LoanRow = ({
7878
}
7979

8080
const prefix = displayCurrency === 'USD' ? '$' : ''
81-
return `${prefix}${localizeNumber(displayNum, language, {
82-
minimumFractionDigits: 2,
83-
maximumFractionDigits: 2,
84-
})} ${currency}`
81+
return `${prefix}${parseAmount(displayNum, 1, language)} ${currency}`
8582
}
8683

8784
const formatFee = (fee: string | number): string => {
@@ -100,10 +97,7 @@ export const LoanRow = ({
10097
}
10198

10299
const prefix = displayCurrency === 'USD' ? '$' : ''
103-
return `${prefix}${localizeNumber(displayNum, language, {
104-
minimumFractionDigits: 0,
105-
maximumFractionDigits: 2,
106-
})} ${currency}`
100+
return `${prefix}${parseAmount(displayNum, 1, language)} ${currency}`
107101
}
108102

109103
const formatGracePeriod = (seconds: number): string => {

src/containers/Vault/VaultLoans/test/utils.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ describe('VaultLoans Utils', () => {
3636
describe('formatRate', () => {
3737
it('converts 1/10th basis points to percentage', () => {
3838
// 500 / 1000 = 0.5%
39-
expect(formatRate(500)).toBe('0.500%')
39+
expect(formatRate(500)).toBe('0.50%')
4040
})
4141

4242
it('handles zero rate', () => {
43-
expect(formatRate(0)).toBe('0.000%')
43+
expect(formatRate(0)).toBe('0.00%')
4444
})
4545

4646
it('handles small rates (less than 1 basis point)', () => {
4747
// 1 / 1000 = 0.001%
48-
expect(formatRate(1)).toBe('0.001%')
48+
expect(formatRate(1)).toBe('0.00%')
4949
})
5050

5151
it('handles large rates', () => {
5252
// 10000 / 1000 = 10%
53-
expect(formatRate(10000)).toBe('10.000%')
53+
expect(formatRate(10000)).toBe('10.00%')
5454
})
5555

5656
it('returns default value for undefined rate', () => {
@@ -60,9 +60,9 @@ describe('VaultLoans Utils', () => {
6060

6161
it('formats with exactly 3 decimal places', () => {
6262
// Ensures consistent formatting regardless of value
63-
expect(formatRate(1000)).toBe('1.000%')
64-
expect(formatRate(1500)).toBe('1.500%')
65-
expect(formatRate(1234)).toBe('1.234%')
63+
expect(formatRate(1000)).toBe('1.00%')
64+
expect(formatRate(1500)).toBe('1.50%')
65+
expect(formatRate(1234)).toBe('1.23%')
6666
})
6767
})
6868

src/containers/Vault/VaultLoans/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const formatRate = (rate: number | undefined): string => {
1919
// 1 basis point = 0.01%, 1/10th basis point = 0.001%
2020
const percentage = rate / ONE_TENTH_BASIS_POINT
2121

22-
// The field must be able to display up to 3 decimal places
23-
return `${percentage.toFixed(3)}%`
22+
// The field must be able to display up to 2 decimal places
23+
return `${percentage.toFixed(2)}%`
2424
}
2525

2626
/**

0 commit comments

Comments
 (0)