-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactoring currency module to use central geo data [ATLAS-167] #119
Changes from all commits
04be70f
0a31e95
0a99b1e
cecfc5e
94a60b4
a1bd63f
f94e5ce
f4a42e4
803a5fc
a8665df
345bbcb
18fb57b
fb69967
31116f1
a33b6ed
155bcdb
e8e64d2
8e1cdbe
0a37540
dff98c0
010849b
2104a53
883fd57
6568461
58fd032
92cfe26
d969053
847cc99
051550d
8ba0688
4fd7677
684fff0
3f0646f
719e25c
08c270a
e6c1a19
550f6e4
6f2c12d
2190465
b0e180e
31db929
de316a9
42b8869
77eefa5
b7af662
dfdb503
da3d1cd
07cef04
45c43ca
9349cee
6f68562
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@razorpay/i18nify-js': patch | ||
--- | ||
|
||
feat: refactoring currency module to use central geo data |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Creates a smaller json currency configuration from parent i18nify-data. | ||
* | ||
* @example | ||
* {"AFN": { | ||
"name": "Afghani", | ||
"numeric_code": "971", | ||
"minor_unit": "2", | ||
"symbol": "؋", | ||
"physical_currency_denominations": [ | ||
"1", | ||
"2", | ||
"5", | ||
"10", | ||
"20", | ||
"50", | ||
"100", | ||
"500", | ||
"1000" | ||
] | ||
} | ||
transforms to | ||
{"AFN": { | ||
"name": "Afghani", | ||
"minor_unit": "2", | ||
"symbol": "؋" | ||
} | ||
} | ||
|
||
* | ||
*/ | ||
|
||
export default () => { | ||
const DATA = require('#/i18nify-data/currency/data.json'); | ||
|
||
const currencyInfo = DATA.currency_information; | ||
|
||
const currencyConfigSubset = Object.keys(currencyInfo).reduce( | ||
(acc: any, curr: any) => { | ||
acc[curr] = { | ||
name: currencyInfo[curr].name, | ||
minor_unit: currencyInfo[curr].minor_unit, | ||
symbol: currencyInfo[curr].symbol, | ||
}; | ||
return acc; | ||
}, | ||
{}, | ||
); | ||
|
||
return { | ||
data: currencyConfigSubset, | ||
subsetFilePath: './src/modules/currency/data/currencyConfig.json', | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import transformFormatterConfig from './phoneNumber/transformFormatterConfig'; | ||
import transformRegexConfig from './phoneNumber/transformRegexConfig'; | ||
import transformCurrencyConfig from './currency/transformCurrencyConfig'; | ||
import createModuleSubsetFile from './createFile'; | ||
|
||
createModuleSubsetFile(transformFormatterConfig()); | ||
createModuleSubsetFile(transformRegexConfig()); | ||
createModuleSubsetFile(transformCurrencyConfig()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { getCurrencyList } from '../index'; | ||
import { CURRENCIES } from '../data/currencies'; | ||
import CURRENCY_INFO from '../data/currencyConfig.json'; | ||
import { Currency } from '../types'; | ||
|
||
describe('getCurrencyList', () => { | ||
it('should return the correct currency list', () => { | ||
const currencyList = getCurrencyList(); | ||
expect(currencyList).toEqual(CURRENCIES); | ||
expect(currencyList).toEqual(CURRENCY_INFO); | ||
}); | ||
|
||
it("check properties 'symbol' and 'name' for a sample currency", () => { | ||
|
@@ -17,10 +19,12 @@ describe('getCurrencyList', () => { | |
it("check the values of 'symbol' and 'name' properties for a sample currency", () => { | ||
const currencyList = getCurrencyList(); | ||
const sampleCurrencyCode = 'USD'; | ||
const sampleCurrency = currencyList[sampleCurrencyCode]; | ||
const sampleCurrency: Currency[string] = currencyList[sampleCurrencyCode]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this translate to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it's needed, since currency interface looks like below: export interface Currency {
[key: string]: {
name: string;
minor_unit: string;
symbol: string;
};
} and sampleCurrency is supposed to store value like below: {
name: "Indian Rupee",
minor_unit: "2",
symbol: "₹"
} |
||
|
||
// Assert that the 'symbol' and 'name' properties have the expected values | ||
expect(sampleCurrency.symbol).toBe(CURRENCIES[sampleCurrencyCode].symbol); | ||
expect(sampleCurrency.name).toBe(CURRENCIES[sampleCurrencyCode].name); | ||
expect(sampleCurrency.symbol).toBe( | ||
CURRENCY_INFO[sampleCurrencyCode].symbol, | ||
); | ||
expect(sampleCurrency.name).toBe(CURRENCY_INFO[sampleCurrencyCode].name); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required in declaration types ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it fixes below error that occurs while creating build, during declaration file creation (
src/modules/currency/index.ts → lib/esm/currency/index.d.ts
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still required ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes tried removing it, and above error pops again while creating build.