@w3ux/utils 0.10.0 → 0.10.1-alpha.2
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/base.cjs +8 -13
- package/base.d.cts +1 -12
- package/base.d.ts +1 -12
- package/base.js +8 -11
- package/index.cjs +26 -81
- package/index.d.cts +3 -3
- package/index.d.ts +3 -3
- package/index.js +25 -78
- package/package.json +1 -1
- package/types.cjs +0 -19
- package/types.d.cts +1 -8
- package/types.d.ts +1 -8
- package/types.js +0 -12
- package/unit.cjs +18 -69
- package/unit.d.cts +11 -12
- package/unit.d.ts +11 -12
- package/unit.js +17 -68
package/base.cjs
CHANGED
|
@@ -25,8 +25,6 @@ __export(base_exports, {
|
|
|
25
25
|
ellipsisFn: () => ellipsisFn,
|
|
26
26
|
eqSet: () => eqSet,
|
|
27
27
|
formatAccountSs58: () => formatAccountSs58,
|
|
28
|
-
greaterThanZero: () => greaterThanZero,
|
|
29
|
-
isNotZero: () => isNotZero,
|
|
30
28
|
isSuperset: () => isSuperset,
|
|
31
29
|
minDecimalPlaces: () => minDecimalPlaces,
|
|
32
30
|
pageFromUri: () => pageFromUri,
|
|
@@ -36,7 +34,6 @@ __export(base_exports, {
|
|
|
36
34
|
withTimeout: () => withTimeout
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(base_exports);
|
|
39
|
-
var import_bignumber = require("bignumber.js");
|
|
40
37
|
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
41
38
|
var camelize = (str) => {
|
|
42
39
|
const convertToString = (string) => {
|
|
@@ -92,15 +89,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
92
89
|
return "..." + str.slice(amount);
|
|
93
90
|
}
|
|
94
91
|
};
|
|
95
|
-
var greaterThanZero = (val) => val.isGreaterThan(0);
|
|
96
|
-
var isNotZero = (val) => !val.isZero();
|
|
97
92
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
missingDecimals.
|
|
103
|
-
|
|
93
|
+
try {
|
|
94
|
+
const whole = BigInt(rmCommas(val).split(".")[0] || "0");
|
|
95
|
+
const decimals = val.split(".")[1] || "";
|
|
96
|
+
const missingDecimals = minDecimals - decimals.length;
|
|
97
|
+
return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
return "0";
|
|
100
|
+
}
|
|
104
101
|
};
|
|
105
102
|
var pageFromUri = (pathname, fallback) => {
|
|
106
103
|
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
@@ -160,8 +157,6 @@ var isSuperset = (set, subset) => {
|
|
|
160
157
|
ellipsisFn,
|
|
161
158
|
eqSet,
|
|
162
159
|
formatAccountSs58,
|
|
163
|
-
greaterThanZero,
|
|
164
|
-
isNotZero,
|
|
165
160
|
isSuperset,
|
|
166
161
|
minDecimalPlaces,
|
|
167
162
|
pageFromUri,
|
package/base.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumber } from 'bignumber.js';
|
|
2
1
|
import { AnyFunction } from '@w3ux/types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -15,16 +14,6 @@ declare const camelize: (str: string) => string;
|
|
|
15
14
|
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
16
15
|
*/
|
|
17
16
|
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
18
|
-
/**
|
|
19
|
-
* @name greaterThanZero
|
|
20
|
-
* @summary Returns whether a BigNumber is greater than zero.
|
|
21
|
-
*/
|
|
22
|
-
declare const greaterThanZero: (val: BigNumber) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
* @name isNotZero
|
|
25
|
-
* @summary Returns whether a BigNumber is zero.
|
|
26
|
-
*/
|
|
27
|
-
declare const isNotZero: (val: BigNumber) => boolean;
|
|
28
17
|
/**
|
|
29
18
|
* @name minDecimalPlaces
|
|
30
19
|
* @summary Forces a number to have at least the provided decimal places.
|
|
@@ -76,4 +65,4 @@ declare const removeHexPrefix: (str: string) => string;
|
|
|
76
65
|
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
77
66
|
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
78
67
|
|
|
79
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58,
|
|
68
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
|
package/base.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumber } from 'bignumber.js';
|
|
2
1
|
import { AnyFunction } from '@w3ux/types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -15,16 +14,6 @@ declare const camelize: (str: string) => string;
|
|
|
15
14
|
* same for beginning and end; if "start" or "end" then its only once the amount; defaults to "start"
|
|
16
15
|
*/
|
|
17
16
|
declare const ellipsisFn: (str: string, amount?: number, position?: "start" | "end" | "center") => string;
|
|
18
|
-
/**
|
|
19
|
-
* @name greaterThanZero
|
|
20
|
-
* @summary Returns whether a BigNumber is greater than zero.
|
|
21
|
-
*/
|
|
22
|
-
declare const greaterThanZero: (val: BigNumber) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
* @name isNotZero
|
|
25
|
-
* @summary Returns whether a BigNumber is zero.
|
|
26
|
-
*/
|
|
27
|
-
declare const isNotZero: (val: BigNumber) => boolean;
|
|
28
17
|
/**
|
|
29
18
|
* @name minDecimalPlaces
|
|
30
19
|
* @summary Forces a number to have at least the provided decimal places.
|
|
@@ -76,4 +65,4 @@ declare const removeHexPrefix: (str: string) => string;
|
|
|
76
65
|
declare const eqSet: (xs: Set<any>, ys: Set<any>) => boolean;
|
|
77
66
|
declare const isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
|
78
67
|
|
|
79
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58,
|
|
68
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout };
|
package/base.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
import { BigNumber } from "bignumber.js";
|
|
3
2
|
import { AccountId } from "@polkadot-api/substrate-bindings";
|
|
4
3
|
var camelize = (str) => {
|
|
5
4
|
const convertToString = (string) => {
|
|
@@ -55,15 +54,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
55
54
|
return "..." + str.slice(amount);
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
|
-
var greaterThanZero = (val) => val.isGreaterThan(0);
|
|
59
|
-
var isNotZero = (val) => !val.isZero();
|
|
60
57
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
missingDecimals.
|
|
66
|
-
|
|
58
|
+
try {
|
|
59
|
+
const whole = BigInt(rmCommas(val).split(".")[0] || "0");
|
|
60
|
+
const decimals = val.split(".")[1] || "";
|
|
61
|
+
const missingDecimals = minDecimals - decimals.length;
|
|
62
|
+
return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return "0";
|
|
65
|
+
}
|
|
67
66
|
};
|
|
68
67
|
var pageFromUri = (pathname, fallback) => {
|
|
69
68
|
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
@@ -122,8 +121,6 @@ export {
|
|
|
122
121
|
ellipsisFn,
|
|
123
122
|
eqSet,
|
|
124
123
|
formatAccountSs58,
|
|
125
|
-
greaterThanZero,
|
|
126
|
-
isNotZero,
|
|
127
124
|
isSuperset,
|
|
128
125
|
minDecimalPlaces,
|
|
129
126
|
pageFromUri,
|
package/index.cjs
CHANGED
|
@@ -38,12 +38,9 @@ __export(src_exports, {
|
|
|
38
38
|
determinePoolDisplay: () => determinePoolDisplay,
|
|
39
39
|
ellipsisFn: () => ellipsisFn,
|
|
40
40
|
eqSet: () => eqSet,
|
|
41
|
-
evalUnits: () => evalUnits,
|
|
42
41
|
extractUrlValue: () => extractUrlValue,
|
|
43
42
|
formatAccountSs58: () => formatAccountSs58,
|
|
44
|
-
greaterThanZero: () => greaterThanZero,
|
|
45
43
|
inChrome: () => inChrome,
|
|
46
|
-
isNotZero: () => isNotZero,
|
|
47
44
|
isSuperset: () => isSuperset,
|
|
48
45
|
isValidAddress: () => isValidAddress,
|
|
49
46
|
isValidHttpUrl: () => isValidHttpUrl,
|
|
@@ -54,6 +51,7 @@ __export(src_exports, {
|
|
|
54
51
|
minDecimalPlaces: () => minDecimalPlaces,
|
|
55
52
|
pageFromUri: () => pageFromUri,
|
|
56
53
|
planckToUnit: () => planckToUnit,
|
|
54
|
+
planckToUnitLegacy: () => planckToUnitLegacy,
|
|
57
55
|
remToUnit: () => remToUnit,
|
|
58
56
|
removeHexPrefix: () => removeHexPrefix,
|
|
59
57
|
removeVarFromUrlHash: () => removeVarFromUrlHash,
|
|
@@ -74,7 +72,6 @@ __export(src_exports, {
|
|
|
74
72
|
module.exports = __toCommonJS(src_exports);
|
|
75
73
|
|
|
76
74
|
// src/base.ts
|
|
77
|
-
var import_bignumber = require("bignumber.js");
|
|
78
75
|
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
79
76
|
var camelize = (str) => {
|
|
80
77
|
const convertToString = (string) => {
|
|
@@ -130,15 +127,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
130
127
|
return "..." + str.slice(amount);
|
|
131
128
|
}
|
|
132
129
|
};
|
|
133
|
-
var greaterThanZero = (val) => val.isGreaterThan(0);
|
|
134
|
-
var isNotZero = (val) => !val.isZero();
|
|
135
130
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
missingDecimals.
|
|
141
|
-
|
|
131
|
+
try {
|
|
132
|
+
const whole = BigInt(rmCommas(val).split(".")[0] || "0");
|
|
133
|
+
const decimals = val.split(".")[1] || "";
|
|
134
|
+
const missingDecimals = minDecimals - decimals.length;
|
|
135
|
+
return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return "0";
|
|
138
|
+
}
|
|
142
139
|
};
|
|
143
140
|
var pageFromUri = (pathname, fallback) => {
|
|
144
141
|
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
@@ -229,7 +226,7 @@ function isFunction(value) {
|
|
|
229
226
|
function invalidFallback() {
|
|
230
227
|
return Number.NaN;
|
|
231
228
|
}
|
|
232
|
-
var
|
|
229
|
+
var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
|
|
233
230
|
|
|
234
231
|
// ../../node_modules/@polkadot/util/hex/toU8a.js
|
|
235
232
|
var CHR = "0123456789abcdef";
|
|
@@ -269,7 +266,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
|
|
|
269
266
|
}
|
|
270
267
|
|
|
271
268
|
// ../../node_modules/@polkadot/util/has.js
|
|
272
|
-
var hasBigInt = typeof
|
|
269
|
+
var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
|
|
273
270
|
var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
|
|
274
271
|
var hasProcess = typeof xglobal.process === "object";
|
|
275
272
|
|
|
@@ -338,15 +335,23 @@ function u8aUnwrapBytes(bytes) {
|
|
|
338
335
|
}
|
|
339
336
|
|
|
340
337
|
// src/unit.ts
|
|
341
|
-
var
|
|
338
|
+
var import_bignumber = require("bignumber.js");
|
|
342
339
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
343
340
|
var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
344
|
-
var
|
|
345
|
-
val.dividedBy(new
|
|
341
|
+
var planckToUnitLegacy = (val, units) => new import_bignumber.BigNumber(
|
|
342
|
+
val.dividedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).toFixed(units)
|
|
346
343
|
);
|
|
344
|
+
var planckToUnit = (val, units) => {
|
|
345
|
+
const bigIntVal = BigInt(val);
|
|
346
|
+
const divisor = BigInt(10) ** BigInt(units);
|
|
347
|
+
const integerPart = bigIntVal / divisor;
|
|
348
|
+
const fractionalPart = bigIntVal % divisor;
|
|
349
|
+
const fractionalStr = fractionalPart.toString().padStart(units, "0");
|
|
350
|
+
return `${integerPart}.${fractionalStr}`;
|
|
351
|
+
};
|
|
347
352
|
var unitToPlanck = (val, units) => {
|
|
348
|
-
const init = new
|
|
349
|
-
return (!init.isNaN() ? init : new
|
|
353
|
+
const init = new import_bignumber.BigNumber(!val.length || !val ? "0" : val);
|
|
354
|
+
return (!init.isNaN() ? init : new import_bignumber.BigNumber(0)).multipliedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).integerValue();
|
|
350
355
|
};
|
|
351
356
|
var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
352
357
|
var snakeToCamel = (str) => str.toLowerCase().replace(
|
|
@@ -498,64 +503,6 @@ var makeCancelable = (promise) => {
|
|
|
498
503
|
}
|
|
499
504
|
};
|
|
500
505
|
};
|
|
501
|
-
var getSiValue = (si2) => new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(si2));
|
|
502
|
-
var si = [
|
|
503
|
-
{ value: getSiValue(24), symbol: "y", isMil: true },
|
|
504
|
-
{ value: getSiValue(21), symbol: "z", isMil: true },
|
|
505
|
-
{ value: getSiValue(18), symbol: "a", isMil: true },
|
|
506
|
-
{ value: getSiValue(15), symbol: "f", isMil: true },
|
|
507
|
-
{ value: getSiValue(12), symbol: "p", isMil: true },
|
|
508
|
-
{ value: getSiValue(9), symbol: "n", isMil: true },
|
|
509
|
-
{ value: getSiValue(6), symbol: "\u03BC", isMil: true },
|
|
510
|
-
{ value: getSiValue(3), symbol: "m", isMil: true },
|
|
511
|
-
{ value: new import_bignumber2.BigNumber(1), symbol: "" },
|
|
512
|
-
{ value: getSiValue(3), symbol: "k" },
|
|
513
|
-
{ value: getSiValue(6), symbol: "M" },
|
|
514
|
-
{ value: getSiValue(9), symbol: "G" },
|
|
515
|
-
{ value: getSiValue(12), symbol: "T" },
|
|
516
|
-
{ value: getSiValue(15), symbol: "P" },
|
|
517
|
-
{ value: getSiValue(18), symbol: "E" },
|
|
518
|
-
{ value: getSiValue(21), symbol: "Y" },
|
|
519
|
-
{ value: getSiValue(24), symbol: "Z" }
|
|
520
|
-
];
|
|
521
|
-
var allowedSymbols = si.map((s) => s.symbol).join(", ").replace(", ,", ",");
|
|
522
|
-
var floats = new RegExp("^[+]?[0-9]*[.,]{1}[0-9]*$");
|
|
523
|
-
var ints = new RegExp("^[+]?[0-9]+$");
|
|
524
|
-
var alphaFloats = new RegExp(
|
|
525
|
-
"^[+]?[0-9]*[.,]{1}[0-9]*[" + allowedSymbols + "]{1}$"
|
|
526
|
-
);
|
|
527
|
-
var alphaInts = new RegExp("^[+]?[0-9]*[" + allowedSymbols + "]{1}$");
|
|
528
|
-
var evalUnits = (input, chainDecimals) => {
|
|
529
|
-
input = input && input.replace("+", "");
|
|
530
|
-
if (!floats.test(input) && !ints.test(input) && !alphaInts.test(input) && !alphaFloats.test(input)) {
|
|
531
|
-
return [null, "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)" /* GIBBERISH */];
|
|
532
|
-
}
|
|
533
|
-
const symbol = input.replace(/[0-9.,]/g, "");
|
|
534
|
-
const siVal = si.find((s) => s.symbol === symbol);
|
|
535
|
-
const numberStr = input.replace(symbol, "").replace(",", ".");
|
|
536
|
-
let numeric = new import_bignumber2.BigNumber(0);
|
|
537
|
-
if (!siVal) {
|
|
538
|
-
return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
|
|
539
|
-
}
|
|
540
|
-
const decimalsBn = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(chainDecimals));
|
|
541
|
-
const containDecimal = numberStr.includes(".");
|
|
542
|
-
const [decPart, fracPart] = numberStr.split(".");
|
|
543
|
-
const fracDecimals = fracPart?.length || 0;
|
|
544
|
-
const fracExp = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(fracDecimals));
|
|
545
|
-
numeric = containDecimal ? new import_bignumber2.BigNumber(
|
|
546
|
-
new import_bignumber2.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber2.BigNumber(fracPart))
|
|
547
|
-
) : new import_bignumber2.BigNumber(new import_bignumber2.BigNumber(numberStr));
|
|
548
|
-
numeric = numeric.multipliedBy(decimalsBn);
|
|
549
|
-
if (containDecimal) {
|
|
550
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
|
|
551
|
-
} else {
|
|
552
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
|
|
553
|
-
}
|
|
554
|
-
if (numeric.eq(new import_bignumber2.BigNumber(0))) {
|
|
555
|
-
return [null, "You cannot send 0 funds" /* ZERO */];
|
|
556
|
-
}
|
|
557
|
-
return [numeric, "" /* SUCCESS */];
|
|
558
|
-
};
|
|
559
506
|
var transformToBaseUnit = (estFee, chainDecimals) => {
|
|
560
507
|
const t = estFee.length - chainDecimals;
|
|
561
508
|
let s = "";
|
|
@@ -598,7 +545,7 @@ var mergeDeep = (target, ...sources) => {
|
|
|
598
545
|
}
|
|
599
546
|
return mergeDeep(target, ...sources);
|
|
600
547
|
};
|
|
601
|
-
var stringToBigNumber = (value) => new
|
|
548
|
+
var stringToBigNumber = (value) => new import_bignumber.BigNumber(rmCommas(value));
|
|
602
549
|
// Annotate the CommonJS export names for ESM import in node:
|
|
603
550
|
0 && (module.exports = {
|
|
604
551
|
addedTo,
|
|
@@ -610,12 +557,9 @@ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(valu
|
|
|
610
557
|
determinePoolDisplay,
|
|
611
558
|
ellipsisFn,
|
|
612
559
|
eqSet,
|
|
613
|
-
evalUnits,
|
|
614
560
|
extractUrlValue,
|
|
615
561
|
formatAccountSs58,
|
|
616
|
-
greaterThanZero,
|
|
617
562
|
inChrome,
|
|
618
|
-
isNotZero,
|
|
619
563
|
isSuperset,
|
|
620
564
|
isValidAddress,
|
|
621
565
|
isValidHttpUrl,
|
|
@@ -626,6 +570,7 @@ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(valu
|
|
|
626
570
|
minDecimalPlaces,
|
|
627
571
|
pageFromUri,
|
|
628
572
|
planckToUnit,
|
|
573
|
+
planckToUnitLegacy,
|
|
629
574
|
remToUnit,
|
|
630
575
|
removeHexPrefix,
|
|
631
576
|
removeVarFromUrlHash,
|
package/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58,
|
|
2
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay,
|
|
3
|
-
import 'bignumber.js';
|
|
1
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.cjs';
|
|
2
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, planckToUnitLegacy, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.cjs';
|
|
4
3
|
import '@w3ux/types';
|
|
4
|
+
import 'bignumber.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import './types.cjs';
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58,
|
|
2
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay,
|
|
3
|
-
import 'bignumber.js';
|
|
1
|
+
export { appendOr, appendOrEmpty, camelize, ellipsisFn, eqSet, formatAccountSs58, isSuperset, minDecimalPlaces, pageFromUri, removeHexPrefix, rmCommas, shuffle, withTimeout } from './base.js';
|
|
2
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, planckToUnitLegacy, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash } from './unit.js';
|
|
4
3
|
import '@w3ux/types';
|
|
4
|
+
import 'bignumber.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import './types.js';
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
import { BigNumber } from "bignumber.js";
|
|
3
2
|
import { AccountId } from "@polkadot-api/substrate-bindings";
|
|
4
3
|
var camelize = (str) => {
|
|
5
4
|
const convertToString = (string) => {
|
|
@@ -55,15 +54,15 @@ var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
|
55
54
|
return "..." + str.slice(amount);
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
|
-
var greaterThanZero = (val) => val.isGreaterThan(0);
|
|
59
|
-
var isNotZero = (val) => !val.isZero();
|
|
60
57
|
var minDecimalPlaces = (val, minDecimals) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
missingDecimals.
|
|
66
|
-
|
|
58
|
+
try {
|
|
59
|
+
const whole = BigInt(rmCommas(val).split(".")[0] || "0");
|
|
60
|
+
const decimals = val.split(".")[1] || "";
|
|
61
|
+
const missingDecimals = minDecimals - decimals.length;
|
|
62
|
+
return missingDecimals > 0 ? `${whole.toString()}.${decimals}${"0".repeat(missingDecimals)}` : val;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return "0";
|
|
65
|
+
}
|
|
67
66
|
};
|
|
68
67
|
var pageFromUri = (pathname, fallback) => {
|
|
69
68
|
const lastUriItem = pathname.substring(pathname.lastIndexOf("/") + 1);
|
|
@@ -154,7 +153,7 @@ function isFunction(value) {
|
|
|
154
153
|
function invalidFallback() {
|
|
155
154
|
return Number.NaN;
|
|
156
155
|
}
|
|
157
|
-
var
|
|
156
|
+
var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
|
|
158
157
|
|
|
159
158
|
// ../../node_modules/@polkadot/util/hex/toU8a.js
|
|
160
159
|
var CHR = "0123456789abcdef";
|
|
@@ -194,7 +193,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
|
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
// ../../node_modules/@polkadot/util/has.js
|
|
197
|
-
var hasBigInt = typeof
|
|
196
|
+
var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
|
|
198
197
|
var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
|
|
199
198
|
var hasProcess = typeof xglobal.process === "object";
|
|
200
199
|
|
|
@@ -263,15 +262,23 @@ function u8aUnwrapBytes(bytes) {
|
|
|
263
262
|
}
|
|
264
263
|
|
|
265
264
|
// src/unit.ts
|
|
266
|
-
import { BigNumber
|
|
265
|
+
import { BigNumber } from "bignumber.js";
|
|
267
266
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
268
267
|
var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
269
|
-
var
|
|
270
|
-
val.dividedBy(new
|
|
268
|
+
var planckToUnitLegacy = (val, units) => new BigNumber(
|
|
269
|
+
val.dividedBy(new BigNumber(10).exponentiatedBy(units)).toFixed(units)
|
|
271
270
|
);
|
|
271
|
+
var planckToUnit = (val, units) => {
|
|
272
|
+
const bigIntVal = BigInt(val);
|
|
273
|
+
const divisor = BigInt(10) ** BigInt(units);
|
|
274
|
+
const integerPart = bigIntVal / divisor;
|
|
275
|
+
const fractionalPart = bigIntVal % divisor;
|
|
276
|
+
const fractionalStr = fractionalPart.toString().padStart(units, "0");
|
|
277
|
+
return `${integerPart}.${fractionalStr}`;
|
|
278
|
+
};
|
|
272
279
|
var unitToPlanck = (val, units) => {
|
|
273
|
-
const init = new
|
|
274
|
-
return (!init.isNaN() ? init : new
|
|
280
|
+
const init = new BigNumber(!val.length || !val ? "0" : val);
|
|
281
|
+
return (!init.isNaN() ? init : new BigNumber(0)).multipliedBy(new BigNumber(10).exponentiatedBy(units)).integerValue();
|
|
275
282
|
};
|
|
276
283
|
var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
277
284
|
var snakeToCamel = (str) => str.toLowerCase().replace(
|
|
@@ -423,64 +430,6 @@ var makeCancelable = (promise) => {
|
|
|
423
430
|
}
|
|
424
431
|
};
|
|
425
432
|
};
|
|
426
|
-
var getSiValue = (si2) => new BigNumber2(10).pow(new BigNumber2(si2));
|
|
427
|
-
var si = [
|
|
428
|
-
{ value: getSiValue(24), symbol: "y", isMil: true },
|
|
429
|
-
{ value: getSiValue(21), symbol: "z", isMil: true },
|
|
430
|
-
{ value: getSiValue(18), symbol: "a", isMil: true },
|
|
431
|
-
{ value: getSiValue(15), symbol: "f", isMil: true },
|
|
432
|
-
{ value: getSiValue(12), symbol: "p", isMil: true },
|
|
433
|
-
{ value: getSiValue(9), symbol: "n", isMil: true },
|
|
434
|
-
{ value: getSiValue(6), symbol: "\u03BC", isMil: true },
|
|
435
|
-
{ value: getSiValue(3), symbol: "m", isMil: true },
|
|
436
|
-
{ value: new BigNumber2(1), symbol: "" },
|
|
437
|
-
{ value: getSiValue(3), symbol: "k" },
|
|
438
|
-
{ value: getSiValue(6), symbol: "M" },
|
|
439
|
-
{ value: getSiValue(9), symbol: "G" },
|
|
440
|
-
{ value: getSiValue(12), symbol: "T" },
|
|
441
|
-
{ value: getSiValue(15), symbol: "P" },
|
|
442
|
-
{ value: getSiValue(18), symbol: "E" },
|
|
443
|
-
{ value: getSiValue(21), symbol: "Y" },
|
|
444
|
-
{ value: getSiValue(24), symbol: "Z" }
|
|
445
|
-
];
|
|
446
|
-
var allowedSymbols = si.map((s) => s.symbol).join(", ").replace(", ,", ",");
|
|
447
|
-
var floats = new RegExp("^[+]?[0-9]*[.,]{1}[0-9]*$");
|
|
448
|
-
var ints = new RegExp("^[+]?[0-9]+$");
|
|
449
|
-
var alphaFloats = new RegExp(
|
|
450
|
-
"^[+]?[0-9]*[.,]{1}[0-9]*[" + allowedSymbols + "]{1}$"
|
|
451
|
-
);
|
|
452
|
-
var alphaInts = new RegExp("^[+]?[0-9]*[" + allowedSymbols + "]{1}$");
|
|
453
|
-
var evalUnits = (input, chainDecimals) => {
|
|
454
|
-
input = input && input.replace("+", "");
|
|
455
|
-
if (!floats.test(input) && !ints.test(input) && !alphaInts.test(input) && !alphaFloats.test(input)) {
|
|
456
|
-
return [null, "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)" /* GIBBERISH */];
|
|
457
|
-
}
|
|
458
|
-
const symbol = input.replace(/[0-9.,]/g, "");
|
|
459
|
-
const siVal = si.find((s) => s.symbol === symbol);
|
|
460
|
-
const numberStr = input.replace(symbol, "").replace(",", ".");
|
|
461
|
-
let numeric = new BigNumber2(0);
|
|
462
|
-
if (!siVal) {
|
|
463
|
-
return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
|
|
464
|
-
}
|
|
465
|
-
const decimalsBn = new BigNumber2(10).pow(new BigNumber2(chainDecimals));
|
|
466
|
-
const containDecimal = numberStr.includes(".");
|
|
467
|
-
const [decPart, fracPart] = numberStr.split(".");
|
|
468
|
-
const fracDecimals = fracPart?.length || 0;
|
|
469
|
-
const fracExp = new BigNumber2(10).pow(new BigNumber2(fracDecimals));
|
|
470
|
-
numeric = containDecimal ? new BigNumber2(
|
|
471
|
-
new BigNumber2(decPart).multipliedBy(fracExp).plus(new BigNumber2(fracPart))
|
|
472
|
-
) : new BigNumber2(new BigNumber2(numberStr));
|
|
473
|
-
numeric = numeric.multipliedBy(decimalsBn);
|
|
474
|
-
if (containDecimal) {
|
|
475
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
|
|
476
|
-
} else {
|
|
477
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
|
|
478
|
-
}
|
|
479
|
-
if (numeric.eq(new BigNumber2(0))) {
|
|
480
|
-
return [null, "You cannot send 0 funds" /* ZERO */];
|
|
481
|
-
}
|
|
482
|
-
return [numeric, "" /* SUCCESS */];
|
|
483
|
-
};
|
|
484
433
|
var transformToBaseUnit = (estFee, chainDecimals) => {
|
|
485
434
|
const t = estFee.length - chainDecimals;
|
|
486
435
|
let s = "";
|
|
@@ -523,7 +472,7 @@ var mergeDeep = (target, ...sources) => {
|
|
|
523
472
|
}
|
|
524
473
|
return mergeDeep(target, ...sources);
|
|
525
474
|
};
|
|
526
|
-
var stringToBigNumber = (value) => new
|
|
475
|
+
var stringToBigNumber = (value) => new BigNumber(rmCommas(value));
|
|
527
476
|
export {
|
|
528
477
|
addedTo,
|
|
529
478
|
appendOr,
|
|
@@ -534,12 +483,9 @@ export {
|
|
|
534
483
|
determinePoolDisplay,
|
|
535
484
|
ellipsisFn,
|
|
536
485
|
eqSet,
|
|
537
|
-
evalUnits,
|
|
538
486
|
extractUrlValue,
|
|
539
487
|
formatAccountSs58,
|
|
540
|
-
greaterThanZero,
|
|
541
488
|
inChrome,
|
|
542
|
-
isNotZero,
|
|
543
489
|
isSuperset,
|
|
544
490
|
isValidAddress,
|
|
545
491
|
isValidHttpUrl,
|
|
@@ -550,6 +496,7 @@ export {
|
|
|
550
496
|
minDecimalPlaces,
|
|
551
497
|
pageFromUri,
|
|
552
498
|
planckToUnit,
|
|
499
|
+
planckToUnitLegacy,
|
|
553
500
|
remToUnit,
|
|
554
501
|
removeHexPrefix,
|
|
555
502
|
removeVarFromUrlHash,
|
package/package.json
CHANGED
package/types.cjs
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -18,21 +14,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
18
14
|
|
|
19
15
|
// src/types.ts
|
|
20
16
|
var types_exports = {};
|
|
21
|
-
__export(types_exports, {
|
|
22
|
-
EvalMessages: () => EvalMessages
|
|
23
|
-
});
|
|
24
17
|
module.exports = __toCommonJS(types_exports);
|
|
25
|
-
var EvalMessages = /* @__PURE__ */ ((EvalMessages2) => {
|
|
26
|
-
EvalMessages2["GIBBERISH"] = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)";
|
|
27
|
-
EvalMessages2["ZERO"] = "You cannot send 0 funds";
|
|
28
|
-
EvalMessages2["SUCCESS"] = "";
|
|
29
|
-
EvalMessages2["SYMBOL_ERROR"] = "Provided symbol is not correct";
|
|
30
|
-
EvalMessages2["GENERAL_ERROR"] = "Check your input. Something went wrong";
|
|
31
|
-
return EvalMessages2;
|
|
32
|
-
})(EvalMessages || {});
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
EvalMessages
|
|
36
|
-
});
|
|
37
18
|
/* @license Copyright 2024 w3ux authors & contributors
|
|
38
19
|
SPDX-License-Identifier: GPL-3.0-only */
|
package/types.d.cts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
type AnyObject = any;
|
|
2
|
-
declare enum EvalMessages {
|
|
3
|
-
GIBBERISH = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)",
|
|
4
|
-
ZERO = "You cannot send 0 funds",
|
|
5
|
-
SUCCESS = "",
|
|
6
|
-
SYMBOL_ERROR = "Provided symbol is not correct",
|
|
7
|
-
GENERAL_ERROR = "Check your input. Something went wrong"
|
|
8
|
-
}
|
|
9
2
|
|
|
10
|
-
export {
|
|
3
|
+
export type { AnyObject };
|
package/types.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
type AnyObject = any;
|
|
2
|
-
declare enum EvalMessages {
|
|
3
|
-
GIBBERISH = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)",
|
|
4
|
-
ZERO = "You cannot send 0 funds",
|
|
5
|
-
SUCCESS = "",
|
|
6
|
-
SYMBOL_ERROR = "Provided symbol is not correct",
|
|
7
|
-
GENERAL_ERROR = "Check your input. Something went wrong"
|
|
8
|
-
}
|
|
9
2
|
|
|
10
|
-
export {
|
|
3
|
+
export type { AnyObject };
|
package/types.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
// src/types.ts
|
|
2
|
-
var EvalMessages = /* @__PURE__ */ ((EvalMessages2) => {
|
|
3
|
-
EvalMessages2["GIBBERISH"] = "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)";
|
|
4
|
-
EvalMessages2["ZERO"] = "You cannot send 0 funds";
|
|
5
|
-
EvalMessages2["SUCCESS"] = "";
|
|
6
|
-
EvalMessages2["SYMBOL_ERROR"] = "Provided symbol is not correct";
|
|
7
|
-
EvalMessages2["GENERAL_ERROR"] = "Check your input. Something went wrong";
|
|
8
|
-
return EvalMessages2;
|
|
9
|
-
})(EvalMessages || {});
|
|
10
|
-
export {
|
|
11
|
-
EvalMessages
|
|
12
|
-
};
|
|
13
1
|
/* @license Copyright 2024 w3ux authors & contributors
|
|
14
2
|
SPDX-License-Identifier: GPL-3.0-only */
|
package/unit.cjs
CHANGED
|
@@ -33,7 +33,6 @@ __export(unit_exports, {
|
|
|
33
33
|
applyWidthAsPadding: () => applyWidthAsPadding,
|
|
34
34
|
capitalizeFirstLetter: () => capitalizeFirstLetter,
|
|
35
35
|
determinePoolDisplay: () => determinePoolDisplay,
|
|
36
|
-
evalUnits: () => evalUnits,
|
|
37
36
|
extractUrlValue: () => extractUrlValue,
|
|
38
37
|
inChrome: () => inChrome,
|
|
39
38
|
isValidAddress: () => isValidAddress,
|
|
@@ -43,6 +42,7 @@ __export(unit_exports, {
|
|
|
43
42
|
matchedProperties: () => matchedProperties,
|
|
44
43
|
mergeDeep: () => mergeDeep,
|
|
45
44
|
planckToUnit: () => planckToUnit,
|
|
45
|
+
planckToUnitLegacy: () => planckToUnitLegacy,
|
|
46
46
|
remToUnit: () => remToUnit,
|
|
47
47
|
removeVarFromUrlHash: () => removeVarFromUrlHash,
|
|
48
48
|
removedFrom: () => removedFrom,
|
|
@@ -96,7 +96,7 @@ function isFunction(value) {
|
|
|
96
96
|
function invalidFallback() {
|
|
97
97
|
return Number.NaN;
|
|
98
98
|
}
|
|
99
|
-
var
|
|
99
|
+
var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
|
|
100
100
|
|
|
101
101
|
// ../../node_modules/@polkadot/util/hex/toU8a.js
|
|
102
102
|
var CHR = "0123456789abcdef";
|
|
@@ -136,7 +136,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
// ../../node_modules/@polkadot/util/has.js
|
|
139
|
-
var hasBigInt = typeof
|
|
139
|
+
var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
|
|
140
140
|
var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
|
|
141
141
|
var hasProcess = typeof xglobal.process === "object";
|
|
142
142
|
|
|
@@ -205,10 +205,9 @@ function u8aUnwrapBytes(bytes) {
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
// src/unit.ts
|
|
208
|
-
var
|
|
208
|
+
var import_bignumber = require("bignumber.js");
|
|
209
209
|
|
|
210
210
|
// src/base.ts
|
|
211
|
-
var import_bignumber = require("bignumber.js");
|
|
212
211
|
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
213
212
|
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
214
213
|
const half = str.length / 2;
|
|
@@ -241,12 +240,20 @@ var rmCommas = (val) => val.replace(/,/g, "");
|
|
|
241
240
|
// src/unit.ts
|
|
242
241
|
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
243
242
|
var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
244
|
-
var
|
|
245
|
-
val.dividedBy(new
|
|
243
|
+
var planckToUnitLegacy = (val, units) => new import_bignumber.BigNumber(
|
|
244
|
+
val.dividedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).toFixed(units)
|
|
246
245
|
);
|
|
246
|
+
var planckToUnit = (val, units) => {
|
|
247
|
+
const bigIntVal = BigInt(val);
|
|
248
|
+
const divisor = BigInt(10) ** BigInt(units);
|
|
249
|
+
const integerPart = bigIntVal / divisor;
|
|
250
|
+
const fractionalPart = bigIntVal % divisor;
|
|
251
|
+
const fractionalStr = fractionalPart.toString().padStart(units, "0");
|
|
252
|
+
return `${integerPart}.${fractionalStr}`;
|
|
253
|
+
};
|
|
247
254
|
var unitToPlanck = (val, units) => {
|
|
248
|
-
const init = new
|
|
249
|
-
return (!init.isNaN() ? init : new
|
|
255
|
+
const init = new import_bignumber.BigNumber(!val.length || !val ? "0" : val);
|
|
256
|
+
return (!init.isNaN() ? init : new import_bignumber.BigNumber(0)).multipliedBy(new import_bignumber.BigNumber(10).exponentiatedBy(units)).integerValue();
|
|
250
257
|
};
|
|
251
258
|
var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
252
259
|
var snakeToCamel = (str) => str.toLowerCase().replace(
|
|
@@ -398,64 +405,6 @@ var makeCancelable = (promise) => {
|
|
|
398
405
|
}
|
|
399
406
|
};
|
|
400
407
|
};
|
|
401
|
-
var getSiValue = (si2) => new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(si2));
|
|
402
|
-
var si = [
|
|
403
|
-
{ value: getSiValue(24), symbol: "y", isMil: true },
|
|
404
|
-
{ value: getSiValue(21), symbol: "z", isMil: true },
|
|
405
|
-
{ value: getSiValue(18), symbol: "a", isMil: true },
|
|
406
|
-
{ value: getSiValue(15), symbol: "f", isMil: true },
|
|
407
|
-
{ value: getSiValue(12), symbol: "p", isMil: true },
|
|
408
|
-
{ value: getSiValue(9), symbol: "n", isMil: true },
|
|
409
|
-
{ value: getSiValue(6), symbol: "\u03BC", isMil: true },
|
|
410
|
-
{ value: getSiValue(3), symbol: "m", isMil: true },
|
|
411
|
-
{ value: new import_bignumber2.BigNumber(1), symbol: "" },
|
|
412
|
-
{ value: getSiValue(3), symbol: "k" },
|
|
413
|
-
{ value: getSiValue(6), symbol: "M" },
|
|
414
|
-
{ value: getSiValue(9), symbol: "G" },
|
|
415
|
-
{ value: getSiValue(12), symbol: "T" },
|
|
416
|
-
{ value: getSiValue(15), symbol: "P" },
|
|
417
|
-
{ value: getSiValue(18), symbol: "E" },
|
|
418
|
-
{ value: getSiValue(21), symbol: "Y" },
|
|
419
|
-
{ value: getSiValue(24), symbol: "Z" }
|
|
420
|
-
];
|
|
421
|
-
var allowedSymbols = si.map((s) => s.symbol).join(", ").replace(", ,", ",");
|
|
422
|
-
var floats = new RegExp("^[+]?[0-9]*[.,]{1}[0-9]*$");
|
|
423
|
-
var ints = new RegExp("^[+]?[0-9]+$");
|
|
424
|
-
var alphaFloats = new RegExp(
|
|
425
|
-
"^[+]?[0-9]*[.,]{1}[0-9]*[" + allowedSymbols + "]{1}$"
|
|
426
|
-
);
|
|
427
|
-
var alphaInts = new RegExp("^[+]?[0-9]*[" + allowedSymbols + "]{1}$");
|
|
428
|
-
var evalUnits = (input, chainDecimals) => {
|
|
429
|
-
input = input && input.replace("+", "");
|
|
430
|
-
if (!floats.test(input) && !ints.test(input) && !alphaInts.test(input) && !alphaFloats.test(input)) {
|
|
431
|
-
return [null, "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)" /* GIBBERISH */];
|
|
432
|
-
}
|
|
433
|
-
const symbol = input.replace(/[0-9.,]/g, "");
|
|
434
|
-
const siVal = si.find((s) => s.symbol === symbol);
|
|
435
|
-
const numberStr = input.replace(symbol, "").replace(",", ".");
|
|
436
|
-
let numeric = new import_bignumber2.BigNumber(0);
|
|
437
|
-
if (!siVal) {
|
|
438
|
-
return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
|
|
439
|
-
}
|
|
440
|
-
const decimalsBn = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(chainDecimals));
|
|
441
|
-
const containDecimal = numberStr.includes(".");
|
|
442
|
-
const [decPart, fracPart] = numberStr.split(".");
|
|
443
|
-
const fracDecimals = fracPart?.length || 0;
|
|
444
|
-
const fracExp = new import_bignumber2.BigNumber(10).pow(new import_bignumber2.BigNumber(fracDecimals));
|
|
445
|
-
numeric = containDecimal ? new import_bignumber2.BigNumber(
|
|
446
|
-
new import_bignumber2.BigNumber(decPart).multipliedBy(fracExp).plus(new import_bignumber2.BigNumber(fracPart))
|
|
447
|
-
) : new import_bignumber2.BigNumber(new import_bignumber2.BigNumber(numberStr));
|
|
448
|
-
numeric = numeric.multipliedBy(decimalsBn);
|
|
449
|
-
if (containDecimal) {
|
|
450
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
|
|
451
|
-
} else {
|
|
452
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
|
|
453
|
-
}
|
|
454
|
-
if (numeric.eq(new import_bignumber2.BigNumber(0))) {
|
|
455
|
-
return [null, "You cannot send 0 funds" /* ZERO */];
|
|
456
|
-
}
|
|
457
|
-
return [numeric, "" /* SUCCESS */];
|
|
458
|
-
};
|
|
459
408
|
var transformToBaseUnit = (estFee, chainDecimals) => {
|
|
460
409
|
const t = estFee.length - chainDecimals;
|
|
461
410
|
let s = "";
|
|
@@ -498,14 +447,13 @@ var mergeDeep = (target, ...sources) => {
|
|
|
498
447
|
}
|
|
499
448
|
return mergeDeep(target, ...sources);
|
|
500
449
|
};
|
|
501
|
-
var stringToBigNumber = (value) => new
|
|
450
|
+
var stringToBigNumber = (value) => new import_bignumber.BigNumber(rmCommas(value));
|
|
502
451
|
// Annotate the CommonJS export names for ESM import in node:
|
|
503
452
|
0 && (module.exports = {
|
|
504
453
|
addedTo,
|
|
505
454
|
applyWidthAsPadding,
|
|
506
455
|
capitalizeFirstLetter,
|
|
507
456
|
determinePoolDisplay,
|
|
508
|
-
evalUnits,
|
|
509
457
|
extractUrlValue,
|
|
510
458
|
inChrome,
|
|
511
459
|
isValidAddress,
|
|
@@ -515,6 +463,7 @@ var stringToBigNumber = (value) => new import_bignumber2.BigNumber(rmCommas(valu
|
|
|
515
463
|
matchedProperties,
|
|
516
464
|
mergeDeep,
|
|
517
465
|
planckToUnit,
|
|
466
|
+
planckToUnitLegacy,
|
|
518
467
|
remToUnit,
|
|
519
468
|
removeVarFromUrlHash,
|
|
520
469
|
removedFrom,
|
package/unit.d.cts
CHANGED
|
@@ -9,13 +9,21 @@ import { AnyJson } from '@w3ux/types';
|
|
|
9
9
|
*/
|
|
10
10
|
declare const remToUnit: (rem: string) => number;
|
|
11
11
|
/**
|
|
12
|
-
* @name
|
|
12
|
+
* @name planckToUnitLegacy
|
|
13
13
|
* @summary convert planck to the token unit.
|
|
14
14
|
* @description
|
|
15
15
|
* Converts an on chain balance value in BigNumber planck to a decimal value in token unit. (1 token
|
|
16
16
|
* = 10^units planck).
|
|
17
17
|
*/
|
|
18
|
-
declare const
|
|
18
|
+
declare const planckToUnitLegacy: (val: BigNumber, units: number) => BigNumber;
|
|
19
|
+
/**
|
|
20
|
+
* @name planckToUnit
|
|
21
|
+
* @summary convert planck to the token unit.
|
|
22
|
+
* @description
|
|
23
|
+
* Converts an on-chain balance value from BigInt planck to a decimal value in token unit.
|
|
24
|
+
* (1 token = 10^units planck).
|
|
25
|
+
*/
|
|
26
|
+
declare const planckToUnit: (val: bigint | string, units: number) => string;
|
|
19
27
|
/**
|
|
20
28
|
* @name unitToPlanck
|
|
21
29
|
* @summary Convert the token unit to planck.
|
|
@@ -128,15 +136,6 @@ declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
|
128
136
|
promise: Promise<unknown>;
|
|
129
137
|
cancel: () => void;
|
|
130
138
|
};
|
|
131
|
-
/**
|
|
132
|
-
* A function that identifes integer/float(comma or dot)/expressions (such as 1k)
|
|
133
|
-
* and converts to actual value (or reports an error).
|
|
134
|
-
* @param {string} input
|
|
135
|
-
* @returns {[number | null, string]} an array of 2 items
|
|
136
|
-
* the first is the actual calculated number (or null if none) while
|
|
137
|
-
* the second is the message that should appear in case of error
|
|
138
|
-
*/
|
|
139
|
-
declare const evalUnits: (input: string, chainDecimals: number) => [BigNumber | null, string];
|
|
140
139
|
/**
|
|
141
140
|
* The transformToBaseUnit function is used to transform a given estimated
|
|
142
141
|
* fee value from its current representation to its base unit representation,
|
|
@@ -168,4 +167,4 @@ declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObje
|
|
|
168
167
|
*/
|
|
169
168
|
declare const stringToBigNumber: (value: string) => BigNumber;
|
|
170
169
|
|
|
171
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay,
|
|
170
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, planckToUnitLegacy, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash };
|
package/unit.d.ts
CHANGED
|
@@ -9,13 +9,21 @@ import { AnyJson } from '@w3ux/types';
|
|
|
9
9
|
*/
|
|
10
10
|
declare const remToUnit: (rem: string) => number;
|
|
11
11
|
/**
|
|
12
|
-
* @name
|
|
12
|
+
* @name planckToUnitLegacy
|
|
13
13
|
* @summary convert planck to the token unit.
|
|
14
14
|
* @description
|
|
15
15
|
* Converts an on chain balance value in BigNumber planck to a decimal value in token unit. (1 token
|
|
16
16
|
* = 10^units planck).
|
|
17
17
|
*/
|
|
18
|
-
declare const
|
|
18
|
+
declare const planckToUnitLegacy: (val: BigNumber, units: number) => BigNumber;
|
|
19
|
+
/**
|
|
20
|
+
* @name planckToUnit
|
|
21
|
+
* @summary convert planck to the token unit.
|
|
22
|
+
* @description
|
|
23
|
+
* Converts an on-chain balance value from BigInt planck to a decimal value in token unit.
|
|
24
|
+
* (1 token = 10^units planck).
|
|
25
|
+
*/
|
|
26
|
+
declare const planckToUnit: (val: bigint | string, units: number) => string;
|
|
19
27
|
/**
|
|
20
28
|
* @name unitToPlanck
|
|
21
29
|
* @summary Convert the token unit to planck.
|
|
@@ -128,15 +136,6 @@ declare const makeCancelable: (promise: Promise<AnyObject>) => {
|
|
|
128
136
|
promise: Promise<unknown>;
|
|
129
137
|
cancel: () => void;
|
|
130
138
|
};
|
|
131
|
-
/**
|
|
132
|
-
* A function that identifes integer/float(comma or dot)/expressions (such as 1k)
|
|
133
|
-
* and converts to actual value (or reports an error).
|
|
134
|
-
* @param {string} input
|
|
135
|
-
* @returns {[number | null, string]} an array of 2 items
|
|
136
|
-
* the first is the actual calculated number (or null if none) while
|
|
137
|
-
* the second is the message that should appear in case of error
|
|
138
|
-
*/
|
|
139
|
-
declare const evalUnits: (input: string, chainDecimals: number) => [BigNumber | null, string];
|
|
140
139
|
/**
|
|
141
140
|
* The transformToBaseUnit function is used to transform a given estimated
|
|
142
141
|
* fee value from its current representation to its base unit representation,
|
|
@@ -168,4 +167,4 @@ declare const mergeDeep: (target: AnyObject, ...sources: AnyObject[]) => AnyObje
|
|
|
168
167
|
*/
|
|
169
168
|
declare const stringToBigNumber: (value: string) => BigNumber;
|
|
170
169
|
|
|
171
|
-
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay,
|
|
170
|
+
export { addedTo, applyWidthAsPadding, capitalizeFirstLetter, determinePoolDisplay, extractUrlValue, inChrome, isValidAddress, isValidHttpUrl, localStorageOrDefault, makeCancelable, matchedProperties, mergeDeep, planckToUnit, planckToUnitLegacy, remToUnit, removeVarFromUrlHash, removedFrom, setStateWithRef, snakeToCamel, sortWithNull, stringToBigNumber, transformToBaseUnit, unescape, unimplemented, unitToPlanck, varToUrlHash };
|
package/unit.js
CHANGED
|
@@ -36,7 +36,7 @@ function isFunction(value) {
|
|
|
36
36
|
function invalidFallback() {
|
|
37
37
|
return Number.NaN;
|
|
38
38
|
}
|
|
39
|
-
var
|
|
39
|
+
var BigInt2 = /* @__PURE__ */ extractGlobal("BigInt", invalidFallback);
|
|
40
40
|
|
|
41
41
|
// ../../node_modules/@polkadot/util/hex/toU8a.js
|
|
42
42
|
var CHR = "0123456789abcdef";
|
|
@@ -76,7 +76,7 @@ function isHex(value, bitLength = -1, ignoreLength) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// ../../node_modules/@polkadot/util/has.js
|
|
79
|
-
var hasBigInt = typeof
|
|
79
|
+
var hasBigInt = typeof BigInt2 === "function" && typeof BigInt2.asIntN === "function";
|
|
80
80
|
var hasBuffer = typeof xglobal.Buffer === "function" && typeof xglobal.Buffer.isBuffer === "function";
|
|
81
81
|
var hasProcess = typeof xglobal.process === "object";
|
|
82
82
|
|
|
@@ -145,10 +145,9 @@ function u8aUnwrapBytes(bytes) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// src/unit.ts
|
|
148
|
-
import { BigNumber
|
|
148
|
+
import { BigNumber } from "bignumber.js";
|
|
149
149
|
|
|
150
150
|
// src/base.ts
|
|
151
|
-
import { BigNumber } from "bignumber.js";
|
|
152
151
|
import { AccountId } from "@polkadot-api/substrate-bindings";
|
|
153
152
|
var ellipsisFn = (str, amount = 6, position = "center") => {
|
|
154
153
|
const half = str.length / 2;
|
|
@@ -181,12 +180,20 @@ var rmCommas = (val) => val.replace(/,/g, "");
|
|
|
181
180
|
// src/unit.ts
|
|
182
181
|
import { AccountId as AccountId2 } from "@polkadot-api/substrate-bindings";
|
|
183
182
|
var remToUnit = (rem) => Number(rem.slice(0, rem.length - 3)) * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
184
|
-
var
|
|
185
|
-
val.dividedBy(new
|
|
183
|
+
var planckToUnitLegacy = (val, units) => new BigNumber(
|
|
184
|
+
val.dividedBy(new BigNumber(10).exponentiatedBy(units)).toFixed(units)
|
|
186
185
|
);
|
|
186
|
+
var planckToUnit = (val, units) => {
|
|
187
|
+
const bigIntVal = BigInt(val);
|
|
188
|
+
const divisor = BigInt(10) ** BigInt(units);
|
|
189
|
+
const integerPart = bigIntVal / divisor;
|
|
190
|
+
const fractionalPart = bigIntVal % divisor;
|
|
191
|
+
const fractionalStr = fractionalPart.toString().padStart(units, "0");
|
|
192
|
+
return `${integerPart}.${fractionalStr}`;
|
|
193
|
+
};
|
|
187
194
|
var unitToPlanck = (val, units) => {
|
|
188
|
-
const init = new
|
|
189
|
-
return (!init.isNaN() ? init : new
|
|
195
|
+
const init = new BigNumber(!val.length || !val ? "0" : val);
|
|
196
|
+
return (!init.isNaN() ? init : new BigNumber(0)).multipliedBy(new BigNumber(10).exponentiatedBy(units)).integerValue();
|
|
190
197
|
};
|
|
191
198
|
var capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
192
199
|
var snakeToCamel = (str) => str.toLowerCase().replace(
|
|
@@ -338,64 +345,6 @@ var makeCancelable = (promise) => {
|
|
|
338
345
|
}
|
|
339
346
|
};
|
|
340
347
|
};
|
|
341
|
-
var getSiValue = (si2) => new BigNumber2(10).pow(new BigNumber2(si2));
|
|
342
|
-
var si = [
|
|
343
|
-
{ value: getSiValue(24), symbol: "y", isMil: true },
|
|
344
|
-
{ value: getSiValue(21), symbol: "z", isMil: true },
|
|
345
|
-
{ value: getSiValue(18), symbol: "a", isMil: true },
|
|
346
|
-
{ value: getSiValue(15), symbol: "f", isMil: true },
|
|
347
|
-
{ value: getSiValue(12), symbol: "p", isMil: true },
|
|
348
|
-
{ value: getSiValue(9), symbol: "n", isMil: true },
|
|
349
|
-
{ value: getSiValue(6), symbol: "\u03BC", isMil: true },
|
|
350
|
-
{ value: getSiValue(3), symbol: "m", isMil: true },
|
|
351
|
-
{ value: new BigNumber2(1), symbol: "" },
|
|
352
|
-
{ value: getSiValue(3), symbol: "k" },
|
|
353
|
-
{ value: getSiValue(6), symbol: "M" },
|
|
354
|
-
{ value: getSiValue(9), symbol: "G" },
|
|
355
|
-
{ value: getSiValue(12), symbol: "T" },
|
|
356
|
-
{ value: getSiValue(15), symbol: "P" },
|
|
357
|
-
{ value: getSiValue(18), symbol: "E" },
|
|
358
|
-
{ value: getSiValue(21), symbol: "Y" },
|
|
359
|
-
{ value: getSiValue(24), symbol: "Z" }
|
|
360
|
-
];
|
|
361
|
-
var allowedSymbols = si.map((s) => s.symbol).join(", ").replace(", ,", ",");
|
|
362
|
-
var floats = new RegExp("^[+]?[0-9]*[.,]{1}[0-9]*$");
|
|
363
|
-
var ints = new RegExp("^[+]?[0-9]+$");
|
|
364
|
-
var alphaFloats = new RegExp(
|
|
365
|
-
"^[+]?[0-9]*[.,]{1}[0-9]*[" + allowedSymbols + "]{1}$"
|
|
366
|
-
);
|
|
367
|
-
var alphaInts = new RegExp("^[+]?[0-9]*[" + allowedSymbols + "]{1}$");
|
|
368
|
-
var evalUnits = (input, chainDecimals) => {
|
|
369
|
-
input = input && input.replace("+", "");
|
|
370
|
-
if (!floats.test(input) && !ints.test(input) && !alphaInts.test(input) && !alphaFloats.test(input)) {
|
|
371
|
-
return [null, "Input is not correct. Use numbers, floats or expression (e.g. 1k, 1.3m)" /* GIBBERISH */];
|
|
372
|
-
}
|
|
373
|
-
const symbol = input.replace(/[0-9.,]/g, "");
|
|
374
|
-
const siVal = si.find((s) => s.symbol === symbol);
|
|
375
|
-
const numberStr = input.replace(symbol, "").replace(",", ".");
|
|
376
|
-
let numeric = new BigNumber2(0);
|
|
377
|
-
if (!siVal) {
|
|
378
|
-
return [null, "Provided symbol is not correct" /* SYMBOL_ERROR */];
|
|
379
|
-
}
|
|
380
|
-
const decimalsBn = new BigNumber2(10).pow(new BigNumber2(chainDecimals));
|
|
381
|
-
const containDecimal = numberStr.includes(".");
|
|
382
|
-
const [decPart, fracPart] = numberStr.split(".");
|
|
383
|
-
const fracDecimals = fracPart?.length || 0;
|
|
384
|
-
const fracExp = new BigNumber2(10).pow(new BigNumber2(fracDecimals));
|
|
385
|
-
numeric = containDecimal ? new BigNumber2(
|
|
386
|
-
new BigNumber2(decPart).multipliedBy(fracExp).plus(new BigNumber2(fracPart))
|
|
387
|
-
) : new BigNumber2(new BigNumber2(numberStr));
|
|
388
|
-
numeric = numeric.multipliedBy(decimalsBn);
|
|
389
|
-
if (containDecimal) {
|
|
390
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value).dividedBy(fracExp) : numeric.multipliedBy(siVal.value).dividedBy(fracExp);
|
|
391
|
-
} else {
|
|
392
|
-
numeric = siVal.isMil ? numeric.dividedBy(siVal.value) : numeric.multipliedBy(siVal.value);
|
|
393
|
-
}
|
|
394
|
-
if (numeric.eq(new BigNumber2(0))) {
|
|
395
|
-
return [null, "You cannot send 0 funds" /* ZERO */];
|
|
396
|
-
}
|
|
397
|
-
return [numeric, "" /* SUCCESS */];
|
|
398
|
-
};
|
|
399
348
|
var transformToBaseUnit = (estFee, chainDecimals) => {
|
|
400
349
|
const t = estFee.length - chainDecimals;
|
|
401
350
|
let s = "";
|
|
@@ -438,13 +387,12 @@ var mergeDeep = (target, ...sources) => {
|
|
|
438
387
|
}
|
|
439
388
|
return mergeDeep(target, ...sources);
|
|
440
389
|
};
|
|
441
|
-
var stringToBigNumber = (value) => new
|
|
390
|
+
var stringToBigNumber = (value) => new BigNumber(rmCommas(value));
|
|
442
391
|
export {
|
|
443
392
|
addedTo,
|
|
444
393
|
applyWidthAsPadding,
|
|
445
394
|
capitalizeFirstLetter,
|
|
446
395
|
determinePoolDisplay,
|
|
447
|
-
evalUnits,
|
|
448
396
|
extractUrlValue,
|
|
449
397
|
inChrome,
|
|
450
398
|
isValidAddress,
|
|
@@ -454,6 +402,7 @@ export {
|
|
|
454
402
|
matchedProperties,
|
|
455
403
|
mergeDeep,
|
|
456
404
|
planckToUnit,
|
|
405
|
+
planckToUnitLegacy,
|
|
457
406
|
remToUnit,
|
|
458
407
|
removeVarFromUrlHash,
|
|
459
408
|
removedFrom,
|