@rabbitio/ui-kit 1.0.0-beta.8 → 1.0.0-beta.9
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/index.js +1 -1
- package/package.json +2 -1
- package/src/common/amountUtils.js +423 -0
- package/src/common/errorUtils.js +27 -0
- package/src/common/fiatCurrenciesService.js +161 -0
- package/{stories → src/components}/atoms/AssetIcon/asset-icon.module.scss +1 -1
- package/{stories → src/components}/atoms/LoadingDots/LoadingDots.module.scss +1 -1
- package/{stories → src/components}/atoms/buttons/Button/Button.module.scss +1 -1
- package/src/index.js +10 -0
- package/stories/index.js +0 -4
- /package/{stories → src/components}/atoms/AssetIcon/AssetIcon.jsx +0 -0
- /package/{stories → src/components}/atoms/LoadingDots/LoadingDots.jsx +0 -0
- /package/{stories → src/components}/atoms/SupportChat/SupportChat.jsx +0 -0
- /package/{stories → src/components}/atoms/buttons/Button/Button.jsx +0 -0
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./src/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rabbitio/ui-kit",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Rabbit.io react.js components kit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"react-dom": ">=18.2.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"bignumber.js": "9.1.2",
|
|
41
42
|
"react": ">=18.2.0",
|
|
42
43
|
"react-dom": ">=18.2.0"
|
|
43
44
|
},
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
import { FiatCurrenciesService } from "./fiatCurrenciesService.js";
|
|
4
|
+
import { improveAndRethrow } from "./errorUtils.js";
|
|
5
|
+
|
|
6
|
+
// TODO: [dev] return addCommasToAmountString internal method to encapsulate commas adding
|
|
7
|
+
|
|
8
|
+
export class AmountUtils {
|
|
9
|
+
static significantDecimalCount = 8;
|
|
10
|
+
static collapsedDecimalCount = 2;
|
|
11
|
+
static maxTotalLength = 12;
|
|
12
|
+
static extraSmallMaxTotalLength = 9; // >=10 breaks transactions list (mobile) and it is hard to avoid this
|
|
13
|
+
static periods = "..";
|
|
14
|
+
|
|
15
|
+
static defaultFiatParams = {
|
|
16
|
+
ticker: true, // If true, currency code will be shown
|
|
17
|
+
enableCurrencySymbols: true, // Enables currency symbols where available. Requires "ticker: true"
|
|
18
|
+
collapsible: true, // Enables minimization of amounts over 1 million (example: 1.52M)
|
|
19
|
+
limitTotalLength: true, // Limits the total amount length to maxTotalLength
|
|
20
|
+
extraSmallLength: false, // Limits the total amount length to extraSmallMaxTotalLength
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
static fiatXs(amount, code) {
|
|
24
|
+
return this.fiat(amount, code, { extraSmallLength: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Universal method for rendering of fiat amounts, taking into account the rules of
|
|
29
|
+
* the passed fiat currency code.
|
|
30
|
+
*
|
|
31
|
+
* TODO: [feature, high] remove 'number' from accepted types list task_id=1e692bcfabbe487a9d1638fc8ff17448
|
|
32
|
+
* @param amount {BigNumber|number|string|null|undefined} The number value to be trimmed
|
|
33
|
+
* @param currencyCode {string|null} The currency code. Can be omitted if { ticker: false } in the config
|
|
34
|
+
* @param [passedParams={}] {object} Formatting parameters
|
|
35
|
+
* @return {string} Formatted fiat amount string
|
|
36
|
+
*/
|
|
37
|
+
static fiat(amount, currencyCode, passedParams = {}) {
|
|
38
|
+
try {
|
|
39
|
+
const params = { ...this.defaultFiatParams, ...passedParams };
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
this._checkIfAmountInvalid(amount, true) ||
|
|
43
|
+
typeof currencyCode !== "string"
|
|
44
|
+
)
|
|
45
|
+
return "NULL";
|
|
46
|
+
|
|
47
|
+
const currencySymbol =
|
|
48
|
+
FiatCurrenciesService.getCurrencySymbolByCode(currencyCode);
|
|
49
|
+
const currencyDecimalCount =
|
|
50
|
+
FiatCurrenciesService.getCurrencyDecimalCountByCode(
|
|
51
|
+
currencyCode
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const trimmedByMaxDigits = BigNumber(amount).toFixed(
|
|
55
|
+
currencyDecimalCount,
|
|
56
|
+
BigNumber.ROUND_FLOOR
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
let processedAmount = BigNumber(trimmedByMaxDigits);
|
|
60
|
+
if (
|
|
61
|
+
params.collapsible &&
|
|
62
|
+
processedAmount.gte(BigNumber("1000000"))
|
|
63
|
+
) {
|
|
64
|
+
processedAmount = this._collapseToMillionsAndFormat(
|
|
65
|
+
processedAmount,
|
|
66
|
+
this.collapsedDecimalCount,
|
|
67
|
+
params
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
const limitResult = this._limitTotalAmountLengthIfNeeded(
|
|
71
|
+
trimmedByMaxDigits,
|
|
72
|
+
params
|
|
73
|
+
);
|
|
74
|
+
processedAmount = BigNumber(
|
|
75
|
+
limitResult.processedAmount
|
|
76
|
+
).toFormat(); // Adds commas to integer part
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Add the currency code or currency symbol, if symbol is enabled and available
|
|
80
|
+
if (params.ticker) {
|
|
81
|
+
if (
|
|
82
|
+
typeof currencySymbol === "string" &&
|
|
83
|
+
params.enableCurrencySymbols
|
|
84
|
+
) {
|
|
85
|
+
processedAmount =
|
|
86
|
+
currencySymbol +
|
|
87
|
+
(currencySymbol.length > 1 ? " " : "") +
|
|
88
|
+
processedAmount;
|
|
89
|
+
} else {
|
|
90
|
+
processedAmount = processedAmount + " " + currencyCode;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return processedAmount;
|
|
95
|
+
} catch (e) {
|
|
96
|
+
improveAndRethrow(e, "fiat", `Passed: ${amount}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static defaultCryptoParams = {
|
|
101
|
+
ticker: true, // If true, asset ticker will be shown
|
|
102
|
+
collapsible: true, // Enables minimization of amounts over 1 million (example: 1.52M)
|
|
103
|
+
trim: true, // Cuts the right part of the amount if necessary, and adds ".." in the end
|
|
104
|
+
limitTotalLength: true, // Limits the total amount length to maxTotalLength
|
|
105
|
+
extraSmallLength: false, // Limits the total amount length to extraSmallMaxTotalLength
|
|
106
|
+
periods: true, // Whether we add periods ("..") as suffix for trimmed numbers
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
static cryptoWoTicker(amount, digits) {
|
|
110
|
+
return this.crypto(amount, null, digits, { ticker: false });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static cryptoWoTickerXs(amount, digits) {
|
|
114
|
+
return this.crypto(amount, null, digits, {
|
|
115
|
+
ticker: false,
|
|
116
|
+
extraSmallLength: true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static cryptoXs(amount, ticker, digits) {
|
|
121
|
+
return this.crypto(amount, ticker, digits, {
|
|
122
|
+
extraSmallLength: true,
|
|
123
|
+
periods: false,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static cryptoFull(amount, ticker, digits) {
|
|
128
|
+
return this.crypto(amount, ticker, digits, {
|
|
129
|
+
collapsible: false,
|
|
130
|
+
trim: false,
|
|
131
|
+
limitTotalLength: false,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Universal method for rendering of crypto amounts, taking into account the rules of
|
|
137
|
+
* the passed ticker. Requires the number of digits after period to be less of equal to
|
|
138
|
+
* the number of digits, supported by the passed ticker.
|
|
139
|
+
*
|
|
140
|
+
* @param amount {BigNumber|string|null|undefined} The number value to be formatted
|
|
141
|
+
* @param ticker {string|null} Coin ticker
|
|
142
|
+
* @param [digits=8] {number} max digits after the dot
|
|
143
|
+
* @param passedParams {object} Formatting parameters
|
|
144
|
+
* @return {string} Formatted crypto amount string
|
|
145
|
+
*/
|
|
146
|
+
static crypto(
|
|
147
|
+
amount,
|
|
148
|
+
ticker,
|
|
149
|
+
digits = this.significantDecimalCount,
|
|
150
|
+
passedParams
|
|
151
|
+
) {
|
|
152
|
+
try {
|
|
153
|
+
const params = { ...this.defaultCryptoParams, ...passedParams };
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
this._checkIfAmountInvalid(amount) ||
|
|
157
|
+
(typeof ticker !== "string" && params.ticker)
|
|
158
|
+
)
|
|
159
|
+
return "NULL";
|
|
160
|
+
|
|
161
|
+
let addPeriods = false;
|
|
162
|
+
|
|
163
|
+
const amountBigNumber = BigNumber(amount);
|
|
164
|
+
|
|
165
|
+
let processedAmount = amountBigNumber.toFixed(
|
|
166
|
+
digits,
|
|
167
|
+
BigNumber.ROUND_FLOOR
|
|
168
|
+
);
|
|
169
|
+
processedAmount =
|
|
170
|
+
this.removeRedundantRightZerosFromNumberString(processedAmount);
|
|
171
|
+
const originalAmountDecimalPlaces =
|
|
172
|
+
BigNumber(processedAmount).decimalPlaces();
|
|
173
|
+
// Check decimal count and throw an error, if the amount has more decimal digits than supported by the asset
|
|
174
|
+
if (originalAmountDecimalPlaces > digits) {
|
|
175
|
+
const errorMessage = `An attempt to render a crypto value with too many digits after period was made: ${amount}, allowed digits: ${digits}. This is a no-op, since the logical and visually rendered values would differ, which is not acceptable for crypto amounts. Please trim the amount before rendering, using the trimCryptoAmountByCoin(amount, coin) method.`;
|
|
176
|
+
// throw new Error(errorMessage);
|
|
177
|
+
// eslint-disable-next-line no-console
|
|
178
|
+
console.log(errorMessage, "crypto");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Shortening the value to general significant number of digits after period
|
|
182
|
+
if (params.trim) {
|
|
183
|
+
processedAmount =
|
|
184
|
+
this.removeRedundantRightZerosFromNumberString(
|
|
185
|
+
amountBigNumber.toFixed(
|
|
186
|
+
this.significantDecimalCount,
|
|
187
|
+
BigNumber.ROUND_FLOOR
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
addPeriods =
|
|
191
|
+
originalAmountDecimalPlaces > this.significantDecimalCount;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const limitResult = this._limitTotalAmountLengthIfNeeded(
|
|
195
|
+
processedAmount,
|
|
196
|
+
params
|
|
197
|
+
);
|
|
198
|
+
processedAmount = limitResult.processedAmount;
|
|
199
|
+
addPeriods ||= limitResult.addPeriods;
|
|
200
|
+
|
|
201
|
+
let wereMillionsCollapsed = false;
|
|
202
|
+
if (params.collapsible && amountBigNumber.gte("1000000")) {
|
|
203
|
+
// Collapse the 1M+ amounts if applicable
|
|
204
|
+
processedAmount = this._collapseToMillionsAndFormat(
|
|
205
|
+
BigNumber(processedAmount),
|
|
206
|
+
this.collapsedDecimalCount,
|
|
207
|
+
params
|
|
208
|
+
);
|
|
209
|
+
wereMillionsCollapsed = true;
|
|
210
|
+
} else {
|
|
211
|
+
// Add separators to integer part of the amount
|
|
212
|
+
processedAmount = BigNumber(processedAmount).toFormat();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Adding periods, if the amount was shortened
|
|
216
|
+
if (params.periods && addPeriods && !wereMillionsCollapsed) {
|
|
217
|
+
processedAmount = processedAmount + this.periods;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Adding an adaptive (printable/full) ticker
|
|
221
|
+
if (params.ticker && ticker) {
|
|
222
|
+
processedAmount = processedAmount + " " + ticker;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return processedAmount;
|
|
226
|
+
} catch (e) {
|
|
227
|
+
improveAndRethrow(
|
|
228
|
+
e,
|
|
229
|
+
"crypto",
|
|
230
|
+
`Passed: ${amount}, ${ticker}, ${digits}`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static _checkIfAmountInvalid(amount, allowNumbers = false) {
|
|
236
|
+
return (
|
|
237
|
+
amount == null ||
|
|
238
|
+
amount === "" ||
|
|
239
|
+
(!BigNumber.isBigNumber(amount) &&
|
|
240
|
+
typeof amount !== "string" &&
|
|
241
|
+
(!allowNumbers || typeof amount !== "number"))
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Trims all digits after period that exceed the number of digits provided.
|
|
247
|
+
* Use this everywhere when calculating some amount value to ensure the result is correct in terms
|
|
248
|
+
* of max digits allowed by specific currency.
|
|
249
|
+
*
|
|
250
|
+
* @param amount {BigNumber|number|string|null|undefined} The number value to be trimmed.
|
|
251
|
+
* HEX strings also allowed "0x..." and JS hex numbers
|
|
252
|
+
* @param digits {number} allowed digits
|
|
253
|
+
* @return {string|null} String with trimmed number or null for invalid amount
|
|
254
|
+
*/
|
|
255
|
+
static trim(amount, digits) {
|
|
256
|
+
try {
|
|
257
|
+
if (this._checkIfAmountInvalid(amount, true)) return null;
|
|
258
|
+
return BigNumber(amount).toFixed(digits, BigNumber.ROUND_FLOOR);
|
|
259
|
+
} catch (e) {
|
|
260
|
+
improveAndRethrow(e, "trim", `Passed: ${amount}, ${digits}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @param amount {BigNumber|number|string|null|undefined} The number value to be trimmed.
|
|
266
|
+
* HEX strings also allowed "0x..." and JS hex numbers
|
|
267
|
+
* @return {string|null}
|
|
268
|
+
*/
|
|
269
|
+
static intStr(amount) {
|
|
270
|
+
return this.trim(amount, 0);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Shortens the line length by using a "1.52M" representation of big amounts.
|
|
275
|
+
*
|
|
276
|
+
* @param amountBigNumber {BigNumber} The number value to be trimmed
|
|
277
|
+
* @param decimalCount {number} The number of digits after period to keep in millions representation
|
|
278
|
+
* @param params {object} params object
|
|
279
|
+
* @return {string} A shortened string, converted into "millions" format, if the amount exceeds 1 million
|
|
280
|
+
*/
|
|
281
|
+
static _collapseToMillionsAndFormat(
|
|
282
|
+
amountBigNumber,
|
|
283
|
+
decimalCount,
|
|
284
|
+
params = {}
|
|
285
|
+
) {
|
|
286
|
+
try {
|
|
287
|
+
// TODO: [feature, moderate] use local format here - take from JS locales (comma/dot etc.)
|
|
288
|
+
const millionBigNumber = BigNumber("1000000");
|
|
289
|
+
const millions = amountBigNumber
|
|
290
|
+
.div(millionBigNumber)
|
|
291
|
+
.toFixed(decimalCount, BigNumber.ROUND_FLOOR);
|
|
292
|
+
const limitedResult = this._limitTotalAmountLengthIfNeeded(
|
|
293
|
+
millions,
|
|
294
|
+
params
|
|
295
|
+
);
|
|
296
|
+
const formatted = BigNumber(
|
|
297
|
+
limitedResult.processedAmount
|
|
298
|
+
).toFormat();
|
|
299
|
+
|
|
300
|
+
return formatted + "M";
|
|
301
|
+
} catch (e) {
|
|
302
|
+
improveAndRethrow(
|
|
303
|
+
e,
|
|
304
|
+
"_collapseAmountAndFormat",
|
|
305
|
+
`Passed: ${amountBigNumber.toFixed()}, ${decimalCount}`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @param amountString {string} The amount to be restricted by length
|
|
312
|
+
* @param params {object} Params object used for formatting
|
|
313
|
+
* @return {{processedAmount:string, addPeriods: boolean}} A shortened string
|
|
314
|
+
*/
|
|
315
|
+
static _limitTotalAmountLengthIfNeeded(amountString, params) {
|
|
316
|
+
try {
|
|
317
|
+
let addPeriods = false;
|
|
318
|
+
if (params.limitTotalLength || params.extraSmallLength) {
|
|
319
|
+
const maxLength = params.extraSmallLength
|
|
320
|
+
? this.extraSmallMaxTotalLength
|
|
321
|
+
: this.maxTotalLength;
|
|
322
|
+
if (amountString.length > maxLength) {
|
|
323
|
+
const delta = amountString.length - maxLength;
|
|
324
|
+
const currentDecimalsCount =
|
|
325
|
+
BigNumber(amountString).decimalPlaces();
|
|
326
|
+
const newDecimalCount = currentDecimalsCount - delta;
|
|
327
|
+
amountString = BigNumber(amountString).toFixed(
|
|
328
|
+
newDecimalCount > 2 ? newDecimalCount : 2,
|
|
329
|
+
BigNumber.ROUND_FLOOR
|
|
330
|
+
);
|
|
331
|
+
addPeriods = currentDecimalsCount > newDecimalCount;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return { addPeriods: addPeriods, processedAmount: amountString };
|
|
336
|
+
} catch (e) {
|
|
337
|
+
improveAndRethrow(
|
|
338
|
+
e,
|
|
339
|
+
"_limitTotalAmountLengthIfNeeded",
|
|
340
|
+
`Passed: ${amountString}, ${params}`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Safely composes rate string (handles small/big rates)
|
|
347
|
+
*
|
|
348
|
+
* @param leftTicker {string}
|
|
349
|
+
* @param rightTicker {string}
|
|
350
|
+
* @param rate {number|string|BigNumber}
|
|
351
|
+
* @param [rightCurrencyDigitsAfterDots=8] {number}
|
|
352
|
+
* @return {string}
|
|
353
|
+
*/
|
|
354
|
+
static composeRateText(
|
|
355
|
+
leftTicker,
|
|
356
|
+
rightTicker,
|
|
357
|
+
rate,
|
|
358
|
+
rightCurrencyDigitsAfterDots = this.significantDecimalCount
|
|
359
|
+
) {
|
|
360
|
+
try {
|
|
361
|
+
/* Here we try to calculate a clear rate for the user. The difficulty is that the rate value can be pretty
|
|
362
|
+
* small as some coins have significantly higher price than the other. For such cases we calculate
|
|
363
|
+
* not the "1 <coin_A> is X <coin B>" but "Y <coin_A> is X <coin B>" where Y is one of the powers of 100.
|
|
364
|
+
*/
|
|
365
|
+
let leftNumber = BigNumber("1");
|
|
366
|
+
const multiplier = BigNumber("100");
|
|
367
|
+
const maxAttemptsToGetRate = 10;
|
|
368
|
+
let right = null;
|
|
369
|
+
const rateBigNumber = BigNumber(rate);
|
|
370
|
+
for (let i = 0; i < maxAttemptsToGetRate; ++i) {
|
|
371
|
+
const rightNumberAttempt = rateBigNumber
|
|
372
|
+
.times(leftNumber)
|
|
373
|
+
.toFixed(
|
|
374
|
+
rightCurrencyDigitsAfterDots,
|
|
375
|
+
BigNumber.ROUND_FLOOR
|
|
376
|
+
);
|
|
377
|
+
if (!BigNumber(rightNumberAttempt).eq(BigNumber("0"))) {
|
|
378
|
+
right = BigNumber(rightNumberAttempt);
|
|
379
|
+
break;
|
|
380
|
+
} else {
|
|
381
|
+
leftNumber = leftNumber.times(multiplier);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const leftAmountString = AmountUtils.intStr(leftNumber);
|
|
385
|
+
const rightAmountString =
|
|
386
|
+
right != null
|
|
387
|
+
? right.toFixed(
|
|
388
|
+
rightCurrencyDigitsAfterDots,
|
|
389
|
+
BigNumber.ROUND_FLOOR
|
|
390
|
+
)
|
|
391
|
+
: null;
|
|
392
|
+
return `${leftAmountString} ${leftTicker} ~ ${
|
|
393
|
+
rightAmountString ?? "?"
|
|
394
|
+
} ${rightTicker}`;
|
|
395
|
+
} catch (e) {
|
|
396
|
+
// eslint-disable-next-line no-console
|
|
397
|
+
console.log("composeRateText", e);
|
|
398
|
+
}
|
|
399
|
+
return "-";
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* @param numberAsAString {string}
|
|
404
|
+
* @return {string}
|
|
405
|
+
*/
|
|
406
|
+
static removeRedundantRightZerosFromNumberString(numberAsAString) {
|
|
407
|
+
try {
|
|
408
|
+
const parts = ("" + numberAsAString).split(".");
|
|
409
|
+
let right = parts[1];
|
|
410
|
+
while (right?.length && right[right.length - 1] === "0") {
|
|
411
|
+
right = right.slice(0, right.length - 1);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return `${parts[0]}${right?.length ? `.${right}` : ""}`;
|
|
415
|
+
} catch (e) {
|
|
416
|
+
improveAndRethrow(
|
|
417
|
+
e,
|
|
418
|
+
"removeRedundantRightZerosFromNumberString",
|
|
419
|
+
`Passed: ${numberAsAString}`
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function improves the passed error object (its message) by adding the passed function name
|
|
3
|
+
* and additional message to it.
|
|
4
|
+
* This is useful as Javascript doesn't guarantee the stack-traces, so we should manually add these details to errors
|
|
5
|
+
* to be able to troubleshoot.
|
|
6
|
+
*
|
|
7
|
+
* @param e {Error}
|
|
8
|
+
* @param settingFunction {string}
|
|
9
|
+
* @param [additionalMessage=""] {string|undefined}
|
|
10
|
+
* @throws {Error} always rethrows the original passed error but with an improved message
|
|
11
|
+
*/
|
|
12
|
+
export function improveAndRethrow(e, settingFunction, additionalMessage = "") {
|
|
13
|
+
const message = improvedErrorMessage(e, settingFunction, additionalMessage);
|
|
14
|
+
if (e) {
|
|
15
|
+
e.message = message;
|
|
16
|
+
throw e; // to preserve existing stacktrace if present
|
|
17
|
+
}
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function improvedErrorMessage(e, settingFunction, additionalMessage) {
|
|
22
|
+
let message = `\nFunction call ${settingFunction ?? ""} failed. `;
|
|
23
|
+
e && e.message && (message += `Error message: ${e.message}. `);
|
|
24
|
+
additionalMessage && (message += `${additionalMessage} `);
|
|
25
|
+
|
|
26
|
+
return message;
|
|
27
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export class FiatCurrenciesService {
|
|
2
|
+
static getFullCurrencyNameByCode(code = "") {
|
|
3
|
+
const data = fiatCurrenciesList.find(
|
|
4
|
+
(currencyData) => currencyData[0] === code.toUpperCase()
|
|
5
|
+
);
|
|
6
|
+
return (data && data[2]) || null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static isCodeValid(code) {
|
|
10
|
+
return !!fiatCurrenciesList.find(
|
|
11
|
+
(currenciesData) => currenciesData[0] === code
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns currency symbol by code if present
|
|
17
|
+
*
|
|
18
|
+
* @param code {string} currency code
|
|
19
|
+
* @return {string|null} code or null if there is no symbol for the currency
|
|
20
|
+
*/
|
|
21
|
+
static getCurrencySymbolByCode(code = "") {
|
|
22
|
+
const data = fiatCurrenciesList.find(
|
|
23
|
+
(currencyData) => currencyData[0] === code.toUpperCase()
|
|
24
|
+
);
|
|
25
|
+
return data?.[1] ?? null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param code {string}
|
|
30
|
+
* @return {number|null}
|
|
31
|
+
*/
|
|
32
|
+
static getCurrencyDecimalCountByCode(code = "") {
|
|
33
|
+
const data = fiatCurrenciesList.find(
|
|
34
|
+
(currencyData) => currencyData[0] === code.toUpperCase()
|
|
35
|
+
);
|
|
36
|
+
return data?.[3] ?? null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const fiatCurrenciesList = [
|
|
41
|
+
["USD", "$", "US Dollar", 2],
|
|
42
|
+
["CAD", "CA$", "Canadian Dollar", 2],
|
|
43
|
+
["EUR", "€", "Euro", 2],
|
|
44
|
+
["AED", "AED", "UAE Dirham", 2],
|
|
45
|
+
["AFN", "؋", "Afghan Afghani", 0],
|
|
46
|
+
["ALL", "ALL", "Albanian Lek", 0],
|
|
47
|
+
["AMD", "֏", "Armenian Dram", 0],
|
|
48
|
+
["ARS", "AR$", "Argentine Peso", 2],
|
|
49
|
+
["AUD", "AU$", "Australian Dollar", 2],
|
|
50
|
+
["AZN", "₼", "Azerbaijani Manat", 2],
|
|
51
|
+
["BAM", "KM", "Bosnia-Herzegovina Convertible Mark", 2],
|
|
52
|
+
["BDT", "Tk", "Bangladeshi Taka", 2],
|
|
53
|
+
["BGN", "BGN", "Bulgarian Lev", 2],
|
|
54
|
+
["BHD", "BD", "Bahraini Dinar", 3],
|
|
55
|
+
["BIF", "FBu", "Burundian Franc", 0],
|
|
56
|
+
["BND", "BN$", "Brunei Dollar", 2],
|
|
57
|
+
["BOB", "Bs", "Bolivian Boliviano", 2],
|
|
58
|
+
["BRL", "R$", "Brazilian Real", 2],
|
|
59
|
+
["BWP", "BWP", "Botswanan Pula", 2],
|
|
60
|
+
["BYN", "Br", "Belarusian Ruble", 2],
|
|
61
|
+
["BZD", "BZ$", "Belize Dollar", 2],
|
|
62
|
+
["CDF", "CDF", "Congolese Franc", 2],
|
|
63
|
+
["CHF", "CHF", "Swiss Franc", 2],
|
|
64
|
+
["CLP", "CL$", "Chilean Peso", 0],
|
|
65
|
+
["CNY", "CN¥", "Chinese Yuan", 2],
|
|
66
|
+
["COP", "CO$", "Colombian Peso", 0],
|
|
67
|
+
["CRC", "₡", "Costa Rican Colón", 0],
|
|
68
|
+
["CVE", "CV$", "Cape Verdean Escudo", 2],
|
|
69
|
+
["CZK", "Kč", "Czech Republic Koruna", 2],
|
|
70
|
+
["DJF", "Fdj", "Djiboutian Franc", 0],
|
|
71
|
+
["DKK", "Dkr", "Danish Krone", 2],
|
|
72
|
+
["DOP", "RD$", "Dominican Peso", 2],
|
|
73
|
+
["DZD", "DA", "Algerian Dinar", 2],
|
|
74
|
+
["EEK", "Ekr", "Estonian Kroon", 2],
|
|
75
|
+
["EGP", "EGP", "Egyptian Pound", 2],
|
|
76
|
+
["ERN", "Nfk", "Eritrean Nakfa", 2],
|
|
77
|
+
["ETB", "Br", "Ethiopian Birr", 2],
|
|
78
|
+
["GBP", "£", "British Pound Sterling", 2],
|
|
79
|
+
["GEL", "₾", "Georgian Lari", 2],
|
|
80
|
+
["GHS", "₵", "Ghanaian Cedi", 2],
|
|
81
|
+
["GNF", "FG", "Guinean Franc", 0],
|
|
82
|
+
["GTQ", "GTQ", "Guatemalan Quetzal", 2],
|
|
83
|
+
["HKD", "HK$", "Hong Kong Dollar", 2],
|
|
84
|
+
["HNL", "HNL", "Honduran Lempira", 2],
|
|
85
|
+
["HRK", "kn", "Croatian Kuna", 2],
|
|
86
|
+
["HUF", "Ft", "Hungarian Forint", 0],
|
|
87
|
+
["IDR", "Rp", "Indonesian Rupiah", 0],
|
|
88
|
+
["ILS", "₪", "Israeli New Sheqel", 2],
|
|
89
|
+
["INR", "₹", "Indian Rupee", 2],
|
|
90
|
+
["IQD", "IQD", "Iraqi Dinar", 0],
|
|
91
|
+
["IRR", "﷼", "Iranian Rial", 0],
|
|
92
|
+
["ISK", "Ikr", "Icelandic Króna", 0],
|
|
93
|
+
["JMD", "J$", "Jamaican Dollar", 2],
|
|
94
|
+
["JOD", "JD", "Jordanian Dinar", 3],
|
|
95
|
+
["JPY", "¥", "Japanese Yen", 0],
|
|
96
|
+
["KES", "Ksh", "Kenyan Shilling", 2],
|
|
97
|
+
["KHR", "KHR", "Cambodian Riel", 2],
|
|
98
|
+
["KMF", "CF", "Comorian Franc", 0],
|
|
99
|
+
["KRW", "₩", "South Korean Won", 0],
|
|
100
|
+
["KWD", "KD", "Kuwaiti Dinar", 3],
|
|
101
|
+
["KZT", "₸", "Kazakhstani Tenge", 2],
|
|
102
|
+
["LBP", "LB£", "Lebanese Pound", 0],
|
|
103
|
+
["LKR", "SLRs", "Sri Lankan Rupee", 2],
|
|
104
|
+
["LTL", "Lt", "Lithuanian Litas", 2],
|
|
105
|
+
["LVL", "Ls", "Latvian Lats", 2],
|
|
106
|
+
["LYD", "LD", "Libyan Dinar", 3],
|
|
107
|
+
["MAD", "MAD", "Moroccan Dirham", 2],
|
|
108
|
+
["MDL", "MDL", "Moldovan Leu", 2],
|
|
109
|
+
["MGA", "MGA", "Malagasy Ariary", 0],
|
|
110
|
+
["MKD", "MKD", "Macedonian Denar", 2],
|
|
111
|
+
["MMK", "MMK", "Myanma Kyat", 0],
|
|
112
|
+
["MNT", "₮", "Mongolian Tugrik", 0],
|
|
113
|
+
["MOP", "MOP$", "Macanese Pataca", 2],
|
|
114
|
+
["MUR", "MURs", "Mauritian Rupee", 0],
|
|
115
|
+
["MXN", "MX$", "Mexican Peso", 2],
|
|
116
|
+
["MYR", "RM", "Malaysian Ringgit", 2],
|
|
117
|
+
["MZN", "MTn", "Mozambican Metical", 2],
|
|
118
|
+
["NAD", "N$", "Namibian Dollar", 2],
|
|
119
|
+
["NGN", "₦", "Nigerian Naira", 2],
|
|
120
|
+
["NIO", "C$", "Nicaraguan Córdoba", 2],
|
|
121
|
+
["NOK", "Nkr", "Norwegian Krone", 2],
|
|
122
|
+
["NPR", "NPRs", "Nepalese Rupee", 2],
|
|
123
|
+
["NZD", "NZ$", "New Zealand Dollar", 2],
|
|
124
|
+
["OMR", "OMR", "Omani Rial", 3],
|
|
125
|
+
["PAB", "B/.", "Panamanian Balboa", 2],
|
|
126
|
+
["PEN", "S/.", "Peruvian Nuevo Sol", 2],
|
|
127
|
+
["PHP", "₱", "Philippine Peso", 2],
|
|
128
|
+
["PKR", "PKRs", "Pakistani Rupee", 0],
|
|
129
|
+
["PLN", "zł", "Polish Zloty", 2],
|
|
130
|
+
["PYG", "₲", "Paraguayan Guarani", 0],
|
|
131
|
+
["QAR", "QR", "Qatari Rial", 2],
|
|
132
|
+
["RON", "RON", "Romanian Leu", 2],
|
|
133
|
+
["RSD", "din.", "Serbian Dinar", 0],
|
|
134
|
+
["RUB", "₽", "Russian Ruble", 2],
|
|
135
|
+
["RWF", "RWF", "Rwandan Franc", 0],
|
|
136
|
+
["SAR", "SR", "Saudi Riyal", 2],
|
|
137
|
+
["SDG", "SDG", "Sudanese Pound", 2],
|
|
138
|
+
["SEK", "Skr", "Swedish Krona", 2],
|
|
139
|
+
["SGD", "S$", "Singapore Dollar", 2],
|
|
140
|
+
["SOS", "Ssh", "Somali Shilling", 0],
|
|
141
|
+
["SYP", "SY£", "Syrian Pound", 0],
|
|
142
|
+
["THB", "฿", "Thai Baht", 2],
|
|
143
|
+
["TND", "DT", "Tunisian Dinar", 3],
|
|
144
|
+
["TOP", "T$", "Tongan Paʻanga", 2],
|
|
145
|
+
["TRY", "₺", "Turkish Lira", 2],
|
|
146
|
+
["TTD", "TT$", "Trinidad and Tobago Dollar", 2],
|
|
147
|
+
["TWD", "NT$", "New Taiwan Dollar", 2],
|
|
148
|
+
["TZS", "TSh", "Tanzanian Shilling", 0],
|
|
149
|
+
["UAH", "₴", "Ukrainian Hryvnia", 2],
|
|
150
|
+
["UGX", "USh", "Ugandan Shilling", 0],
|
|
151
|
+
["UYU", "$U", "Uruguayan Peso", 2],
|
|
152
|
+
["UZS", "UZS", "Uzbekistan Som", 0],
|
|
153
|
+
["VEF", "Bs.F.", "Venezuelan Bolívar", 2],
|
|
154
|
+
["VND", "₫", "Vietnamese Dong", 0],
|
|
155
|
+
["XAF", "FCFA", "CFA Franc BEAC", 0],
|
|
156
|
+
["XOF", "CFA", "CFA Franc BCEAO", 0],
|
|
157
|
+
["YER", "﷼", "Yemeni Rial", 0],
|
|
158
|
+
["ZAR", "R", "South African Rand", 2],
|
|
159
|
+
["ZMK", "ZK", "Zambian Kwacha", 0],
|
|
160
|
+
["ZWL", "ZWL$", "Zimbabwean Dollar", 0],
|
|
161
|
+
];
|
package/src/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// UI-KIT components
|
|
2
|
+
export { Button } from "./components/atoms/buttons/Button/Button.jsx";
|
|
3
|
+
export { LoadingDots } from "./components/atoms/LoadingDots/LoadingDots.jsx";
|
|
4
|
+
export { SupportChat } from "./components/atoms/SupportChat/SupportChat.jsx";
|
|
5
|
+
export { AssetIcon } from "./components/atoms/AssetIcon/AssetIcon.jsx";
|
|
6
|
+
|
|
7
|
+
// Common code
|
|
8
|
+
export { improveAndRethrow } from "./common/errorUtils.js";
|
|
9
|
+
export { FiatCurrenciesService } from "./common/fiatCurrenciesService.js";
|
|
10
|
+
export { AmountUtils } from "./common/amountUtils.js";
|
package/stories/index.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|