@lightsparkdev/core 1.0.21 → 1.1.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.
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-Y3FWNVYS.js → chunk-XRYQNSG7.js} +157 -131
- package/dist/{index-9e41ffe5.d.ts → index-4698c2db.d.ts} +39 -75
- package/dist/index.cjs +189 -145
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -16
- package/dist/utils/index.cjs +158 -132
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +3 -3
- package/package.json +1 -1
- package/src/requester/Requester.ts +35 -14
- package/src/utils/currency.ts +96 -114
- package/src/utils/types.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
getLocalStorageConfigItem,
|
|
21
21
|
hexToBytes,
|
|
22
22
|
isBrowser,
|
|
23
|
-
isCurrencyAmount,
|
|
24
23
|
isCurrencyAmountObj,
|
|
25
24
|
isCurrencyMap,
|
|
26
25
|
isError,
|
|
@@ -28,6 +27,7 @@ import {
|
|
|
28
27
|
isErrorWithMessage,
|
|
29
28
|
isNode,
|
|
30
29
|
isNumber,
|
|
30
|
+
isSDKCurrencyAmount,
|
|
31
31
|
isTest,
|
|
32
32
|
isType,
|
|
33
33
|
isUint8Array,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
setLocalStorageBoolean,
|
|
44
44
|
sleep,
|
|
45
45
|
urlsafe_b64decode
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-XRYQNSG7.js";
|
|
47
47
|
|
|
48
48
|
// src/Logger.ts
|
|
49
49
|
var LoggingLevel = /* @__PURE__ */ ((LoggingLevel2) => {
|
|
@@ -582,7 +582,7 @@ var Requester = class {
|
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
584
|
const operation = operationMatch[2];
|
|
585
|
-
|
|
585
|
+
const payload = {
|
|
586
586
|
query: queryPayload,
|
|
587
587
|
variables,
|
|
588
588
|
operationName: operation
|
|
@@ -592,14 +592,19 @@ var Requester = class {
|
|
|
592
592
|
const baseHeaders = {
|
|
593
593
|
"Content-Type": "application/json",
|
|
594
594
|
"X-Lightspark-SDK": sdkUserAgent,
|
|
595
|
-
"User-Agent": browserUserAgent || sdkUserAgent
|
|
595
|
+
"User-Agent": browserUserAgent || sdkUserAgent,
|
|
596
|
+
"X-GraphQL-Operation": operation
|
|
596
597
|
};
|
|
597
598
|
const headers = skipAuth ? baseHeaders : await this.authProvider.addAuthHeaders(baseHeaders);
|
|
598
|
-
bodyData = await this.addSigningDataIfNeeded(
|
|
599
|
-
|
|
599
|
+
let bodyData = await this.addSigningDataIfNeeded(
|
|
600
|
+
payload,
|
|
600
601
|
headers,
|
|
601
602
|
signingNodeId
|
|
602
603
|
);
|
|
604
|
+
if (bodyData.length > 1024 && typeof CompressionStream != "undefined") {
|
|
605
|
+
bodyData = await compress(bodyData);
|
|
606
|
+
headers["Content-Encoding"] = "deflate";
|
|
607
|
+
}
|
|
603
608
|
let urlWithProtocol = this.baseUrl;
|
|
604
609
|
if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
|
|
605
610
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
@@ -613,7 +618,7 @@ var Requester = class {
|
|
|
613
618
|
const response = await fetch(url, {
|
|
614
619
|
method: "POST",
|
|
615
620
|
headers,
|
|
616
|
-
body:
|
|
621
|
+
body: bodyData
|
|
617
622
|
});
|
|
618
623
|
if (!response.ok) {
|
|
619
624
|
throw new LightsparkException_default(
|
|
@@ -640,8 +645,14 @@ var Requester = class {
|
|
|
640
645
|
return url.replace(/.*?:\/\//g, "");
|
|
641
646
|
}
|
|
642
647
|
async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
|
|
648
|
+
let TextEncoderImpl;
|
|
649
|
+
if (typeof TextEncoder === "undefined") {
|
|
650
|
+
TextEncoderImpl = (await import("text-encoding")).TextEncoder;
|
|
651
|
+
} else {
|
|
652
|
+
TextEncoderImpl = TextEncoder;
|
|
653
|
+
}
|
|
643
654
|
if (!signingNodeId) {
|
|
644
|
-
return queryPayload;
|
|
655
|
+
return new TextEncoderImpl().encode(JSON.stringify(queryPayload));
|
|
645
656
|
}
|
|
646
657
|
const query = queryPayload.query;
|
|
647
658
|
const variables = queryPayload.variables;
|
|
@@ -661,12 +672,6 @@ var Requester = class {
|
|
|
661
672
|
"Missing node of encrypted_signing_private_key"
|
|
662
673
|
);
|
|
663
674
|
}
|
|
664
|
-
let TextEncoderImpl;
|
|
665
|
-
if (typeof TextEncoder === "undefined") {
|
|
666
|
-
TextEncoderImpl = (await import("text-encoding")).TextEncoder;
|
|
667
|
-
} else {
|
|
668
|
-
TextEncoderImpl = TextEncoder;
|
|
669
|
-
}
|
|
670
675
|
const encodedPayload = new TextEncoderImpl().encode(
|
|
671
676
|
JSON.stringify(payload)
|
|
672
677
|
);
|
|
@@ -676,9 +681,22 @@ var Requester = class {
|
|
|
676
681
|
v: "1",
|
|
677
682
|
signature: encodedSignedPayload
|
|
678
683
|
});
|
|
679
|
-
return
|
|
684
|
+
return encodedPayload;
|
|
680
685
|
}
|
|
681
686
|
};
|
|
687
|
+
async function compress(data) {
|
|
688
|
+
const stream = new Blob([data]).stream();
|
|
689
|
+
const compressedStream = stream.pipeThrough(new CompressionStream("deflate"));
|
|
690
|
+
const reader = compressedStream.getReader();
|
|
691
|
+
const chunks = [];
|
|
692
|
+
let done, value;
|
|
693
|
+
while (!done) {
|
|
694
|
+
({ done, value } = await reader.read());
|
|
695
|
+
chunks.push(value);
|
|
696
|
+
}
|
|
697
|
+
const blob = new Blob(chunks);
|
|
698
|
+
return new Uint8Array(await blob.arrayBuffer());
|
|
699
|
+
}
|
|
682
700
|
var Requester_default = Requester;
|
|
683
701
|
export {
|
|
684
702
|
ConfigKeys,
|
|
@@ -718,7 +736,6 @@ export {
|
|
|
718
736
|
getLocalStorageConfigItem,
|
|
719
737
|
hexToBytes,
|
|
720
738
|
isBrowser,
|
|
721
|
-
isCurrencyAmount,
|
|
722
739
|
isCurrencyAmountObj,
|
|
723
740
|
isCurrencyMap,
|
|
724
741
|
isError,
|
|
@@ -726,6 +743,7 @@ export {
|
|
|
726
743
|
isErrorWithMessage,
|
|
727
744
|
isNode,
|
|
728
745
|
isNumber,
|
|
746
|
+
isSDKCurrencyAmount,
|
|
729
747
|
isTest,
|
|
730
748
|
isType,
|
|
731
749
|
isUint8Array,
|
package/dist/utils/index.cjs
CHANGED
|
@@ -50,7 +50,6 @@ __export(utils_exports, {
|
|
|
50
50
|
getLocalStorageConfigItem: () => getLocalStorageConfigItem,
|
|
51
51
|
hexToBytes: () => hexToBytes,
|
|
52
52
|
isBrowser: () => isBrowser,
|
|
53
|
-
isCurrencyAmount: () => isCurrencyAmount,
|
|
54
53
|
isCurrencyAmountObj: () => isCurrencyAmountObj,
|
|
55
54
|
isCurrencyMap: () => isCurrencyMap,
|
|
56
55
|
isError: () => isError,
|
|
@@ -58,6 +57,7 @@ __export(utils_exports, {
|
|
|
58
57
|
isErrorWithMessage: () => isErrorWithMessage,
|
|
59
58
|
isNode: () => isNode,
|
|
60
59
|
isNumber: () => isNumber,
|
|
60
|
+
isSDKCurrencyAmount: () => isSDKCurrencyAmount,
|
|
61
61
|
isTest: () => isTest,
|
|
62
62
|
isType: () => isType,
|
|
63
63
|
isUint8Array: () => isUint8Array,
|
|
@@ -470,102 +470,108 @@ function isNumber(value) {
|
|
|
470
470
|
|
|
471
471
|
// src/utils/currency.ts
|
|
472
472
|
var defaultCurrencyCode = "USD";
|
|
473
|
-
var CurrencyUnit =
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
473
|
+
var CurrencyUnit = {
|
|
474
|
+
FUTURE_VALUE: "FUTURE_VALUE",
|
|
475
|
+
BITCOIN: "BITCOIN",
|
|
476
|
+
SATOSHI: "SATOSHI",
|
|
477
|
+
MILLISATOSHI: "MILLISATOSHI",
|
|
478
|
+
USD: "USD",
|
|
479
|
+
NANOBITCOIN: "NANOBITCOIN",
|
|
480
|
+
MICROBITCOIN: "MICROBITCOIN",
|
|
481
|
+
MILLIBITCOIN: "MILLIBITCOIN",
|
|
482
|
+
Bitcoin: "BITCOIN",
|
|
483
|
+
Microbitcoin: "MICROBITCOIN",
|
|
484
|
+
Millibitcoin: "MILLIBITCOIN",
|
|
485
|
+
Millisatoshi: "MILLISATOSHI",
|
|
486
|
+
Nanobitcoin: "NANOBITCOIN",
|
|
487
|
+
Satoshi: "SATOSHI",
|
|
488
|
+
Usd: "USD"
|
|
489
|
+
};
|
|
484
490
|
var CONVERSION_MAP = {
|
|
485
|
-
[
|
|
486
|
-
[
|
|
487
|
-
[
|
|
488
|
-
[
|
|
489
|
-
[
|
|
490
|
-
[
|
|
491
|
-
[
|
|
492
|
-
[
|
|
491
|
+
[CurrencyUnit.BITCOIN]: {
|
|
492
|
+
[CurrencyUnit.BITCOIN]: (v) => v,
|
|
493
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e6,
|
|
494
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v * 1e3,
|
|
495
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
|
|
496
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
|
|
497
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e8,
|
|
498
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
493
499
|
/* Round without decimals since we're returning cents: */
|
|
494
500
|
round(v * centsPerBtc, 2)
|
|
495
501
|
)
|
|
496
502
|
},
|
|
497
|
-
[
|
|
498
|
-
[
|
|
499
|
-
[
|
|
500
|
-
[
|
|
501
|
-
[
|
|
502
|
-
[
|
|
503
|
-
[
|
|
504
|
-
[
|
|
503
|
+
[CurrencyUnit.MICROBITCOIN]: {
|
|
504
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e6,
|
|
505
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v,
|
|
506
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e3,
|
|
507
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
|
|
508
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
|
|
509
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 100,
|
|
510
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
505
511
|
/* Round without decimals since we're returning cents: */
|
|
506
512
|
round(v / 1e6 * centsPerBtc)
|
|
507
513
|
)
|
|
508
514
|
},
|
|
509
|
-
[
|
|
510
|
-
[
|
|
511
|
-
[
|
|
512
|
-
[
|
|
513
|
-
[
|
|
514
|
-
[
|
|
515
|
-
[
|
|
516
|
-
[
|
|
515
|
+
[CurrencyUnit.MILLIBITCOIN]: {
|
|
516
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e3,
|
|
517
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e3,
|
|
518
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v,
|
|
519
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
|
|
520
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
|
|
521
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e5,
|
|
522
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
517
523
|
/* Round without decimals since we're returning cents: */
|
|
518
524
|
round(v / 1e3 * centsPerBtc)
|
|
519
525
|
)
|
|
520
526
|
},
|
|
521
|
-
[
|
|
522
|
-
[
|
|
523
|
-
[
|
|
524
|
-
[
|
|
525
|
-
[
|
|
526
|
-
[
|
|
527
|
-
[
|
|
528
|
-
[
|
|
527
|
+
[CurrencyUnit.MILLISATOSHI]: {
|
|
528
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e11,
|
|
529
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e5,
|
|
530
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e8,
|
|
531
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v,
|
|
532
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
|
|
533
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 1e3,
|
|
534
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
529
535
|
/* Round without decimals since we're returning cents: */
|
|
530
536
|
round(v / 1e11 * centsPerBtc)
|
|
531
537
|
)
|
|
532
538
|
},
|
|
533
|
-
[
|
|
534
|
-
[
|
|
535
|
-
[
|
|
536
|
-
[
|
|
537
|
-
[
|
|
538
|
-
[
|
|
539
|
-
[
|
|
540
|
-
[
|
|
539
|
+
[CurrencyUnit.NANOBITCOIN]: {
|
|
540
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e9,
|
|
541
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e3,
|
|
542
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e6,
|
|
543
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
|
|
544
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v,
|
|
545
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 10,
|
|
546
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
541
547
|
/* Round without decimals since we're returning cents: */
|
|
542
548
|
round(v / 1e9 * centsPerBtc)
|
|
543
549
|
)
|
|
544
550
|
},
|
|
545
|
-
[
|
|
546
|
-
[
|
|
547
|
-
[
|
|
548
|
-
[
|
|
549
|
-
[
|
|
550
|
-
[
|
|
551
|
-
[
|
|
552
|
-
[
|
|
551
|
+
[CurrencyUnit.SATOSHI]: {
|
|
552
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e8,
|
|
553
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 100,
|
|
554
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e5,
|
|
555
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
|
|
556
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
|
|
557
|
+
[CurrencyUnit.SATOSHI]: (v) => v,
|
|
558
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
553
559
|
/* Round without decimals since we're returning cents: */
|
|
554
560
|
round(v / 1e8 * centsPerBtc)
|
|
555
561
|
)
|
|
556
562
|
},
|
|
557
|
-
[
|
|
558
|
-
[
|
|
559
|
-
[
|
|
560
|
-
[
|
|
561
|
-
[
|
|
562
|
-
[
|
|
563
|
-
[
|
|
564
|
-
[
|
|
563
|
+
[CurrencyUnit.USD]: {
|
|
564
|
+
[CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
|
|
565
|
+
[CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
|
|
566
|
+
[CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
|
|
567
|
+
[CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
|
|
568
|
+
[CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
|
|
569
|
+
[CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
|
|
570
|
+
[CurrencyUnit.USD]: (v) => v
|
|
565
571
|
}
|
|
566
572
|
};
|
|
567
573
|
function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
|
|
568
|
-
if (fromUnit ===
|
|
574
|
+
if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
|
|
569
575
|
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
570
576
|
}
|
|
571
577
|
if (fromUnit === toUnit) {
|
|
@@ -596,8 +602,9 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
596
602
|
function isCurrencyAmountObj(arg) {
|
|
597
603
|
return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
|
|
598
604
|
}
|
|
599
|
-
function
|
|
600
|
-
return typeof arg === "object" && arg !== null &&
|
|
605
|
+
function isSDKCurrencyAmount(arg) {
|
|
606
|
+
return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
|
|
607
|
+
"originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
|
|
601
608
|
}
|
|
602
609
|
function asNumber(value) {
|
|
603
610
|
if (typeof value === "string") {
|
|
@@ -608,67 +615,67 @@ function asNumber(value) {
|
|
|
608
615
|
function getCurrencyAmount(currencyAmountArg) {
|
|
609
616
|
let value = 0;
|
|
610
617
|
let unit = void 0;
|
|
611
|
-
if (
|
|
612
|
-
value = asNumber(currencyAmountArg.value);
|
|
613
|
-
unit = currencyAmountArg.unit;
|
|
614
|
-
} else if (isCurrencyAmount(currencyAmountArg)) {
|
|
618
|
+
if (isSDKCurrencyAmount(currencyAmountArg)) {
|
|
615
619
|
value = currencyAmountArg.originalValue;
|
|
616
620
|
unit = currencyAmountArg.originalUnit;
|
|
621
|
+
} else if (isCurrencyAmountObj(currencyAmountArg)) {
|
|
622
|
+
value = asNumber(currencyAmountArg.value);
|
|
623
|
+
unit = currencyAmountArg.unit;
|
|
617
624
|
}
|
|
618
625
|
return {
|
|
619
626
|
value: asNumber(value),
|
|
620
|
-
unit: unit ||
|
|
627
|
+
unit: unit || CurrencyUnit.SATOSHI
|
|
621
628
|
};
|
|
622
629
|
}
|
|
623
630
|
function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
624
631
|
const { value, unit } = getCurrencyAmount(currencyAmountArg);
|
|
625
632
|
const convert = convertCurrencyAmountValue;
|
|
626
|
-
const sats = convert(unit,
|
|
627
|
-
const btc = convert(unit,
|
|
628
|
-
const msats = convert(unit,
|
|
629
|
-
const usd = convert(unit,
|
|
630
|
-
const mibtc = convert(unit,
|
|
631
|
-
const mlbtc = convert(unit,
|
|
632
|
-
const nbtc = convert(unit,
|
|
633
|
+
const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
|
|
634
|
+
const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
|
|
635
|
+
const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
|
|
636
|
+
const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
|
|
637
|
+
const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
|
|
638
|
+
const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
|
|
639
|
+
const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
|
|
633
640
|
const mapWithCurrencyUnits = {
|
|
634
|
-
[
|
|
635
|
-
[
|
|
636
|
-
[
|
|
637
|
-
[
|
|
638
|
-
[
|
|
639
|
-
[
|
|
640
|
-
[
|
|
641
|
-
[
|
|
641
|
+
[CurrencyUnit.BITCOIN]: btc,
|
|
642
|
+
[CurrencyUnit.SATOSHI]: sats,
|
|
643
|
+
[CurrencyUnit.MILLISATOSHI]: msats,
|
|
644
|
+
[CurrencyUnit.USD]: usd,
|
|
645
|
+
[CurrencyUnit.MICROBITCOIN]: mibtc,
|
|
646
|
+
[CurrencyUnit.MILLIBITCOIN]: mlbtc,
|
|
647
|
+
[CurrencyUnit.NANOBITCOIN]: nbtc,
|
|
648
|
+
[CurrencyUnit.FUTURE_VALUE]: NaN,
|
|
642
649
|
formatted: {
|
|
643
|
-
[
|
|
650
|
+
[CurrencyUnit.BITCOIN]: formatCurrencyStr({
|
|
644
651
|
value: btc,
|
|
645
|
-
unit:
|
|
652
|
+
unit: CurrencyUnit.BITCOIN
|
|
646
653
|
}),
|
|
647
|
-
[
|
|
654
|
+
[CurrencyUnit.SATOSHI]: formatCurrencyStr({
|
|
648
655
|
value: sats,
|
|
649
|
-
unit:
|
|
656
|
+
unit: CurrencyUnit.SATOSHI
|
|
650
657
|
}),
|
|
651
|
-
[
|
|
658
|
+
[CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
|
|
652
659
|
value: msats,
|
|
653
|
-
unit:
|
|
660
|
+
unit: CurrencyUnit.MILLISATOSHI
|
|
654
661
|
}),
|
|
655
|
-
[
|
|
662
|
+
[CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
|
|
656
663
|
value: mibtc,
|
|
657
|
-
unit:
|
|
664
|
+
unit: CurrencyUnit.MICROBITCOIN
|
|
658
665
|
}),
|
|
659
|
-
[
|
|
666
|
+
[CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
|
|
660
667
|
value: mlbtc,
|
|
661
|
-
unit:
|
|
668
|
+
unit: CurrencyUnit.MILLIBITCOIN
|
|
662
669
|
}),
|
|
663
|
-
[
|
|
670
|
+
[CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
|
|
664
671
|
value: nbtc,
|
|
665
|
-
unit:
|
|
672
|
+
unit: CurrencyUnit.NANOBITCOIN
|
|
666
673
|
}),
|
|
667
|
-
[
|
|
674
|
+
[CurrencyUnit.USD]: formatCurrencyStr({
|
|
668
675
|
value: usd,
|
|
669
|
-
unit:
|
|
676
|
+
unit: CurrencyUnit.USD
|
|
670
677
|
}),
|
|
671
|
-
[
|
|
678
|
+
[CurrencyUnit.FUTURE_VALUE]: "-"
|
|
672
679
|
}
|
|
673
680
|
};
|
|
674
681
|
return {
|
|
@@ -706,9 +713,9 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
706
713
|
},
|
|
707
714
|
formatted: {
|
|
708
715
|
...mapWithCurrencyUnits.formatted,
|
|
709
|
-
btc: mapWithCurrencyUnits.formatted[
|
|
710
|
-
sats: mapWithCurrencyUnits.formatted[
|
|
711
|
-
msats: mapWithCurrencyUnits.formatted[
|
|
716
|
+
btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
|
|
717
|
+
sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
|
|
718
|
+
msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI]
|
|
712
719
|
},
|
|
713
720
|
type: "CurrencyMap"
|
|
714
721
|
};
|
|
@@ -716,54 +723,73 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
716
723
|
var isCurrencyMap = (currencyMap) => typeof currencyMap === "object" && currencyMap !== null && "type" in currencyMap && typeof currencyMap.type === "string" && currencyMap.type === "CurrencyMap";
|
|
717
724
|
var abbrCurrencyUnit = (unit) => {
|
|
718
725
|
switch (unit) {
|
|
719
|
-
case
|
|
726
|
+
case CurrencyUnit.BITCOIN:
|
|
720
727
|
return "BTC";
|
|
721
|
-
case
|
|
728
|
+
case CurrencyUnit.SATOSHI:
|
|
722
729
|
return "SAT";
|
|
723
|
-
case
|
|
730
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
724
731
|
return "MSAT";
|
|
725
|
-
case
|
|
732
|
+
case CurrencyUnit.USD:
|
|
726
733
|
return "USD";
|
|
727
734
|
}
|
|
728
735
|
return "Unsupported CurrencyUnit";
|
|
729
736
|
};
|
|
730
|
-
|
|
737
|
+
var defaultOptions = {
|
|
738
|
+
/* undefined indicates to use default precision for unit defined below */
|
|
739
|
+
precision: void 0,
|
|
740
|
+
compact: false,
|
|
741
|
+
showBtcSymbol: false
|
|
742
|
+
};
|
|
743
|
+
function formatCurrencyStr(amount, options) {
|
|
744
|
+
const { precision, compact, showBtcSymbol } = {
|
|
745
|
+
...defaultOptions,
|
|
746
|
+
...options
|
|
747
|
+
};
|
|
731
748
|
const currencyAmount = getCurrencyAmount(amount);
|
|
732
749
|
let { value: num } = currencyAmount;
|
|
733
750
|
const { unit } = currencyAmount;
|
|
734
|
-
if (unit ===
|
|
751
|
+
if (unit === CurrencyUnit.USD) {
|
|
735
752
|
num = num / 100;
|
|
736
753
|
}
|
|
737
|
-
function getDefaultMaxFractionDigits(defaultDigits) {
|
|
738
|
-
|
|
754
|
+
function getDefaultMaxFractionDigits(defaultDigits, fullPrecisionDigits) {
|
|
755
|
+
let digits = defaultDigits;
|
|
756
|
+
if (precision === "full") {
|
|
757
|
+
digits = fullPrecisionDigits;
|
|
758
|
+
} else if (typeof precision === "number") {
|
|
759
|
+
digits = precision;
|
|
760
|
+
} else if (compact) {
|
|
761
|
+
digits = 1;
|
|
762
|
+
}
|
|
763
|
+
return digits;
|
|
739
764
|
}
|
|
740
|
-
const symbol = !showBtcSymbol ? "" : unit ===
|
|
765
|
+
const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
|
|
741
766
|
const currentLocale = getCurrentLocale();
|
|
742
767
|
switch (unit) {
|
|
743
|
-
case
|
|
768
|
+
case CurrencyUnit.BITCOIN:
|
|
769
|
+
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
770
|
+
notation: compact ? "compact" : void 0,
|
|
771
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(4, 8)
|
|
772
|
+
})}`;
|
|
773
|
+
case CurrencyUnit.SATOSHI:
|
|
744
774
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
745
775
|
notation: compact ? "compact" : void 0,
|
|
746
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(
|
|
747
|
-
...options
|
|
776
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(0, 3)
|
|
748
777
|
})}`;
|
|
749
|
-
case
|
|
750
|
-
case
|
|
751
|
-
case
|
|
752
|
-
case
|
|
753
|
-
case "NANOBITCOIN" /* NANOBITCOIN */:
|
|
778
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
779
|
+
case CurrencyUnit.MICROBITCOIN:
|
|
780
|
+
case CurrencyUnit.MILLIBITCOIN:
|
|
781
|
+
case CurrencyUnit.NANOBITCOIN:
|
|
754
782
|
default:
|
|
755
783
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
756
784
|
notation: compact ? "compact" : void 0,
|
|
757
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(0)
|
|
758
|
-
...options
|
|
785
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(0, 0)
|
|
759
786
|
})}`;
|
|
760
|
-
case
|
|
787
|
+
case CurrencyUnit.USD:
|
|
761
788
|
return num.toLocaleString(currentLocale, {
|
|
762
789
|
style: "currency",
|
|
763
790
|
currency: defaultCurrencyCode,
|
|
764
791
|
notation: compact ? "compact" : void 0,
|
|
765
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(2)
|
|
766
|
-
...options
|
|
792
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
|
|
767
793
|
});
|
|
768
794
|
}
|
|
769
795
|
}
|
|
@@ -1006,7 +1032,6 @@ function notNullUndefined(value) {
|
|
|
1006
1032
|
getLocalStorageConfigItem,
|
|
1007
1033
|
hexToBytes,
|
|
1008
1034
|
isBrowser,
|
|
1009
|
-
isCurrencyAmount,
|
|
1010
1035
|
isCurrencyAmountObj,
|
|
1011
1036
|
isCurrencyMap,
|
|
1012
1037
|
isError,
|
|
@@ -1014,6 +1039,7 @@ function notNullUndefined(value) {
|
|
|
1014
1039
|
isErrorWithMessage,
|
|
1015
1040
|
isNode,
|
|
1016
1041
|
isNumber,
|
|
1042
|
+
isSDKCurrencyAmount,
|
|
1017
1043
|
isTest,
|
|
1018
1044
|
isType,
|
|
1019
1045
|
isUint8Array,
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Z as ById, a7 as Complete, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a0 as DeepPartial, Y as ExpandRecursively, a1 as JSONLiteral, a3 as JSONObject, a2 as JSONType, X as Maybe, a4 as NN, _ as OmitTypename, a6 as PartialBy, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, m as isSDKCurrencyAmount, w as isTest, $ as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a5 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-4698c2db.js';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Z as ById, a7 as Complete, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a0 as DeepPartial, Y as ExpandRecursively, a1 as JSONLiteral, a3 as JSONObject, a2 as JSONType, X as Maybe, a4 as NN, _ as OmitTypename, a6 as PartialBy, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, m as isSDKCurrencyAmount, w as isTest, $ as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a5 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-4698c2db.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
getLocalStorageConfigItem,
|
|
20
20
|
hexToBytes,
|
|
21
21
|
isBrowser,
|
|
22
|
-
isCurrencyAmount,
|
|
23
22
|
isCurrencyAmountObj,
|
|
24
23
|
isCurrencyMap,
|
|
25
24
|
isError,
|
|
@@ -27,6 +26,7 @@ import {
|
|
|
27
26
|
isErrorWithMessage,
|
|
28
27
|
isNode,
|
|
29
28
|
isNumber,
|
|
29
|
+
isSDKCurrencyAmount,
|
|
30
30
|
isTest,
|
|
31
31
|
isType,
|
|
32
32
|
isUint8Array,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
setLocalStorageBoolean,
|
|
43
43
|
sleep,
|
|
44
44
|
urlsafe_b64decode
|
|
45
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-XRYQNSG7.js";
|
|
46
46
|
export {
|
|
47
47
|
CurrencyUnit,
|
|
48
48
|
abbrCurrencyUnit,
|
|
@@ -64,7 +64,6 @@ export {
|
|
|
64
64
|
getLocalStorageConfigItem,
|
|
65
65
|
hexToBytes,
|
|
66
66
|
isBrowser,
|
|
67
|
-
isCurrencyAmount,
|
|
68
67
|
isCurrencyAmountObj,
|
|
69
68
|
isCurrencyMap,
|
|
70
69
|
isError,
|
|
@@ -72,6 +71,7 @@ export {
|
|
|
72
71
|
isErrorWithMessage,
|
|
73
72
|
isNode,
|
|
74
73
|
isNumber,
|
|
74
|
+
isSDKCurrencyAmount,
|
|
75
75
|
isTest,
|
|
76
76
|
isType,
|
|
77
77
|
isUint8Array,
|