-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix the formatPrice fn to show at least 1 relevant decimal
- Loading branch information
1 parent
a2d7308
commit b32ebba
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
webapp/src/components/Modals/BuyWithCryptoModal/utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Token } from 'decentraland-transactions/crossChain' | ||
import { formatPrice } from './utils' | ||
|
||
let token: Token | ||
|
||
describe('Utils', () => { | ||
describe('formatPrice with high value token', () => { | ||
beforeEach(() => { | ||
token = { usdPrice: 1000 } as Token | ||
}) | ||
it('should render the right amount of decimals', () => { | ||
expect(formatPrice(1234.5678, token)).toBe(1234.5678) | ||
expect(formatPrice('1234.5678', token)).toBe(1234.5678) | ||
expect(formatPrice(1234.56789, token)).toBe(1234.5678) | ||
expect(formatPrice('1234.56789', token)).toBe(1234.5678) | ||
expect(formatPrice(0.0000001, token)).toBe(0.0000001) // show first relevant decimal even if it's too low | ||
}) | ||
}) | ||
|
||
describe('formatPrice with low value token', () => { | ||
beforeEach(() => { | ||
token = { usdPrice: 0.5 } as Token | ||
}) | ||
it('should render the right amount of decimals', () => { | ||
expect(formatPrice(0.0001234, token)).toBe(0.00012) | ||
expect(formatPrice('0.0001234', token)).toBe(0.00012) | ||
expect(formatPrice(0.0001267, token)).toBe(0.00012) | ||
expect(formatPrice('0.0001267', token)).toBe(0.00012) | ||
expect(formatPrice(0.0000001, token)).toBe(0.0000001) // show first relevant decimal even if it's too low | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters