Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

[react-i18n] Fix unformatCurrency utility stripping significant digits on RSD currency #1902

Merged
merged 5 commits into from
May 19, 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
4 changes: 3 additions & 1 deletion packages/react-i18n/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->
<!-- Unreleased -->

- Fixed `currencyDecimalSymbol` function returning `DECIMAL_NOT_SUPPORTED` for RSD [#1902](https://github.com/Shopify/quilt/pull/1902)

## 5.3.4 - 2021-04-13

Expand Down
1 change: 1 addition & 0 deletions packages/react-i18n/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export class I18n {
const templatedInput = 1;
const decimal = this.formatCurrency(templatedInput, {
currency: currencyCode,
form: 'short',
})
.replace(symbol, '')
.replace(digitOrSpace, '');
Expand Down
11 changes: 11 additions & 0 deletions packages/react-i18n/src/test/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,17 @@ describe('I18n', () => {
expect(i18n.unformatCurrency('1', 'USD')).toBe('1.00');
});

it('handles formatted RSD input', () => {
getCurrencySymbol.mockReturnValue({
symbol: 'RSD',
prefixed: true,
});

const i18n = new I18n(defaultTranslations, defaultDetails);
expect(i18n.unformatCurrency('1,234.55', 'RSD')).toBe('1234.55');
expect(i18n.unformatCurrency('1', 'RSD')).toBe('1.00');
});

describe('prefixed symbols', () => {
it('handles prefix with a space', () => {
getCurrencySymbol.mockReturnValue(mockSymbolResult);
Expand Down