Skip to content
This repository was archived by the owner on Apr 4, 2022. It is now read-only.

Cowswap 1316/trailling dot #300

Merged
merged 2 commits into from
Dec 3, 2021
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
2 changes: 1 addition & 1 deletion src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function _formatSmart(

const amountBeforePrecisionCheck =
_formatNumber(integerPart.toString(10), thousandsSymbol) + decimalsSymbol + decimalsPadded
return `${sign}${adjustPrecision(amountBeforePrecisionCheck, finalPrecision, decimalsSymbol).replace(/0+$/, '')}`
return `${sign}${adjustPrecision(amountBeforePrecisionCheck, finalPrecision, decimalsSymbol).replace(/\.?0*$/, '')}`
}

function _decomposeBn(
Expand Down
5 changes: 5 additions & 0 deletions test/utils/format/formatSmart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ describe('Edge cases', () => {
const amount = new BN('1234567')
expect(formatSmart({ amount, precision: 2, decimals: 4 })).toEqual('12,345.67')
})

test('Do not return values with trailing dots', () => {
const amount = '353276954043779'
expect(formatSmart({ amount, precision: 6, decimals: 4, smallLimit: '0.0001', thousandSeparator: false, isLocaleAware: false })).toEqual('353276954')
})
})

describe('Amount is a string', () => {
Expand Down