@swapkit/helpers 1.0.0-rc.75 → 1.0.0-rc.76
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/LICENSE +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +159 -158
- package/dist/index.es.js.map +1 -1
- package/package.json +7 -7
- package/src/helpers/asset.ts +1 -1
- package/src/modules/bigIntArithmetics.ts +13 -12
- package/src/modules/swapKitError.ts +1 -1
|
@@ -15,7 +15,8 @@ type AllowedNumberTypes = "bigint" | "number" | "string";
|
|
|
15
15
|
|
|
16
16
|
const DEFAULT_DECIMAL = 8;
|
|
17
17
|
const toMultiplier = (decimal: number) => 10n ** BigInt(decimal);
|
|
18
|
-
const decimalFromMultiplier = (multiplier: bigint) =>
|
|
18
|
+
const decimalFromMultiplier = (multiplier: bigint) =>
|
|
19
|
+
Math.log10(Number.parseFloat(multiplier.toString()));
|
|
19
20
|
|
|
20
21
|
export function formatBigIntToSafeValue({
|
|
21
22
|
value,
|
|
@@ -40,10 +41,10 @@ export function formatBigIntToSafeValue({
|
|
|
40
41
|
let decimalString = valueString.slice(-decimal);
|
|
41
42
|
|
|
42
43
|
// Check if we need to round up
|
|
43
|
-
if (parseInt(decimalString[bigIntDecimal]) >= 5) {
|
|
44
|
+
if (Number.parseInt(decimalString[bigIntDecimal]) >= 5) {
|
|
44
45
|
// Increment the last decimal place and slice off the rest
|
|
45
46
|
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(
|
|
46
|
-
parseInt(decimalString[bigIntDecimal - 1]) + 1
|
|
47
|
+
Number.parseInt(decimalString[bigIntDecimal - 1]) + 1
|
|
47
48
|
).toString()}`;
|
|
48
49
|
} else {
|
|
49
50
|
// Just slice off the extra digits
|
|
@@ -175,7 +176,7 @@ export class BigIntArithmetics {
|
|
|
175
176
|
const [int, dec] = this.getValue("string").split(".");
|
|
176
177
|
const integer = int || "";
|
|
177
178
|
const decimal = dec || "";
|
|
178
|
-
const valueLength = parseInt(integer) ? integer.length + decimal.length : decimal.length;
|
|
179
|
+
const valueLength = Number.parseInt(integer) ? integer.length + decimal.length : decimal.length;
|
|
179
180
|
|
|
180
181
|
if (valueLength <= significantDigits) {
|
|
181
182
|
return this.getValue("string");
|
|
@@ -185,14 +186,14 @@ export class BigIntArithmetics {
|
|
|
185
186
|
return integer.slice(0, significantDigits).padEnd(integer.length, "0");
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
if (parseInt(integer)) {
|
|
189
|
+
if (Number.parseInt(integer)) {
|
|
189
190
|
return `${integer}.${decimal.slice(0, significantDigits - integer.length)}`.padEnd(
|
|
190
191
|
significantDigits - integer.length,
|
|
191
192
|
"0",
|
|
192
193
|
);
|
|
193
194
|
}
|
|
194
195
|
|
|
195
|
-
const trimmedDecimal = parseInt(decimal);
|
|
196
|
+
const trimmedDecimal = Number.parseInt(decimal);
|
|
196
197
|
const slicedDecimal = `${trimmedDecimal}`.slice(0, significantDigits);
|
|
197
198
|
|
|
198
199
|
return `0.${slicedDecimal.padStart(
|
|
@@ -206,11 +207,11 @@ export class BigIntArithmetics {
|
|
|
206
207
|
const integer = int || "";
|
|
207
208
|
const decimal = dec || "";
|
|
208
209
|
|
|
209
|
-
if (parseInt(integer)) {
|
|
210
|
+
if (Number.parseInt(integer)) {
|
|
210
211
|
return `${integer}.${decimal.slice(0, fixedDigits)}`.padEnd(fixedDigits, "0");
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
const trimmedDecimal = parseInt(decimal);
|
|
214
|
+
const trimmedDecimal = Number.parseInt(decimal);
|
|
214
215
|
const slicedDecimal = `${trimmedDecimal}`.slice(0, fixedDigits);
|
|
215
216
|
|
|
216
217
|
return `0.${slicedDecimal.padStart(
|
|
@@ -249,8 +250,8 @@ export class BigIntArithmetics {
|
|
|
249
250
|
const parsedValue =
|
|
250
251
|
int || dec
|
|
251
252
|
? int === "0"
|
|
252
|
-
? `${parseFloat(`0.${dec}`)}`.replace(".", decimalSeparator)
|
|
253
|
-
: `${integer}${parseInt(dec) ? `${decimalSeparator}${dec.slice(0, decimal)}` : ""}`
|
|
253
|
+
? `${Number.parseFloat(`0.${dec}`)}`.replace(".", decimalSeparator)
|
|
254
|
+
: `${integer}${Number.parseInt(dec) ? `${decimalSeparator}${dec.slice(0, decimal)}` : ""}`
|
|
254
255
|
: "0.00";
|
|
255
256
|
|
|
256
257
|
return `${currencyPosition === "start" ? currency : ""}${parsedValue}${
|
|
@@ -275,10 +276,10 @@ export class BigIntArithmetics {
|
|
|
275
276
|
let decimalString = parsedValueString.slice(-decimalToUseForConversion);
|
|
276
277
|
|
|
277
278
|
// Check if we need to round up
|
|
278
|
-
if (parseInt(decimalString[bigIntDecimal]) >= 5) {
|
|
279
|
+
if (Number.parseInt(decimalString[bigIntDecimal]) >= 5) {
|
|
279
280
|
// Increment the last decimal place and slice off the rest
|
|
280
281
|
decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(
|
|
281
|
-
parseInt(decimalString[bigIntDecimal - 1]) + 1
|
|
282
|
+
Number.parseInt(decimalString[bigIntDecimal - 1]) + 1
|
|
282
283
|
).toString()}`;
|
|
283
284
|
} else {
|
|
284
285
|
// Just slice off the extra digits
|
|
@@ -7,6 +7,7 @@ const errorMessages = {
|
|
|
7
7
|
core_extend_error: 10003,
|
|
8
8
|
core_inbound_data_not_found: 10004,
|
|
9
9
|
core_approve_asset_address_or_from_not_found: 10005,
|
|
10
|
+
core_plugin_not_found: 10006,
|
|
10
11
|
core_chain_halted: 10099,
|
|
11
12
|
/**
|
|
12
13
|
* Core - Wallet Connection
|
|
@@ -31,7 +32,6 @@ const errorMessages = {
|
|
|
31
32
|
core_swap_contract_not_supported: 10205,
|
|
32
33
|
core_swap_transaction_error: 10206,
|
|
33
34
|
core_swap_quote_mode_not_supported: 10207,
|
|
34
|
-
core_swap_provider_not_found: 10208,
|
|
35
35
|
/**
|
|
36
36
|
* Core - Transaction
|
|
37
37
|
*/
|