@subwallet/extension-base 1.1.59-0 → 1.1.60-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.
Files changed (43) hide show
  1. package/background/KoniTypes.d.ts +18 -1
  2. package/cjs/constants/staking.js +2 -1
  3. package/cjs/constants/storage.js +4 -2
  4. package/cjs/koni/api/coingecko.js +58 -15
  5. package/cjs/koni/api/nft/config.js +26 -22
  6. package/cjs/koni/background/handlers/Extension.js +130 -122
  7. package/cjs/packageInfo.js +1 -1
  8. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +7 -1
  9. package/cjs/services/chain-service/index.js +6 -1
  10. package/cjs/services/chain-service/utils/index.js +34 -14
  11. package/cjs/services/price-service/coingecko.js +54 -35
  12. package/cjs/services/price-service/index.js +83 -12
  13. package/cjs/services/setting-service/constants.js +4 -1
  14. package/cjs/services/storage-service/DatabaseService.js +2 -3
  15. package/cjs/utils/number.js +84 -1
  16. package/cjs/utils/staticData/index.js +6 -1
  17. package/constants/staking.js +2 -1
  18. package/constants/storage.d.ts +1 -0
  19. package/constants/storage.js +2 -1
  20. package/koni/api/coingecko.d.ts +2 -2
  21. package/koni/api/coingecko.js +58 -15
  22. package/koni/api/nft/config.js +27 -21
  23. package/koni/background/handlers/Extension.d.ts +1 -0
  24. package/koni/background/handlers/Extension.js +7 -0
  25. package/package.json +7 -6
  26. package/packageInfo.js +1 -1
  27. package/services/balance-service/helpers/subscribe/substrate/index.js +8 -2
  28. package/services/chain-service/index.js +6 -1
  29. package/services/chain-service/utils/index.d.ts +13 -0
  30. package/services/chain-service/utils/index.js +32 -14
  31. package/services/price-service/coingecko.d.ts +3 -2
  32. package/services/price-service/coingecko.js +50 -32
  33. package/services/price-service/index.d.ts +7 -2
  34. package/services/price-service/index.js +85 -15
  35. package/services/setting-service/constants.d.ts +1 -0
  36. package/services/setting-service/constants.js +2 -0
  37. package/services/storage-service/DatabaseService.d.ts +1 -1
  38. package/services/storage-service/DatabaseService.js +2 -3
  39. package/utils/number.d.ts +1 -0
  40. package/utils/number.js +82 -0
  41. package/utils/staticData/currencySymbol.json +11 -0
  42. package/utils/staticData/index.d.ts +3 -0
  43. package/utils/staticData/index.js +4 -0
package/utils/number.js CHANGED
@@ -90,6 +90,88 @@ export const balanceFormatter = (input, metadata) => {
90
90
  }
91
91
  return int;
92
92
  };
93
+ const intToLocaleString = (str, separator) => str.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
94
+ const getNumberSeparators = () => {
95
+ // default
96
+ const res = {
97
+ decimal: '.',
98
+ thousand: ''
99
+ };
100
+
101
+ // convert a number formatted according to locale
102
+ const str = parseFloat('1234.56').toLocaleString();
103
+
104
+ // if the resulting number does not contain previous number
105
+ // (i.e. in some Arabic formats), return defaults
106
+ if (!str.match('1')) {
107
+ return res;
108
+ }
109
+
110
+ // get decimal and thousand separators
111
+ res.decimal = str.replace(/.*4(.*)5.*/, '$1');
112
+ res.thousand = str.replace(/.*1(.*)2.*/, '$1');
113
+
114
+ // return results
115
+ return res;
116
+ };
117
+ export const balanceNoPrefixFormater = (input, metadata) => {
118
+ const [int, decimal] = input.split('.');
119
+ const {
120
+ thousand: thousandSeparator
121
+ } = getNumberSeparators();
122
+ const absGteOne = new BigNumber(input).abs().gte(1);
123
+ const minNumberFormat = (metadata === null || metadata === void 0 ? void 0 : metadata.minNumberFormat) || 2;
124
+ const maxNumberFormat = (metadata === null || metadata === void 0 ? void 0 : metadata.maxNumberFormat) || 6;
125
+ let _decimal = '';
126
+ if (absGteOne) {
127
+ // Get only minNumberFormat number at decimal
128
+ if (decimal.length <= minNumberFormat) {
129
+ _decimal = decimal;
130
+ } else {
131
+ _decimal = decimal.slice(0, minNumberFormat);
132
+ }
133
+
134
+ // Clear zero number for decimal
135
+ _decimal = clearZero(_decimal);
136
+ } else {
137
+ // Index of cursor
138
+ let index = 0;
139
+
140
+ // Count of not zero number in decimal
141
+ let current = 0;
142
+
143
+ // Find a not zero number in decimal
144
+ let metNotZero = false;
145
+
146
+ // Get at least minNumberFormat number not 0 from index 0
147
+ // If count of 0 number at prefix greater or equal maxNumberFormat should stop and return 0
148
+
149
+ // current === minNumberFormat: get enough number
150
+ // index === decimal.length: end of decimal
151
+ // index === maxNumberFormat: reach limit of 0 number at prefix
152
+ if (decimal) {
153
+ while (current < minNumberFormat && index < decimal.length && (index < maxNumberFormat || metNotZero)) {
154
+ const _char = decimal[index];
155
+ _decimal += _char;
156
+ index++;
157
+ if (_char !== '0') {
158
+ metNotZero = true;
159
+ }
160
+ if (metNotZero) {
161
+ current++;
162
+ }
163
+ }
164
+
165
+ // Clear zero number for decimal
166
+ _decimal = clearZero(_decimal);
167
+ }
168
+ }
169
+ const int_ = intToLocaleString(int, thousandSeparator);
170
+ if (_decimal) {
171
+ return `${int_}.${_decimal}`;
172
+ }
173
+ return int_;
174
+ };
93
175
  export const PREDEFINED_FORMATTER = {
94
176
  balance: balanceFormatter
95
177
  };
@@ -0,0 +1,11 @@
1
+ {
2
+ "USD": {"label": "United States Dollar", "symbol": "USD", "isPrefix": false},
3
+ "BRL": {"label": "Brazilian Real", "symbol": "BRL", "isPrefix": false},
4
+ "CNY": {"label": "Chinese Yuan", "symbol": "CNY", "isPrefix": false},
5
+ "EUR": {"label": "Euro", "symbol": "EUR", "isPrefix": false},
6
+ "GBP": {"label": "British Pound Sterling", "symbol": "GBP", "isPrefix": false},
7
+ "HKD": {"label": "Hong Kong Dollar", "symbol": "HKD", "isPrefix": false},
8
+ "JPY": {"label": "Japanese Yen", "symbol": "JPY", "isPrefix": false},
9
+ "RUB": {"label": "Russian Ruble", "symbol": "RUB", "isPrefix": false},
10
+ "VND": {"label": "Vietnamese Dong", "symbol": "VND", "isPrefix": false}
11
+ }
@@ -3,9 +3,11 @@ export declare const buyTokenConfigs: Record<string, unknown>[];
3
3
  export declare const crowdloanFunds: Record<string, unknown>[];
4
4
  export declare const marketingCampaigns: Record<string, unknown>;
5
5
  export declare const termAndCondition: Record<string, unknown>;
6
+ export declare const currencySymbol: Record<string, unknown>;
6
7
  export declare enum StaticKey {
7
8
  BUY_SERVICE_INFOS = "buy-service-infos",
8
9
  CHAINS = "chains",
10
+ CURRENCY_SYMBOL = "currency_symbols",
9
11
  MARKETING_CAMPAINGS = "marketing-campaigns",
10
12
  CROWDLOAN_FUNDS = "crowdloan-funds",
11
13
  TERM_AND_CONDITION = "term-and-condition",
@@ -13,6 +15,7 @@ export declare enum StaticKey {
13
15
  }
14
16
  export declare const staticData: {
15
17
  chains: import("@subwallet/chain-list/types")._ChainInfo[];
18
+ currency_symbols: Record<string, unknown>;
16
19
  "buy-service-infos": Record<string, unknown>[];
17
20
  "crowdloan-funds": Record<string, unknown>[];
18
21
  "marketing-campaigns": Record<string, unknown>;
@@ -14,10 +14,13 @@ export const crowdloanFunds = require("./crowdloanFunds.json");
14
14
  export const marketingCampaigns = require("./marketingCampaigns.json");
15
15
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
16
16
  export const termAndCondition = require("./termAndCondition.json");
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
18
+ export const currencySymbol = require("./currencySymbol.json");
17
19
  export let StaticKey;
18
20
  (function (StaticKey) {
19
21
  StaticKey["BUY_SERVICE_INFOS"] = "buy-service-infos";
20
22
  StaticKey["CHAINS"] = "chains";
23
+ StaticKey["CURRENCY_SYMBOL"] = "currency_symbols";
21
24
  StaticKey["MARKETING_CAMPAINGS"] = "marketing-campaigns";
22
25
  StaticKey["CROWDLOAN_FUNDS"] = "crowdloan-funds";
23
26
  StaticKey["TERM_AND_CONDITION"] = "term-and-condition";
@@ -25,6 +28,7 @@ export let StaticKey;
25
28
  })(StaticKey || (StaticKey = {}));
26
29
  export const staticData = {
27
30
  [StaticKey.CHAINS]: Object.values(ChainInfoMap),
31
+ [StaticKey.CURRENCY_SYMBOL]: currencySymbol,
28
32
  [StaticKey.BUY_SERVICE_INFOS]: buyServiceInfos,
29
33
  [StaticKey.CROWDLOAN_FUNDS]: crowdloanFunds,
30
34
  [StaticKey.MARKETING_CAMPAINGS]: marketingCampaigns,