@reown/appkit-common-react-native 0.0.0-feat-onramp-20250401173834 → 0.0.0-feat-onramp-20250401190352
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/lib/commonjs/utils/ConstantsUtil.js +1 -1
- package/lib/commonjs/utils/NumberUtil.js +13 -48
- package/lib/commonjs/utils/NumberUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +1 -1
- package/lib/module/utils/NumberUtil.js +13 -48
- package/lib/module/utils/NumberUtil.js.map +1 -1
- package/lib/typescript/utils/NumberUtil.d.ts +0 -5
- package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/utils/ConstantsUtil.ts +1 -1
- package/src/utils/NumberUtil.ts +14 -53
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ConstantsUtil = void 0;
|
|
7
7
|
const ConstantsUtil = exports.ConstantsUtil = {
|
|
8
|
-
VERSION: '0.0.0-feat-onramp-
|
|
8
|
+
VERSION: '0.0.0-feat-onramp-20250401190352',
|
|
9
9
|
EIP155: 'eip155',
|
|
10
10
|
ADD_CHAIN_METHOD: 'wallet_addEthereumChain',
|
|
11
11
|
WC_NAME_SUFFIX: '.reown.id',
|
|
@@ -43,29 +43,19 @@ const NumberUtil = exports.NumberUtil = {
|
|
|
43
43
|
* @returns
|
|
44
44
|
*/
|
|
45
45
|
formatNumberToLocalString(value, decimals = 2) {
|
|
46
|
-
const options = {
|
|
47
|
-
maximumFractionDigits: decimals
|
|
48
|
-
// Omit minimumFractionDigits to remove trailing zeros
|
|
49
|
-
};
|
|
50
|
-
|
|
51
46
|
if (value === undefined) {
|
|
52
|
-
|
|
53
|
-
return 0 .toLocaleString(undefined, options);
|
|
54
|
-
}
|
|
55
|
-
let numberValue;
|
|
56
|
-
if (typeof value === 'string') {
|
|
57
|
-
// Attempt to parse the string, handling potential locale-specific formats might be complex here,
|
|
58
|
-
// assuming parseFloat works for common cases after removing grouping separators might be needed if issues arise.
|
|
59
|
-
// For now, stick to parseFloat as it was.
|
|
60
|
-
numberValue = parseFloat(value);
|
|
61
|
-
} else {
|
|
62
|
-
numberValue = value;
|
|
47
|
+
return '0.00';
|
|
63
48
|
}
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
if (typeof value === 'number') {
|
|
50
|
+
return value.toLocaleString('en-US', {
|
|
51
|
+
maximumFractionDigits: decimals,
|
|
52
|
+
minimumFractionDigits: decimals
|
|
53
|
+
});
|
|
67
54
|
}
|
|
68
|
-
return
|
|
55
|
+
return parseFloat(value).toLocaleString('en-US', {
|
|
56
|
+
maximumFractionDigits: decimals,
|
|
57
|
+
minimumFractionDigits: decimals
|
|
58
|
+
});
|
|
69
59
|
},
|
|
70
60
|
/**
|
|
71
61
|
* Parse a formatted local string back to a number
|
|
@@ -73,37 +63,12 @@ const NumberUtil = exports.NumberUtil = {
|
|
|
73
63
|
* @returns
|
|
74
64
|
*/
|
|
75
65
|
parseLocalStringToNumber(value) {
|
|
76
|
-
if (value === undefined
|
|
66
|
+
if (value === undefined) {
|
|
77
67
|
return 0;
|
|
78
68
|
}
|
|
79
|
-
const decimalSeparator = this.getLocaleDecimalSeparator();
|
|
80
|
-
let processedValue = value;
|
|
81
|
-
if (decimalSeparator === ',') {
|
|
82
|
-
// If locale uses COMMA for decimal:
|
|
83
|
-
// 1. Remove all period characters (thousand separators)
|
|
84
|
-
processedValue = processedValue.replace(/\./g, '');
|
|
85
|
-
// 2. Replace the comma decimal separator with a period
|
|
86
|
-
processedValue = processedValue.replace(/,/g, '.');
|
|
87
|
-
} else {
|
|
88
|
-
// If locale uses PERIOD for decimal (or anything else):
|
|
89
|
-
// 1. Remove all comma characters (thousand separators)
|
|
90
|
-
processedValue = processedValue.replace(/,/g, '');
|
|
91
|
-
// 2. Period decimal separator is already correct
|
|
92
|
-
}
|
|
93
69
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Return the parsed number, or 0 if parsing failed (NaN)
|
|
98
|
-
return isNaN(result) ? 0 : result;
|
|
99
|
-
},
|
|
100
|
-
/**
|
|
101
|
-
* Determines the decimal separator based on the user's locale.
|
|
102
|
-
* @returns The locale's decimal separator (e.g., '.' or ',').
|
|
103
|
-
*/
|
|
104
|
-
getLocaleDecimalSeparator() {
|
|
105
|
-
// Format a known decimal number and extract the second character
|
|
106
|
-
return 1.1.toLocaleString().substring(1, 2);
|
|
70
|
+
// Remove any commas used as thousand separators and parse the float
|
|
71
|
+
return parseFloat(value.replace(/,/gu, ''));
|
|
107
72
|
}
|
|
108
73
|
};
|
|
109
74
|
//# sourceMappingURL=NumberUtil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BigNumber","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","NumberUtil","exports","bigNumber","value","replace","multiply","b","undefined","aBigNumber","bBigNumber","multipliedBy","roundNumber","number","threshold","fixed","roundedNumber","toString","length","Number","toFixed","nextMultipleOfTen","amount","Math","max","ceil","formatNumberToLocalString","decimals","
|
|
1
|
+
{"version":3,"names":["BigNumber","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","NumberUtil","exports","bigNumber","value","replace","multiply","b","undefined","aBigNumber","bBigNumber","multipliedBy","roundNumber","number","threshold","fixed","roundedNumber","toString","length","Number","toFixed","nextMultipleOfTen","amount","Math","max","ceil","formatNumberToLocalString","decimals","toLocaleString","maximumFractionDigits","minimumFractionDigits","parseFloat","parseLocalStringToNumber"],"sourceRoot":"../../../src","sources":["utils/NumberUtil.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,uBAAA,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ACA;AACA;EACEI,yBAAyBA,CAACtB,KAAkC,EAAEuB,QAAQ,GAAG,CAAC,EAAE;IAC1E,IAAIvB,KAAK,KAAKI,SAAS,EAAE;MACvB,OAAO,MAAM;IACf;IAEA,IAAI,OAAOJ,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAOA,KAAK,CAACwB,cAAc,CAAC,OAAO,EAAE;QACnCC,qBAAqB,EAAEF,QAAQ;QAC/BG,qBAAqB,EAAEH;MACzB,CAAC,CAAC;IACJ;IAEA,OAAOI,UAAU,CAAC3B,KAAK,CAAC,CAACwB,cAAc,CAAC,OAAO,EAAE;MAC/CC,qBAAqB,EAAEF,QAAQ;MAC/BG,qBAAqB,EAAEH;IACzB,CAAC,CAAC;EACJ,CAAC;EACD;AACF;AACA;AACA;AACA;EACEK,wBAAwBA,CAAC5B,KAAyB,EAAE;IAClD,IAAIA,KAAK,KAAKI,SAAS,EAAE;MACvB,OAAO,CAAC;IACV;;IAEA;IACA,OAAOuB,UAAU,CAAC3B,KAAK,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;EAC7C;AACF,CAAC"}
|
|
@@ -35,29 +35,19 @@ export const NumberUtil = {
|
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
37
|
formatNumberToLocalString(value, decimals = 2) {
|
|
38
|
-
const options = {
|
|
39
|
-
maximumFractionDigits: decimals
|
|
40
|
-
// Omit minimumFractionDigits to remove trailing zeros
|
|
41
|
-
};
|
|
42
|
-
|
|
43
38
|
if (value === undefined) {
|
|
44
|
-
|
|
45
|
-
return 0 .toLocaleString(undefined, options);
|
|
46
|
-
}
|
|
47
|
-
let numberValue;
|
|
48
|
-
if (typeof value === 'string') {
|
|
49
|
-
// Attempt to parse the string, handling potential locale-specific formats might be complex here,
|
|
50
|
-
// assuming parseFloat works for common cases after removing grouping separators might be needed if issues arise.
|
|
51
|
-
// For now, stick to parseFloat as it was.
|
|
52
|
-
numberValue = parseFloat(value);
|
|
53
|
-
} else {
|
|
54
|
-
numberValue = value;
|
|
39
|
+
return '0.00';
|
|
55
40
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
return value.toLocaleString('en-US', {
|
|
43
|
+
maximumFractionDigits: decimals,
|
|
44
|
+
minimumFractionDigits: decimals
|
|
45
|
+
});
|
|
59
46
|
}
|
|
60
|
-
return
|
|
47
|
+
return parseFloat(value).toLocaleString('en-US', {
|
|
48
|
+
maximumFractionDigits: decimals,
|
|
49
|
+
minimumFractionDigits: decimals
|
|
50
|
+
});
|
|
61
51
|
},
|
|
62
52
|
/**
|
|
63
53
|
* Parse a formatted local string back to a number
|
|
@@ -65,37 +55,12 @@ export const NumberUtil = {
|
|
|
65
55
|
* @returns
|
|
66
56
|
*/
|
|
67
57
|
parseLocalStringToNumber(value) {
|
|
68
|
-
if (value === undefined
|
|
58
|
+
if (value === undefined) {
|
|
69
59
|
return 0;
|
|
70
60
|
}
|
|
71
|
-
const decimalSeparator = this.getLocaleDecimalSeparator();
|
|
72
|
-
let processedValue = value;
|
|
73
|
-
if (decimalSeparator === ',') {
|
|
74
|
-
// If locale uses COMMA for decimal:
|
|
75
|
-
// 1. Remove all period characters (thousand separators)
|
|
76
|
-
processedValue = processedValue.replace(/\./g, '');
|
|
77
|
-
// 2. Replace the comma decimal separator with a period
|
|
78
|
-
processedValue = processedValue.replace(/,/g, '.');
|
|
79
|
-
} else {
|
|
80
|
-
// If locale uses PERIOD for decimal (or anything else):
|
|
81
|
-
// 1. Remove all comma characters (thousand separators)
|
|
82
|
-
processedValue = processedValue.replace(/,/g, '');
|
|
83
|
-
// 2. Period decimal separator is already correct
|
|
84
|
-
}
|
|
85
61
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Return the parsed number, or 0 if parsing failed (NaN)
|
|
90
|
-
return isNaN(result) ? 0 : result;
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* Determines the decimal separator based on the user's locale.
|
|
94
|
-
* @returns The locale's decimal separator (e.g., '.' or ',').
|
|
95
|
-
*/
|
|
96
|
-
getLocaleDecimalSeparator() {
|
|
97
|
-
// Format a known decimal number and extract the second character
|
|
98
|
-
return 1.1.toLocaleString().substring(1, 2);
|
|
62
|
+
// Remove any commas used as thousand separators and parse the float
|
|
63
|
+
return parseFloat(value.replace(/,/gu, ''));
|
|
99
64
|
}
|
|
100
65
|
};
|
|
101
66
|
//# sourceMappingURL=NumberUtil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BigNumber","NumberUtil","bigNumber","value","replace","multiply","a","b","undefined","aBigNumber","bBigNumber","multipliedBy","roundNumber","number","threshold","fixed","roundedNumber","toString","length","Number","toFixed","nextMultipleOfTen","amount","Math","max","ceil","formatNumberToLocalString","decimals","
|
|
1
|
+
{"version":3,"names":["BigNumber","NumberUtil","bigNumber","value","replace","multiply","a","b","undefined","aBigNumber","bBigNumber","multipliedBy","roundNumber","number","threshold","fixed","roundedNumber","toString","length","Number","toFixed","nextMultipleOfTen","amount","Math","max","ceil","formatNumberToLocalString","decimals","toLocaleString","maximumFractionDigits","minimumFractionDigits","parseFloat","parseLocalStringToNumber"],"sourceRoot":"../../../src","sources":["utils/NumberUtil.ts"],"mappings":"AAAA,OAAO,KAAKA,SAAS,MAAM,cAAc;AAEzC,OAAO,MAAMC,UAAU,GAAG;EACxBC,SAASA,CAACC,KAAgC,EAAE;IAC1C,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAO,IAAIH,SAAS,CAACA,SAAS,CAACG,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACzD;IAEA,OAAO,IAAIJ,SAAS,CAACA,SAAS,CAACG,KAAK,CAAC;EACvC,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEE,QAAQA,CAACC,CAAwC,EAAEC,CAAwC,EAAE;IAC3F,IAAID,CAAC,KAAK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B,EAAEH;MACzB,CAAC,CAAC;IACJ;IAEA,OAAOI,UAAU,CAAC5B,KAAK,CAAC,CAACyB,cAAc,CAAC,OAAO,EAAE;MAC/CC,qBAAqB,EAAEF,QAAQ;MAC/BG,qBAAqB,EAAEH;IACzB,CAAC,CAAC;EACJ,CAAC;EACD;AACF;AACA;AACA;AACA;EACEK,wBAAwBA,CAAC7B,KAAyB,EAAE;IAClD,IAAIA,KAAK,KAAKK,SAAS,EAAE;MACvB,OAAO,CAAC;IACV;;IAEA;IACA,OAAOuB,UAAU,CAAC5B,KAAK,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;EAC7C;AACF,CAAC"}
|
|
@@ -23,10 +23,5 @@ export declare const NumberUtil: {
|
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
25
|
parseLocalStringToNumber(value: string | undefined): number;
|
|
26
|
-
/**
|
|
27
|
-
* Determines the decimal separator based on the user's locale.
|
|
28
|
-
* @returns The locale's decimal separator (e.g., '.' or ',').
|
|
29
|
-
*/
|
|
30
|
-
getLocaleDecimalSeparator(): string;
|
|
31
26
|
};
|
|
32
27
|
//# sourceMappingURL=NumberUtil.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/NumberUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,eAAO,MAAM,UAAU;qBACJ,mBAAmB,CAAC,KAAK;IAQ1C;;;;;OAKG;gBACS,mBAAmB,CAAC,KAAK,GAAG,SAAS,KAAK,mBAAmB,CAAC,KAAK,GAAG,SAAS;wBAWvE,MAAM,aAAa,MAAM,SAAS,MAAM;+BAOjC,MAAM;IAMjC;;;;;OAKG;qCAC8B,MAAM,GAAG,MAAM,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"NumberUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/NumberUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,eAAO,MAAM,UAAU;qBACJ,mBAAmB,CAAC,KAAK;IAQ1C;;;;;OAKG;gBACS,mBAAmB,CAAC,KAAK,GAAG,SAAS,KAAK,mBAAmB,CAAC,KAAK,GAAG,SAAS;wBAWvE,MAAM,aAAa,MAAM,SAAS,MAAM;+BAOjC,MAAM;IAMjC;;;;;OAKG;qCAC8B,MAAM,GAAG,MAAM,GAAG,SAAS;IAiB5D;;;;OAIG;oCAC6B,MAAM,GAAG,SAAS;CAQnD,CAAC"}
|
package/package.json
CHANGED
package/src/utils/NumberUtil.ts
CHANGED
|
@@ -46,72 +46,33 @@ export const NumberUtil = {
|
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
48
|
formatNumberToLocalString(value: string | number | undefined, decimals = 2) {
|
|
49
|
-
const options: Intl.NumberFormatOptions = {
|
|
50
|
-
maximumFractionDigits: decimals
|
|
51
|
-
// Omit minimumFractionDigits to remove trailing zeros
|
|
52
|
-
};
|
|
53
|
-
|
|
54
49
|
if (value === undefined) {
|
|
55
|
-
|
|
56
|
-
return (0).toLocaleString(undefined, options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let numberValue: number;
|
|
60
|
-
if (typeof value === 'string') {
|
|
61
|
-
// Attempt to parse the string, handling potential locale-specific formats might be complex here,
|
|
62
|
-
// assuming parseFloat works for common cases after removing grouping separators might be needed if issues arise.
|
|
63
|
-
// For now, stick to parseFloat as it was.
|
|
64
|
-
numberValue = parseFloat(value);
|
|
65
|
-
} else {
|
|
66
|
-
numberValue = value;
|
|
50
|
+
return '0.00';
|
|
67
51
|
}
|
|
68
52
|
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
if (typeof value === 'number') {
|
|
54
|
+
return value.toLocaleString('en-US', {
|
|
55
|
+
maximumFractionDigits: decimals,
|
|
56
|
+
minimumFractionDigits: decimals
|
|
57
|
+
});
|
|
72
58
|
}
|
|
73
59
|
|
|
74
|
-
return
|
|
60
|
+
return parseFloat(value).toLocaleString('en-US', {
|
|
61
|
+
maximumFractionDigits: decimals,
|
|
62
|
+
minimumFractionDigits: decimals
|
|
63
|
+
});
|
|
75
64
|
},
|
|
76
65
|
/**
|
|
77
66
|
* Parse a formatted local string back to a number
|
|
78
67
|
* @param value - The formatted string to parse
|
|
79
68
|
* @returns
|
|
80
69
|
*/
|
|
81
|
-
parseLocalStringToNumber(value: string | undefined)
|
|
82
|
-
if (value === undefined
|
|
70
|
+
parseLocalStringToNumber(value: string | undefined) {
|
|
71
|
+
if (value === undefined) {
|
|
83
72
|
return 0;
|
|
84
73
|
}
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (decimalSeparator === ',') {
|
|
90
|
-
// If locale uses COMMA for decimal:
|
|
91
|
-
// 1. Remove all period characters (thousand separators)
|
|
92
|
-
processedValue = processedValue.replace(/\./g, '');
|
|
93
|
-
// 2. Replace the comma decimal separator with a period
|
|
94
|
-
processedValue = processedValue.replace(/,/g, '.');
|
|
95
|
-
} else {
|
|
96
|
-
// If locale uses PERIOD for decimal (or anything else):
|
|
97
|
-
// 1. Remove all comma characters (thousand separators)
|
|
98
|
-
processedValue = processedValue.replace(/,/g, '');
|
|
99
|
-
// 2. Period decimal separator is already correct
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Parse the cleaned string which should now use '.' as decimal and no thousand separators
|
|
103
|
-
const result = parseFloat(processedValue);
|
|
104
|
-
|
|
105
|
-
// Return the parsed number, or 0 if parsing failed (NaN)
|
|
106
|
-
return isNaN(result) ? 0 : result;
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Determines the decimal separator based on the user's locale.
|
|
111
|
-
* @returns The locale's decimal separator (e.g., '.' or ',').
|
|
112
|
-
*/
|
|
113
|
-
getLocaleDecimalSeparator(): string {
|
|
114
|
-
// Format a known decimal number and extract the second character
|
|
115
|
-
return (1.1).toLocaleString().substring(1, 2);
|
|
75
|
+
// Remove any commas used as thousand separators and parse the float
|
|
76
|
+
return parseFloat(value.replace(/,/gu, ''));
|
|
116
77
|
}
|
|
117
78
|
};
|