@ledgerhq/coin-module-framework 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.unimportedrc.json +0 -1
- package/CHANGELOG.md +12 -0
- package/lib/api/types.d.ts +6 -1
- package/lib/api/types.d.ts.map +1 -1
- package/lib/config.d.ts +3 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +2 -2
- package/lib/config.js.map +1 -1
- package/lib/currencies/BigNumberToLocaleString.d.ts +7 -0
- package/lib/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.js +58 -0
- package/lib/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib/currencies/formatCurrencyUnit.d.ts +25 -1
- package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -1
- package/lib/currencies/formatCurrencyUnit.js +130 -4
- package/lib/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib/currencies/localeUtility.d.ts +8 -0
- package/lib/currencies/localeUtility.d.ts.map +1 -0
- package/lib/currencies/localeUtility.js +51 -0
- package/lib/currencies/localeUtility.js.map +1 -0
- package/lib/currencies/parseCurrencyUnit.d.ts +2 -1
- package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -1
- package/lib/currencies/parseCurrencyUnit.js +9 -2
- package/lib/currencies/parseCurrencyUnit.js.map +1 -1
- package/lib-es/api/types.d.ts +6 -1
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/config.d.ts +3 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +2 -2
- package/lib-es/config.js.map +1 -1
- package/lib-es/currencies/BigNumberToLocaleString.d.ts +7 -0
- package/lib-es/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.js +54 -0
- package/lib-es/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts +25 -1
- package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -1
- package/lib-es/currencies/formatCurrencyUnit.js +127 -1
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -1
- package/lib-es/currencies/localeUtility.d.ts +8 -0
- package/lib-es/currencies/localeUtility.d.ts.map +1 -0
- package/lib-es/currencies/localeUtility.js +48 -0
- package/lib-es/currencies/localeUtility.js.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts +2 -1
- package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -1
- package/lib-es/currencies/parseCurrencyUnit.js +8 -1
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -1
- package/package.json +5 -5
- package/src/api/types.ts +8 -1
- package/src/config.ts +4 -5
- package/src/currencies/BigNumberToLocaleString.test.ts +164 -0
- package/src/currencies/BigNumberToLocaleString.ts +70 -0
- package/src/currencies/formatCurrencyUnit.test.ts +215 -0
- package/src/currencies/formatCurrencyUnit.ts +200 -6
- package/src/currencies/localeUtility.test.ts +22 -0
- package/src/currencies/localeUtility.ts +59 -0
- package/src/currencies/parseCurrencyUnit.test.ts +26 -0
- package/src/currencies/parseCurrencyUnit.ts +10 -1
package/lib-es/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,KAAK,YAAY,GACb;IACE,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAA;CAC3B,GACD;IACE,IAAI,EAAE,mBAAmB,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GACD;IACE,IAAI,EAAE,WAAW,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,GACD;IACE,IAAI,EAAE,qBAAqB,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EACH,SAAS,GACT,MAAM,GACN,eAAe,GACf,kBAAkB,GAClB,MAAM,GACN,SAAS,GACT,gBAAgB,GAChB,kBAAkB,GAClB,SAAS,GACT,0BAA0B,CAAA;CAC/B,GACD;IACE,IAAI,EAAE,oBAAoB,CAAA;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;CACb,GACD;IACE,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAEL,KAAK,MAAM,GAAG;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,YAAY,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,CAAC,CAAA;AAE7E,iBAAS,eAAe,CAAC,CAAC,SAAS,cAAc;4BAGhB,UAAU,CAAC,CAAC,CAAC,KAAG,IAAI;iCAIf,MAAM,KAAG,CAAC;EAY/C;AAED,eAAe,eAAe,CAAA"}
|
package/lib-es/config.js
CHANGED
|
@@ -4,11 +4,11 @@ function buildCoinConfig() {
|
|
|
4
4
|
const setCoinConfig = (config) => {
|
|
5
5
|
coinConfig = config;
|
|
6
6
|
};
|
|
7
|
-
const getCoinConfig = (
|
|
7
|
+
const getCoinConfig = (currencyId) => {
|
|
8
8
|
if (!coinConfig) {
|
|
9
9
|
throw new MissingCoinConfig();
|
|
10
10
|
}
|
|
11
|
-
return coinConfig(
|
|
11
|
+
return coinConfig(currencyId);
|
|
12
12
|
};
|
|
13
13
|
return {
|
|
14
14
|
setCoinConfig,
|
package/lib-es/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AA0D5C,SAAS,eAAe;IACtB,IAAI,UAAqC,CAAA;IAEzC,MAAM,aAAa,GAAG,CAAC,MAAqB,EAAQ,EAAE;QACpD,UAAU,GAAG,MAAM,CAAA;IACrB,CAAC,CAAA;IAED,MAAM,aAAa,GAAG,CAAC,UAAmB,EAAK,EAAE;QAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAiB,EAAE,CAAA;QAC/B,CAAC;QAED,OAAO,UAAU,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC,CAAA;IAED,OAAO;QACL,aAAa;QACb,aAAa;KACd,CAAA;AACH,CAAC;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type SupportedOptions = {
|
|
2
|
+
minimumFractionDigits: number;
|
|
3
|
+
maximumFractionDigits: number;
|
|
4
|
+
useGrouping: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const toLocaleString: (n: BigNumber, localeInput?: string, options?: Partial<SupportedOptions>) => string;
|
|
7
|
+
//# sourceMappingURL=BigNumberToLocaleString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigNumberToLocaleString.d.ts","sourceRoot":"","sources":["../../src/currencies/BigNumberToLocaleString.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;AAiBD,eAAO,MAAM,cAAc,GACzB,GAAG,SAAS,EACZ,cAAc,MAAM,EACpB,UAAS,OAAO,CAAC,gBAAgB,CAAM,KACtC,MAwCF,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Forked from @ledgerhq/live-currency-format/src/BigNumberToLocaleString.ts
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { getSeparators } from './localeUtility';
|
|
4
|
+
const getFormatForLocale = (locale) => {
|
|
5
|
+
const { decimal, thousands } = getSeparators(locale);
|
|
6
|
+
const opts = {
|
|
7
|
+
decimalSeparator: '.',
|
|
8
|
+
groupSeparator: ',',
|
|
9
|
+
groupSize: 3,
|
|
10
|
+
secondaryGroupSize: 0,
|
|
11
|
+
fractionGroupSeparator: '\xA0', // non-breaking space
|
|
12
|
+
fractionGroupSize: 0,
|
|
13
|
+
};
|
|
14
|
+
if (typeof decimal === 'string')
|
|
15
|
+
opts.decimalSeparator = decimal;
|
|
16
|
+
if (typeof thousands === 'string')
|
|
17
|
+
opts.groupSeparator = thousands;
|
|
18
|
+
return opts;
|
|
19
|
+
};
|
|
20
|
+
export const toLocaleString = (n, localeInput, options = {}) => {
|
|
21
|
+
let locale = localeInput;
|
|
22
|
+
if (!locale)
|
|
23
|
+
locale = 'en';
|
|
24
|
+
const minimumFractionDigits = typeof options.minimumFractionDigits === 'number' ? options.minimumFractionDigits : 0;
|
|
25
|
+
const maximumFractionDigits = typeof options.maximumFractionDigits === 'number'
|
|
26
|
+
? options.maximumFractionDigits
|
|
27
|
+
: Math.max(minimumFractionDigits, 3);
|
|
28
|
+
const useGrouping = 'useGrouping' in options ? options.useGrouping : true;
|
|
29
|
+
const format = getFormatForLocale(locale);
|
|
30
|
+
if (!useGrouping) {
|
|
31
|
+
format.groupSeparator = '';
|
|
32
|
+
}
|
|
33
|
+
const BN = BigNumber.clone({
|
|
34
|
+
FORMAT: format,
|
|
35
|
+
});
|
|
36
|
+
const bn = new BN(n);
|
|
37
|
+
const maxDecimals = bn.toFormat(maximumFractionDigits, BigNumber.ROUND_FLOOR);
|
|
38
|
+
if (maximumFractionDigits !== minimumFractionDigits) {
|
|
39
|
+
const minDecimals = bn.toFormat(minimumFractionDigits, BigNumber.ROUND_FLOOR);
|
|
40
|
+
let i = maxDecimals.length;
|
|
41
|
+
while (i > minDecimals.length) {
|
|
42
|
+
if (maxDecimals[i - 1] !== '0') {
|
|
43
|
+
if (maxDecimals[i - 1] === format.decimalSeparator) {
|
|
44
|
+
i--;
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
i--;
|
|
49
|
+
}
|
|
50
|
+
return maxDecimals.slice(0, i);
|
|
51
|
+
}
|
|
52
|
+
return maxDecimals;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=BigNumberToLocaleString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigNumberToLocaleString.js","sourceRoot":"","sources":["../../src/currencies/BigNumberToLocaleString.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQ/C,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC5C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IACpD,MAAM,IAAI,GAAG;QACX,gBAAgB,EAAE,GAAG;QACrB,cAAc,EAAE,GAAG;QACnB,SAAS,EAAE,CAAC;QACZ,kBAAkB,EAAE,CAAC;QACrB,sBAAsB,EAAE,MAAM,EAAE,qBAAqB;QACrD,iBAAiB,EAAE,CAAC;KACrB,CAAA;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,IAAI,CA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,QAAQ,CAAC,qBAAqB,EAAE,SAAS,CAAC,WAAW,CAAC,CAAA;QAC7E,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,CAAA;QAE1B,OAAO,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;YAC9B,IAAI,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBAC/B,IAAI,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,gBAAgB,EAAE,CAAC;oBACnD,CAAC,EAAE,CAAA;gBACL,CAAC;gBACD,MAAK;YACP,CAAC;YACD,CAAC,EAAE,CAAA;QACL,CAAC;QAED,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Unit } from '../api/types';
|
|
2
|
+
declare const defaultFormatOptions: {
|
|
3
|
+
locale: string;
|
|
4
|
+
showCode: boolean;
|
|
5
|
+
alwaysShowSign: boolean;
|
|
6
|
+
showAllDigits: boolean;
|
|
7
|
+
disableRounding: boolean;
|
|
8
|
+
useGrouping: boolean;
|
|
9
|
+
subMagnitude: number;
|
|
10
|
+
discreet: boolean;
|
|
11
|
+
joinFragmentsSeparator: string;
|
|
12
|
+
dynamicSignificantDigits: number;
|
|
13
|
+
staticSignificantDigits: number;
|
|
14
|
+
};
|
|
15
|
+
export type formatCurrencyUnitOptions = Partial<typeof defaultFormatOptions>;
|
|
16
|
+
export type FormatterValue = {
|
|
17
|
+
integerPart: string;
|
|
18
|
+
decimalPart: string;
|
|
19
|
+
decimalSeparator: '.' | ',';
|
|
20
|
+
currencyText: string;
|
|
21
|
+
currencyPosition: 'start' | 'end';
|
|
22
|
+
};
|
|
23
|
+
export declare const formatCurrencyUnitFragment: (unit: Unit, value: BigNumber, options?: formatCurrencyUnitOptions) => FormatterValue;
|
|
24
|
+
export declare const formatCurrencyUnit: (unit: Unit, value: BigNumber, options?: formatCurrencyUnitOptions) => string;
|
|
25
|
+
export {};
|
|
2
26
|
//# sourceMappingURL=formatCurrencyUnit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatCurrencyUnit.d.ts","sourceRoot":"","sources":["../../src/currencies/formatCurrencyUnit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatCurrencyUnit.d.ts","sourceRoot":"","sources":["../../src/currencies/formatCurrencyUnit.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGxC,QAAA,MAAM,oBAAoB;;;;;;;;;;;;CAYzB,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAE5E,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,GAAG,GAAG,GAAG,CAAA;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,OAAO,GAAG,KAAK,CAAA;CAClC,CAAA;AA4GD,eAAO,MAAM,0BAA0B,GACrC,MAAM,IAAI,EACV,OAAO,SAAS,EAChB,UAAU,yBAAyB,KAClC,cAgCF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,MAAM,IAAI,EACV,OAAO,SAAS,EAChB,UAAU,yBAAyB,KAClC,MAoBF,CAAA"}
|
|
@@ -1,2 +1,128 @@
|
|
|
1
|
-
|
|
1
|
+
// Forked from @ledgerhq/live-currency-format/src/formatCurrencyUnit.ts
|
|
2
|
+
import { BigNumber } from 'bignumber.js';
|
|
3
|
+
import { getSeparators } from './localeUtility';
|
|
4
|
+
import { toLocaleString } from './BigNumberToLocaleString';
|
|
5
|
+
const nonBreakableSpace = '\u00A0';
|
|
6
|
+
const defaultFormatOptions = {
|
|
7
|
+
locale: 'en-EN',
|
|
8
|
+
showCode: false,
|
|
9
|
+
alwaysShowSign: false,
|
|
10
|
+
showAllDigits: false,
|
|
11
|
+
disableRounding: false,
|
|
12
|
+
useGrouping: true,
|
|
13
|
+
subMagnitude: 0,
|
|
14
|
+
discreet: false,
|
|
15
|
+
joinFragmentsSeparator: '',
|
|
16
|
+
dynamicSignificantDigits: 6,
|
|
17
|
+
staticSignificantDigits: 8,
|
|
18
|
+
};
|
|
19
|
+
const buildFormatState = (unit, value, _options) => {
|
|
20
|
+
const emptyState = () => ({
|
|
21
|
+
value: '',
|
|
22
|
+
sign: null,
|
|
23
|
+
code: null,
|
|
24
|
+
decimalSeparator: '.',
|
|
25
|
+
currencyPosition: unit.prefixCode ? 'start' : 'end',
|
|
26
|
+
});
|
|
27
|
+
if (!BigNumber.isBigNumber(value)) {
|
|
28
|
+
console.warn('formatCurrencyUnit called with value=', value);
|
|
29
|
+
return emptyState();
|
|
30
|
+
}
|
|
31
|
+
if (value.isNaN()) {
|
|
32
|
+
console.warn('formatCurrencyUnit called with NaN value!');
|
|
33
|
+
return emptyState();
|
|
34
|
+
}
|
|
35
|
+
if (!value.isFinite()) {
|
|
36
|
+
console.warn('formatCurrencyUnit called with infinite value=', value);
|
|
37
|
+
return emptyState();
|
|
38
|
+
}
|
|
39
|
+
const options = {};
|
|
40
|
+
if (_options) {
|
|
41
|
+
let k;
|
|
42
|
+
for (k in _options) {
|
|
43
|
+
const optionValue = _options[k];
|
|
44
|
+
if (optionValue !== undefined) {
|
|
45
|
+
options[k] = optionValue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const resolvedOptions = {
|
|
50
|
+
...defaultFormatOptions,
|
|
51
|
+
...unit,
|
|
52
|
+
...options,
|
|
53
|
+
};
|
|
54
|
+
const { showCode, alwaysShowSign, showAllDigits, locale, disableRounding, useGrouping, subMagnitude, discreet, dynamicSignificantDigits, staticSignificantDigits, } = resolvedOptions;
|
|
55
|
+
const { magnitude, code } = unit;
|
|
56
|
+
const floatValue = value.div(new BigNumber(10).pow(magnitude));
|
|
57
|
+
const floatValueAbs = floatValue.abs();
|
|
58
|
+
const minimumFractionDigits = showAllDigits ? magnitude : 0;
|
|
59
|
+
const maximumFractionDigits = disableRounding
|
|
60
|
+
? magnitude + subMagnitude
|
|
61
|
+
: Math.max(minimumFractionDigits, Math.max(0, Math.min(dynamicSignificantDigits - Math.ceil(Math.log(floatValueAbs.toNumber()) / Math.log(10)), magnitude + subMagnitude, staticSignificantDigits)));
|
|
62
|
+
const sign = alwaysShowSign || floatValue.isNegative() ? (floatValue.isNegative() ? '-' : '+') : null;
|
|
63
|
+
const formattedValue = discreet
|
|
64
|
+
? '***'
|
|
65
|
+
: toLocaleString(floatValueAbs, locale, {
|
|
66
|
+
maximumFractionDigits,
|
|
67
|
+
minimumFractionDigits,
|
|
68
|
+
useGrouping,
|
|
69
|
+
});
|
|
70
|
+
const separators = getSeparators(locale);
|
|
71
|
+
const decimalSeparator = separators.decimal === ',' ? ',' : '.';
|
|
72
|
+
const currencyPosition = unit.prefixCode ? 'start' : 'end';
|
|
73
|
+
return {
|
|
74
|
+
value: formattedValue,
|
|
75
|
+
sign,
|
|
76
|
+
code: showCode ? code : null,
|
|
77
|
+
decimalSeparator,
|
|
78
|
+
currencyPosition,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export const formatCurrencyUnitFragment = (unit, value, options) => {
|
|
82
|
+
const { value: formattedValue, sign, code, decimalSeparator, currencyPosition, } = buildFormatState(unit, value, options);
|
|
83
|
+
const hasDecimals = formattedValue.indexOf(decimalSeparator) !== -1;
|
|
84
|
+
const [integerPartRaw, decimalPartRaw] = hasDecimals
|
|
85
|
+
? formattedValue.split(decimalSeparator)
|
|
86
|
+
: [formattedValue, ''];
|
|
87
|
+
let integerPart = integerPartRaw;
|
|
88
|
+
const decimalPart = decimalPartRaw || '';
|
|
89
|
+
let currencyText = code || '';
|
|
90
|
+
if (sign) {
|
|
91
|
+
if (currencyPosition === 'start' && currencyText) {
|
|
92
|
+
currencyText = `${sign}${currencyText}`;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
integerPart = `${sign}${integerPart}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
integerPart,
|
|
100
|
+
decimalPart,
|
|
101
|
+
decimalSeparator,
|
|
102
|
+
currencyText,
|
|
103
|
+
currencyPosition,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export const formatCurrencyUnit = (unit, value, options) => {
|
|
107
|
+
const joinFragmentsSeparator = (options && options.joinFragmentsSeparator) || defaultFormatOptions.joinFragmentsSeparator;
|
|
108
|
+
const { value: formattedValue, sign, code } = buildFormatState(unit, value, options);
|
|
109
|
+
const parts = [];
|
|
110
|
+
if (unit.prefixCode) {
|
|
111
|
+
if (sign)
|
|
112
|
+
parts.push(sign);
|
|
113
|
+
if (code)
|
|
114
|
+
parts.push(code);
|
|
115
|
+
parts.push(formattedValue);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
if (sign)
|
|
119
|
+
parts.push(sign);
|
|
120
|
+
parts.push(formattedValue);
|
|
121
|
+
if (code) {
|
|
122
|
+
parts.push(nonBreakableSpace);
|
|
123
|
+
parts.push(code);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return parts.join(joinFragmentsSeparator);
|
|
127
|
+
};
|
|
2
128
|
//# sourceMappingURL=formatCurrencyUnit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatCurrencyUnit.js","sourceRoot":"","sources":["../../src/currencies/formatCurrencyUnit.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"formatCurrencyUnit.js","sourceRoot":"","sources":["../../src/currencies/formatCurrencyUnit.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,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,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1B,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC1B,IAAI,IAAI,EAAE,CAAC;YACT,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;YAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;AAC3C,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const prefixFormat: readonly ["sign", "code", "value"];
|
|
2
|
+
export declare const suffixFormat: readonly ["sign", "value", "separator", "code"];
|
|
3
|
+
export type GetSeparators = (locale: string) => {
|
|
4
|
+
decimal: string | null | undefined;
|
|
5
|
+
thousands: string | null | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const getSeparators: GetSeparators;
|
|
8
|
+
//# sourceMappingURL=localeUtility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeUtility.d.ts","sourceRoot":"","sources":["../../src/currencies/localeUtility.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,YAAY,oCAAqC,CAAA;AAC9D,eAAO,MAAM,YAAY,iDAAkD,CAAA;AAE3E,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK;IAC9C,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAClC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,aAoB1B,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Forked from @ledgerhq/live-currency-format/src/localeUtility.ts
|
|
2
|
+
const memoize = (fn) => {
|
|
3
|
+
const cache = {};
|
|
4
|
+
return ((arg) => {
|
|
5
|
+
if (!(arg in cache)) {
|
|
6
|
+
cache[arg] = fn(arg);
|
|
7
|
+
}
|
|
8
|
+
return cache[arg];
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const options = {
|
|
12
|
+
style: 'currency',
|
|
13
|
+
currency: 'USD',
|
|
14
|
+
};
|
|
15
|
+
const localeNotAvailable = (1.2).toLocaleString('en', options) !== '$1.20';
|
|
16
|
+
const getFallback = (locale) => staticFallback[Object.prototype.hasOwnProperty.call(staticFallback, locale) ? locale : 'en'];
|
|
17
|
+
const staticFallback = {
|
|
18
|
+
en: ['-$1.00', '10,000.2'],
|
|
19
|
+
es: ['-1,00 US$', '10.000,2'],
|
|
20
|
+
fr: ['-1,00 $US', '10 000,2'],
|
|
21
|
+
ja: ['-US$1.00', '10,000.2'],
|
|
22
|
+
ko: ['-US$1.00', '10,000.2'],
|
|
23
|
+
ru: ['-1,00 $', '10 000,2'],
|
|
24
|
+
zh: ['-US$1.00', '10,000.2'],
|
|
25
|
+
};
|
|
26
|
+
export const prefixFormat = ['sign', 'code', 'value'];
|
|
27
|
+
export const suffixFormat = ['sign', 'value', 'separator', 'code'];
|
|
28
|
+
export const getSeparators = memoize((locale) => {
|
|
29
|
+
const res = localeNotAvailable ? getFallback(locale)[1] : (10000.2).toLocaleString(locale);
|
|
30
|
+
let decimal;
|
|
31
|
+
let thousands;
|
|
32
|
+
for (let i = 0; i < res.length; i++) {
|
|
33
|
+
const c = res[i];
|
|
34
|
+
if (/[0-9]/.test(c))
|
|
35
|
+
continue;
|
|
36
|
+
if (!thousands) {
|
|
37
|
+
thousands = c;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
decimal = c;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
decimal,
|
|
45
|
+
thousands,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=localeUtility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeUtility.js","sourceRoot":"","sources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AM,EAAE,OAAO,CAAU,CAAA;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,CAAU,CAAA;AAO3E,MAAM,CAAC,MAAM,aAAa,GAAkB,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;IAC7D,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAC1F,IAAI,OAAO,CAAA;IACX,IAAI,SAAS,CAAA;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAChB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAAE,SAAQ;QAE7B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,CAAC,CAAA;QACf,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,CAAC,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,SAAS;KACV,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCurrencyUnit.d.ts","sourceRoot":"","sources":["../../src/currencies/parseCurrencyUnit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseCurrencyUnit.d.ts","sourceRoot":"","sources":["../../src/currencies/parseCurrencyUnit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGxC,eAAO,MAAM,iBAAiB,GAAI,MAAM,IAAI,EAAE,aAAa,MAAM,KAAG,SAKnE,CAAA"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { BigNumber } from 'bignumber.js';
|
|
2
|
+
export const parseCurrencyUnit = (unit, valueString) => {
|
|
3
|
+
const str = valueString.replace(/,/g, '.');
|
|
4
|
+
const value = new BigNumber(str);
|
|
5
|
+
if (value.isNaN())
|
|
6
|
+
return new BigNumber(0);
|
|
7
|
+
return value.times(new BigNumber(10).pow(unit.magnitude)).integerValue();
|
|
8
|
+
};
|
|
2
9
|
//# sourceMappingURL=parseCurrencyUnit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCurrencyUnit.js","sourceRoot":"","sources":["../../src/currencies/parseCurrencyUnit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseCurrencyUnit.js","sourceRoot":"","sources":["../../src/currencies/parseCurrencyUnit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAU,EAAE,WAAmB,EAAa,EAAE;IAC9E,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAC1C,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,KAAK,CAAC,KAAK,EAAE;QAAE,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,EAAE,CAAA;AAC1E,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-module-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Ledger framework for Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
},
|
|
52
52
|
"license": "Apache-2.0",
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@ledgerhq/errors": "6.31.0-nightly.20260317030141",
|
|
55
|
-
"@ledgerhq/live-env": "2.30.0-nightly.20260317030141",
|
|
56
|
-
"@ledgerhq/live-currency-format": "0.6.0-nightly.20260317030141",
|
|
57
|
-
"@ledgerhq/types-cryptoassets": "7.35.0-nightly.20260317030141",
|
|
58
54
|
"bignumber.js": "^9.1.2"
|
|
59
55
|
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@ledgerhq/errors": "^6.33.0",
|
|
58
|
+
"@ledgerhq/live-env": "^2.31.0"
|
|
59
|
+
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^24.0.0",
|
|
62
62
|
"@types/jest": "^30.0.0",
|
package/src/api/types.ts
CHANGED
|
@@ -485,6 +485,12 @@ export type AddressValidationCurrencyParameters = {
|
|
|
485
485
|
networkId: number
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
+
export type BalanceOptions = {
|
|
489
|
+
// Mandatory options: coin module must respect these requirements, or raise an error if unable to
|
|
490
|
+
/** Asset whitelist (if provided, only matching assets are included) */
|
|
491
|
+
includeAssets?: (asset: AssetInfo) => Promise<boolean>
|
|
492
|
+
}
|
|
493
|
+
|
|
488
494
|
export type AlpacaApi<
|
|
489
495
|
MemoType extends Memo = MemoNotSupported,
|
|
490
496
|
TxDataType extends TxData = TxDataNotSupported,
|
|
@@ -553,11 +559,12 @@ export type AlpacaApi<
|
|
|
553
559
|
* If account is not found, implementation must return an empty balance.
|
|
554
560
|
*
|
|
555
561
|
* @param address the account address
|
|
562
|
+
* @param options optional parameters to filter/restrict the returned balances (see {@link BalanceOptions})
|
|
556
563
|
* @returns an array of balances for all assets held by the address
|
|
557
564
|
* @see getStakes
|
|
558
565
|
* @see listOperations
|
|
559
566
|
*/
|
|
560
|
-
getBalance: (address: string) => Promise<Balance[]>
|
|
567
|
+
getBalance: (address: string, options?: BalanceOptions) => Promise<Balance[]>
|
|
561
568
|
|
|
562
569
|
/**
|
|
563
570
|
* List operations for an address/account.
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CryptoCurrency, CryptoCurrencyId } from '@ledgerhq/types-cryptoassets'
|
|
2
1
|
import { MissingCoinConfig } from './errors'
|
|
3
2
|
import type { FeatureConfig } from './features/types'
|
|
4
3
|
|
|
@@ -13,7 +12,7 @@ type ConfigStatus =
|
|
|
13
12
|
}
|
|
14
13
|
| {
|
|
15
14
|
type: 'migration'
|
|
16
|
-
chain:
|
|
15
|
+
chain: string
|
|
17
16
|
from: string
|
|
18
17
|
to: string
|
|
19
18
|
link: string
|
|
@@ -55,7 +54,7 @@ export type CurrencyConfig = {
|
|
|
55
54
|
[key: string]: unknown
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
export type CoinConfig<T extends CurrencyConfig> = (
|
|
57
|
+
export type CoinConfig<T extends CurrencyConfig> = (currencyId?: string) => T
|
|
59
58
|
|
|
60
59
|
function buildCoinConfig<T extends CurrencyConfig>() {
|
|
61
60
|
let coinConfig: CoinConfig<T> | undefined
|
|
@@ -64,12 +63,12 @@ function buildCoinConfig<T extends CurrencyConfig>() {
|
|
|
64
63
|
coinConfig = config
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
const getCoinConfig = (
|
|
66
|
+
const getCoinConfig = (currencyId?: string): T => {
|
|
68
67
|
if (!coinConfig) {
|
|
69
68
|
throw new MissingCoinConfig()
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
return coinConfig(
|
|
71
|
+
return coinConfig(currencyId)
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
return {
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Forked from @ledgerhq/live-currency-format/src/BigNumberToLocaleString.test.ts
|
|
2
|
+
import { BigNumber } from 'bignumber.js'
|
|
3
|
+
import { toLocaleString } from './BigNumberToLocaleString'
|
|
4
|
+
|
|
5
|
+
test('basic toLocaleString usage', () => {
|
|
6
|
+
expect(toLocaleString(new BigNumber(0))).toBe('0')
|
|
7
|
+
expect(toLocaleString(new BigNumber(8))).toBe('8')
|
|
8
|
+
expect(toLocaleString(new BigNumber(123))).toBe('123')
|
|
9
|
+
expect(toLocaleString(new BigNumber(0.001))).toBe('0.001')
|
|
10
|
+
expect(toLocaleString(new BigNumber(13.1))).toBe('13.1')
|
|
11
|
+
expect(toLocaleString(new BigNumber(123.01))).toBe('123.01')
|
|
12
|
+
expect(toLocaleString(new BigNumber(123.012))).toBe('123.012')
|
|
13
|
+
expect(toLocaleString(new BigNumber(1123))).toBe('1,123')
|
|
14
|
+
expect(toLocaleString(new BigNumber('9999999999999999'))).toBe('9,999,999,999,999,999')
|
|
15
|
+
expect(toLocaleString(new BigNumber('9999999999999.99'))).toBe('9,999,999,999,999.99')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('toLocaleString to default maximumFractionDigits to 3', () => {
|
|
19
|
+
expect(toLocaleString(new BigNumber(4.44444))).toBe('4.444')
|
|
20
|
+
expect(toLocaleString(new BigNumber(444444.444444444))).toBe('444,444.444')
|
|
21
|
+
expect(toLocaleString(new BigNumber(0.444444444))).toBe('0.444')
|
|
22
|
+
expect(toLocaleString(new BigNumber(9.99999))).toBe('9.999')
|
|
23
|
+
expect(toLocaleString(new BigNumber(111111.111111111))).toBe('111,111.111')
|
|
24
|
+
expect(toLocaleString(new BigNumber(0.999999999))).toBe('0.999')
|
|
25
|
+
expect(toLocaleString(new BigNumber(9.5))).toBe('9.5')
|
|
26
|
+
expect(toLocaleString(new BigNumber(9.9))).toBe('9.9')
|
|
27
|
+
expect(toLocaleString(new BigNumber(99.6))).toBe('99.6')
|
|
28
|
+
expect(toLocaleString(new BigNumber(99.8))).toBe('99.8')
|
|
29
|
+
expect(toLocaleString(new BigNumber(999.7))).toBe('999.7')
|
|
30
|
+
expect(toLocaleString(new BigNumber(999.9))).toBe('999.9')
|
|
31
|
+
expect(toLocaleString(new BigNumber(999999.7))).toBe('999,999.7')
|
|
32
|
+
expect(toLocaleString(new BigNumber(999999.9))).toBe('999,999.9')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('toLocaleString minimumFractionDigits', () => {
|
|
36
|
+
expect(
|
|
37
|
+
toLocaleString(new BigNumber(0), 'en', {
|
|
38
|
+
minimumFractionDigits: 1,
|
|
39
|
+
})
|
|
40
|
+
).toBe('0.0')
|
|
41
|
+
expect(
|
|
42
|
+
toLocaleString(new BigNumber(8), 'en', {
|
|
43
|
+
minimumFractionDigits: 1,
|
|
44
|
+
})
|
|
45
|
+
).toBe('8.0')
|
|
46
|
+
expect(
|
|
47
|
+
toLocaleString(new BigNumber(123), 'en', {
|
|
48
|
+
minimumFractionDigits: 1,
|
|
49
|
+
})
|
|
50
|
+
).toBe('123.0')
|
|
51
|
+
expect(
|
|
52
|
+
toLocaleString(new BigNumber(0.001), 'en', {
|
|
53
|
+
minimumFractionDigits: 1,
|
|
54
|
+
})
|
|
55
|
+
).toBe('0.001')
|
|
56
|
+
expect(
|
|
57
|
+
toLocaleString(new BigNumber(9.5), 'en', {
|
|
58
|
+
minimumFractionDigits: 1,
|
|
59
|
+
})
|
|
60
|
+
).toBe('9.5')
|
|
61
|
+
expect(
|
|
62
|
+
toLocaleString(new BigNumber(9.6), 'en', {
|
|
63
|
+
minimumFractionDigits: 2,
|
|
64
|
+
})
|
|
65
|
+
).toBe('9.60')
|
|
66
|
+
expect(
|
|
67
|
+
toLocaleString(new BigNumber(13.1), 'en', {
|
|
68
|
+
minimumFractionDigits: 3,
|
|
69
|
+
})
|
|
70
|
+
).toBe('13.100')
|
|
71
|
+
expect(
|
|
72
|
+
toLocaleString(new BigNumber(123.01), 'en', {
|
|
73
|
+
minimumFractionDigits: 5,
|
|
74
|
+
})
|
|
75
|
+
).toBe('123.01000')
|
|
76
|
+
expect(
|
|
77
|
+
toLocaleString(new BigNumber(123.012), 'en', {
|
|
78
|
+
minimumFractionDigits: 10,
|
|
79
|
+
})
|
|
80
|
+
).toBe('123.0120000000')
|
|
81
|
+
expect(
|
|
82
|
+
toLocaleString(new BigNumber(1123), 'en', {
|
|
83
|
+
minimumFractionDigits: 1,
|
|
84
|
+
})
|
|
85
|
+
).toBe('1,123.0')
|
|
86
|
+
expect(
|
|
87
|
+
toLocaleString(new BigNumber('9999999999999999'), 'en', {
|
|
88
|
+
minimumFractionDigits: 1,
|
|
89
|
+
})
|
|
90
|
+
).toBe('9,999,999,999,999,999.0')
|
|
91
|
+
expect(
|
|
92
|
+
toLocaleString(new BigNumber('9999999999999.999'), 'en', {
|
|
93
|
+
minimumFractionDigits: 5,
|
|
94
|
+
})
|
|
95
|
+
).toBe('9,999,999,999,999.99900')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('toLocaleString minimumFractionDigits and maximumFractionDigits', () => {
|
|
99
|
+
expect(
|
|
100
|
+
toLocaleString(new BigNumber(1), 'en', {
|
|
101
|
+
minimumFractionDigits: 1,
|
|
102
|
+
maximumFractionDigits: 5,
|
|
103
|
+
})
|
|
104
|
+
).toBe('1.0')
|
|
105
|
+
expect(
|
|
106
|
+
toLocaleString(new BigNumber(1.003), 'en', {
|
|
107
|
+
minimumFractionDigits: 1,
|
|
108
|
+
maximumFractionDigits: 5,
|
|
109
|
+
})
|
|
110
|
+
).toBe('1.003')
|
|
111
|
+
expect(
|
|
112
|
+
toLocaleString(new BigNumber(1.000003), 'en', {
|
|
113
|
+
minimumFractionDigits: 1,
|
|
114
|
+
maximumFractionDigits: 5,
|
|
115
|
+
})
|
|
116
|
+
).toBe('1.0')
|
|
117
|
+
expect(
|
|
118
|
+
toLocaleString(new BigNumber(1.333333333333), 'en', {
|
|
119
|
+
minimumFractionDigits: 1,
|
|
120
|
+
maximumFractionDigits: 5,
|
|
121
|
+
})
|
|
122
|
+
).toBe('1.33333')
|
|
123
|
+
expect(
|
|
124
|
+
toLocaleString(new BigNumber(0), 'en', {
|
|
125
|
+
minimumFractionDigits: 1,
|
|
126
|
+
maximumFractionDigits: 5,
|
|
127
|
+
})
|
|
128
|
+
).toBe('0.0')
|
|
129
|
+
expect(
|
|
130
|
+
toLocaleString(new BigNumber(0.003), 'en', {
|
|
131
|
+
minimumFractionDigits: 1,
|
|
132
|
+
maximumFractionDigits: 5,
|
|
133
|
+
})
|
|
134
|
+
).toBe('0.003')
|
|
135
|
+
expect(
|
|
136
|
+
toLocaleString(new BigNumber(0.000003), 'en', {
|
|
137
|
+
minimumFractionDigits: 1,
|
|
138
|
+
maximumFractionDigits: 5,
|
|
139
|
+
})
|
|
140
|
+
).toBe('0.0')
|
|
141
|
+
expect(
|
|
142
|
+
toLocaleString(new BigNumber(9.7), 'en', {
|
|
143
|
+
minimumFractionDigits: 1,
|
|
144
|
+
maximumFractionDigits: 1,
|
|
145
|
+
})
|
|
146
|
+
).toBe('9.7')
|
|
147
|
+
expect(
|
|
148
|
+
toLocaleString(new BigNumber('4.4444444444444444444411111111111111'), 'en', {
|
|
149
|
+
maximumFractionDigits: 20,
|
|
150
|
+
})
|
|
151
|
+
).toBe('4.44444444444444444444')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('toLocaleString with different locales', () => {
|
|
155
|
+
const resultEn = toLocaleString(new BigNumber('1234.56'), 'en')
|
|
156
|
+
expect(resultEn).toBe('1,234.56')
|
|
157
|
+
const resultFr = toLocaleString(new BigNumber('1234.56'), 'fr')
|
|
158
|
+
expect(resultFr).toBeDefined()
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('toLocaleString handles separator types', () => {
|
|
162
|
+
const result = toLocaleString(new BigNumber('1234.56'), 'en')
|
|
163
|
+
expect(result).toBe('1,234.56')
|
|
164
|
+
})
|