@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fda487d: - Move formatCurrencyStr options into an object (#1095)
|
|
8
|
+
- Compress requests with deflate (#10512)
|
|
9
|
+
|
|
10
|
+
## 1.0.22
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- baeccd9: - Improve currency functions and types
|
|
15
|
+
|
|
3
16
|
## 1.0.21
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -392,102 +392,108 @@ function isNumber(value) {
|
|
|
392
392
|
|
|
393
393
|
// src/utils/currency.ts
|
|
394
394
|
var defaultCurrencyCode = "USD";
|
|
395
|
-
var CurrencyUnit =
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
395
|
+
var CurrencyUnit = {
|
|
396
|
+
FUTURE_VALUE: "FUTURE_VALUE",
|
|
397
|
+
BITCOIN: "BITCOIN",
|
|
398
|
+
SATOSHI: "SATOSHI",
|
|
399
|
+
MILLISATOSHI: "MILLISATOSHI",
|
|
400
|
+
USD: "USD",
|
|
401
|
+
NANOBITCOIN: "NANOBITCOIN",
|
|
402
|
+
MICROBITCOIN: "MICROBITCOIN",
|
|
403
|
+
MILLIBITCOIN: "MILLIBITCOIN",
|
|
404
|
+
Bitcoin: "BITCOIN",
|
|
405
|
+
Microbitcoin: "MICROBITCOIN",
|
|
406
|
+
Millibitcoin: "MILLIBITCOIN",
|
|
407
|
+
Millisatoshi: "MILLISATOSHI",
|
|
408
|
+
Nanobitcoin: "NANOBITCOIN",
|
|
409
|
+
Satoshi: "SATOSHI",
|
|
410
|
+
Usd: "USD"
|
|
411
|
+
};
|
|
406
412
|
var CONVERSION_MAP = {
|
|
407
|
-
[
|
|
408
|
-
[
|
|
409
|
-
[
|
|
410
|
-
[
|
|
411
|
-
[
|
|
412
|
-
[
|
|
413
|
-
[
|
|
414
|
-
[
|
|
413
|
+
[CurrencyUnit.BITCOIN]: {
|
|
414
|
+
[CurrencyUnit.BITCOIN]: (v) => v,
|
|
415
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e6,
|
|
416
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v * 1e3,
|
|
417
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
|
|
418
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
|
|
419
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e8,
|
|
420
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
415
421
|
/* Round without decimals since we're returning cents: */
|
|
416
422
|
round(v * centsPerBtc, 2)
|
|
417
423
|
)
|
|
418
424
|
},
|
|
419
|
-
[
|
|
420
|
-
[
|
|
421
|
-
[
|
|
422
|
-
[
|
|
423
|
-
[
|
|
424
|
-
[
|
|
425
|
-
[
|
|
426
|
-
[
|
|
425
|
+
[CurrencyUnit.MICROBITCOIN]: {
|
|
426
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e6,
|
|
427
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v,
|
|
428
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e3,
|
|
429
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
|
|
430
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
|
|
431
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 100,
|
|
432
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
427
433
|
/* Round without decimals since we're returning cents: */
|
|
428
434
|
round(v / 1e6 * centsPerBtc)
|
|
429
435
|
)
|
|
430
436
|
},
|
|
431
|
-
[
|
|
432
|
-
[
|
|
433
|
-
[
|
|
434
|
-
[
|
|
435
|
-
[
|
|
436
|
-
[
|
|
437
|
-
[
|
|
438
|
-
[
|
|
437
|
+
[CurrencyUnit.MILLIBITCOIN]: {
|
|
438
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e3,
|
|
439
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e3,
|
|
440
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v,
|
|
441
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
|
|
442
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
|
|
443
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e5,
|
|
444
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
439
445
|
/* Round without decimals since we're returning cents: */
|
|
440
446
|
round(v / 1e3 * centsPerBtc)
|
|
441
447
|
)
|
|
442
448
|
},
|
|
443
|
-
[
|
|
444
|
-
[
|
|
445
|
-
[
|
|
446
|
-
[
|
|
447
|
-
[
|
|
448
|
-
[
|
|
449
|
-
[
|
|
450
|
-
[
|
|
449
|
+
[CurrencyUnit.MILLISATOSHI]: {
|
|
450
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e11,
|
|
451
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e5,
|
|
452
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e8,
|
|
453
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v,
|
|
454
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
|
|
455
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 1e3,
|
|
456
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
451
457
|
/* Round without decimals since we're returning cents: */
|
|
452
458
|
round(v / 1e11 * centsPerBtc)
|
|
453
459
|
)
|
|
454
460
|
},
|
|
455
|
-
[
|
|
456
|
-
[
|
|
457
|
-
[
|
|
458
|
-
[
|
|
459
|
-
[
|
|
460
|
-
[
|
|
461
|
-
[
|
|
462
|
-
[
|
|
461
|
+
[CurrencyUnit.NANOBITCOIN]: {
|
|
462
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e9,
|
|
463
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e3,
|
|
464
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e6,
|
|
465
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
|
|
466
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v,
|
|
467
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 10,
|
|
468
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
463
469
|
/* Round without decimals since we're returning cents: */
|
|
464
470
|
round(v / 1e9 * centsPerBtc)
|
|
465
471
|
)
|
|
466
472
|
},
|
|
467
|
-
[
|
|
468
|
-
[
|
|
469
|
-
[
|
|
470
|
-
[
|
|
471
|
-
[
|
|
472
|
-
[
|
|
473
|
-
[
|
|
474
|
-
[
|
|
473
|
+
[CurrencyUnit.SATOSHI]: {
|
|
474
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e8,
|
|
475
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 100,
|
|
476
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e5,
|
|
477
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
|
|
478
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
|
|
479
|
+
[CurrencyUnit.SATOSHI]: (v) => v,
|
|
480
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
475
481
|
/* Round without decimals since we're returning cents: */
|
|
476
482
|
round(v / 1e8 * centsPerBtc)
|
|
477
483
|
)
|
|
478
484
|
},
|
|
479
|
-
[
|
|
480
|
-
[
|
|
481
|
-
[
|
|
482
|
-
[
|
|
483
|
-
[
|
|
484
|
-
[
|
|
485
|
-
[
|
|
486
|
-
[
|
|
485
|
+
[CurrencyUnit.USD]: {
|
|
486
|
+
[CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
|
|
487
|
+
[CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
|
|
488
|
+
[CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
|
|
489
|
+
[CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
|
|
490
|
+
[CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
|
|
491
|
+
[CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
|
|
492
|
+
[CurrencyUnit.USD]: (v) => v
|
|
487
493
|
}
|
|
488
494
|
};
|
|
489
495
|
function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
|
|
490
|
-
if (fromUnit ===
|
|
496
|
+
if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
|
|
491
497
|
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
492
498
|
}
|
|
493
499
|
if (fromUnit === toUnit) {
|
|
@@ -518,8 +524,9 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
518
524
|
function isCurrencyAmountObj(arg) {
|
|
519
525
|
return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
|
|
520
526
|
}
|
|
521
|
-
function
|
|
522
|
-
return typeof arg === "object" && arg !== null &&
|
|
527
|
+
function isSDKCurrencyAmount(arg) {
|
|
528
|
+
return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
|
|
529
|
+
"originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
|
|
523
530
|
}
|
|
524
531
|
function asNumber(value) {
|
|
525
532
|
if (typeof value === "string") {
|
|
@@ -530,67 +537,67 @@ function asNumber(value) {
|
|
|
530
537
|
function getCurrencyAmount(currencyAmountArg) {
|
|
531
538
|
let value = 0;
|
|
532
539
|
let unit = void 0;
|
|
533
|
-
if (
|
|
534
|
-
value = asNumber(currencyAmountArg.value);
|
|
535
|
-
unit = currencyAmountArg.unit;
|
|
536
|
-
} else if (isCurrencyAmount(currencyAmountArg)) {
|
|
540
|
+
if (isSDKCurrencyAmount(currencyAmountArg)) {
|
|
537
541
|
value = currencyAmountArg.originalValue;
|
|
538
542
|
unit = currencyAmountArg.originalUnit;
|
|
543
|
+
} else if (isCurrencyAmountObj(currencyAmountArg)) {
|
|
544
|
+
value = asNumber(currencyAmountArg.value);
|
|
545
|
+
unit = currencyAmountArg.unit;
|
|
539
546
|
}
|
|
540
547
|
return {
|
|
541
548
|
value: asNumber(value),
|
|
542
|
-
unit: unit ||
|
|
549
|
+
unit: unit || CurrencyUnit.SATOSHI
|
|
543
550
|
};
|
|
544
551
|
}
|
|
545
552
|
function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
546
553
|
const { value, unit } = getCurrencyAmount(currencyAmountArg);
|
|
547
554
|
const convert = convertCurrencyAmountValue;
|
|
548
|
-
const sats = convert(unit,
|
|
549
|
-
const btc = convert(unit,
|
|
550
|
-
const msats = convert(unit,
|
|
551
|
-
const usd = convert(unit,
|
|
552
|
-
const mibtc = convert(unit,
|
|
553
|
-
const mlbtc = convert(unit,
|
|
554
|
-
const nbtc = convert(unit,
|
|
555
|
+
const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
|
|
556
|
+
const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
|
|
557
|
+
const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
|
|
558
|
+
const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
|
|
559
|
+
const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
|
|
560
|
+
const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
|
|
561
|
+
const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
|
|
555
562
|
const mapWithCurrencyUnits = {
|
|
556
|
-
[
|
|
557
|
-
[
|
|
558
|
-
[
|
|
559
|
-
[
|
|
560
|
-
[
|
|
561
|
-
[
|
|
562
|
-
[
|
|
563
|
-
[
|
|
563
|
+
[CurrencyUnit.BITCOIN]: btc,
|
|
564
|
+
[CurrencyUnit.SATOSHI]: sats,
|
|
565
|
+
[CurrencyUnit.MILLISATOSHI]: msats,
|
|
566
|
+
[CurrencyUnit.USD]: usd,
|
|
567
|
+
[CurrencyUnit.MICROBITCOIN]: mibtc,
|
|
568
|
+
[CurrencyUnit.MILLIBITCOIN]: mlbtc,
|
|
569
|
+
[CurrencyUnit.NANOBITCOIN]: nbtc,
|
|
570
|
+
[CurrencyUnit.FUTURE_VALUE]: NaN,
|
|
564
571
|
formatted: {
|
|
565
|
-
[
|
|
572
|
+
[CurrencyUnit.BITCOIN]: formatCurrencyStr({
|
|
566
573
|
value: btc,
|
|
567
|
-
unit:
|
|
574
|
+
unit: CurrencyUnit.BITCOIN
|
|
568
575
|
}),
|
|
569
|
-
[
|
|
576
|
+
[CurrencyUnit.SATOSHI]: formatCurrencyStr({
|
|
570
577
|
value: sats,
|
|
571
|
-
unit:
|
|
578
|
+
unit: CurrencyUnit.SATOSHI
|
|
572
579
|
}),
|
|
573
|
-
[
|
|
580
|
+
[CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
|
|
574
581
|
value: msats,
|
|
575
|
-
unit:
|
|
582
|
+
unit: CurrencyUnit.MILLISATOSHI
|
|
576
583
|
}),
|
|
577
|
-
[
|
|
584
|
+
[CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
|
|
578
585
|
value: mibtc,
|
|
579
|
-
unit:
|
|
586
|
+
unit: CurrencyUnit.MICROBITCOIN
|
|
580
587
|
}),
|
|
581
|
-
[
|
|
588
|
+
[CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
|
|
582
589
|
value: mlbtc,
|
|
583
|
-
unit:
|
|
590
|
+
unit: CurrencyUnit.MILLIBITCOIN
|
|
584
591
|
}),
|
|
585
|
-
[
|
|
592
|
+
[CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
|
|
586
593
|
value: nbtc,
|
|
587
|
-
unit:
|
|
594
|
+
unit: CurrencyUnit.NANOBITCOIN
|
|
588
595
|
}),
|
|
589
|
-
[
|
|
596
|
+
[CurrencyUnit.USD]: formatCurrencyStr({
|
|
590
597
|
value: usd,
|
|
591
|
-
unit:
|
|
598
|
+
unit: CurrencyUnit.USD
|
|
592
599
|
}),
|
|
593
|
-
[
|
|
600
|
+
[CurrencyUnit.FUTURE_VALUE]: "-"
|
|
594
601
|
}
|
|
595
602
|
};
|
|
596
603
|
return {
|
|
@@ -628,9 +635,9 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
628
635
|
},
|
|
629
636
|
formatted: {
|
|
630
637
|
...mapWithCurrencyUnits.formatted,
|
|
631
|
-
btc: mapWithCurrencyUnits.formatted[
|
|
632
|
-
sats: mapWithCurrencyUnits.formatted[
|
|
633
|
-
msats: mapWithCurrencyUnits.formatted[
|
|
638
|
+
btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
|
|
639
|
+
sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
|
|
640
|
+
msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI]
|
|
634
641
|
},
|
|
635
642
|
type: "CurrencyMap"
|
|
636
643
|
};
|
|
@@ -638,54 +645,73 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
638
645
|
var isCurrencyMap = (currencyMap) => typeof currencyMap === "object" && currencyMap !== null && "type" in currencyMap && typeof currencyMap.type === "string" && currencyMap.type === "CurrencyMap";
|
|
639
646
|
var abbrCurrencyUnit = (unit) => {
|
|
640
647
|
switch (unit) {
|
|
641
|
-
case
|
|
648
|
+
case CurrencyUnit.BITCOIN:
|
|
642
649
|
return "BTC";
|
|
643
|
-
case
|
|
650
|
+
case CurrencyUnit.SATOSHI:
|
|
644
651
|
return "SAT";
|
|
645
|
-
case
|
|
652
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
646
653
|
return "MSAT";
|
|
647
|
-
case
|
|
654
|
+
case CurrencyUnit.USD:
|
|
648
655
|
return "USD";
|
|
649
656
|
}
|
|
650
657
|
return "Unsupported CurrencyUnit";
|
|
651
658
|
};
|
|
652
|
-
|
|
659
|
+
var defaultOptions = {
|
|
660
|
+
/* undefined indicates to use default precision for unit defined below */
|
|
661
|
+
precision: void 0,
|
|
662
|
+
compact: false,
|
|
663
|
+
showBtcSymbol: false
|
|
664
|
+
};
|
|
665
|
+
function formatCurrencyStr(amount, options) {
|
|
666
|
+
const { precision, compact, showBtcSymbol } = {
|
|
667
|
+
...defaultOptions,
|
|
668
|
+
...options
|
|
669
|
+
};
|
|
653
670
|
const currencyAmount = getCurrencyAmount(amount);
|
|
654
671
|
let { value: num } = currencyAmount;
|
|
655
672
|
const { unit } = currencyAmount;
|
|
656
|
-
if (unit ===
|
|
673
|
+
if (unit === CurrencyUnit.USD) {
|
|
657
674
|
num = num / 100;
|
|
658
675
|
}
|
|
659
|
-
function getDefaultMaxFractionDigits(defaultDigits) {
|
|
660
|
-
|
|
676
|
+
function getDefaultMaxFractionDigits(defaultDigits, fullPrecisionDigits) {
|
|
677
|
+
let digits = defaultDigits;
|
|
678
|
+
if (precision === "full") {
|
|
679
|
+
digits = fullPrecisionDigits;
|
|
680
|
+
} else if (typeof precision === "number") {
|
|
681
|
+
digits = precision;
|
|
682
|
+
} else if (compact) {
|
|
683
|
+
digits = 1;
|
|
684
|
+
}
|
|
685
|
+
return digits;
|
|
661
686
|
}
|
|
662
|
-
const symbol = !showBtcSymbol ? "" : unit ===
|
|
687
|
+
const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
|
|
663
688
|
const currentLocale = getCurrentLocale();
|
|
664
689
|
switch (unit) {
|
|
665
|
-
case
|
|
690
|
+
case CurrencyUnit.BITCOIN:
|
|
691
|
+
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
692
|
+
notation: compact ? "compact" : void 0,
|
|
693
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(4, 8)
|
|
694
|
+
})}`;
|
|
695
|
+
case CurrencyUnit.SATOSHI:
|
|
666
696
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
667
697
|
notation: compact ? "compact" : void 0,
|
|
668
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(
|
|
669
|
-
...options
|
|
698
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(0, 3)
|
|
670
699
|
})}`;
|
|
671
|
-
case
|
|
672
|
-
case
|
|
673
|
-
case
|
|
674
|
-
case
|
|
675
|
-
case "NANOBITCOIN" /* NANOBITCOIN */:
|
|
700
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
701
|
+
case CurrencyUnit.MICROBITCOIN:
|
|
702
|
+
case CurrencyUnit.MILLIBITCOIN:
|
|
703
|
+
case CurrencyUnit.NANOBITCOIN:
|
|
676
704
|
default:
|
|
677
705
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
678
706
|
notation: compact ? "compact" : void 0,
|
|
679
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(0)
|
|
680
|
-
...options
|
|
707
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(0, 0)
|
|
681
708
|
})}`;
|
|
682
|
-
case
|
|
709
|
+
case CurrencyUnit.USD:
|
|
683
710
|
return num.toLocaleString(currentLocale, {
|
|
684
711
|
style: "currency",
|
|
685
712
|
currency: defaultCurrencyCode,
|
|
686
713
|
notation: compact ? "compact" : void 0,
|
|
687
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(2)
|
|
688
|
-
...options
|
|
714
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
|
|
689
715
|
});
|
|
690
716
|
}
|
|
691
717
|
}
|
|
@@ -930,7 +956,7 @@ export {
|
|
|
930
956
|
convertCurrencyAmountValue,
|
|
931
957
|
convertCurrencyAmount,
|
|
932
958
|
isCurrencyAmountObj,
|
|
933
|
-
|
|
959
|
+
isSDKCurrencyAmount,
|
|
934
960
|
mapCurrencyAmount,
|
|
935
961
|
isCurrencyMap,
|
|
936
962
|
abbrCurrencyUnit,
|
|
@@ -13,78 +13,33 @@ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
|
|
|
13
13
|
declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
|
|
14
14
|
|
|
15
15
|
declare const defaultCurrencyCode = "USD";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* This is the unit most commonly used in Lightning transactions.
|
|
36
|
-
* *
|
|
37
|
-
*/
|
|
38
|
-
SATOSHI = "SATOSHI",
|
|
39
|
-
/**
|
|
40
|
-
* 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
|
|
41
|
-
* instead when possible. *
|
|
42
|
-
*/
|
|
43
|
-
MILLISATOSHI = "MILLISATOSHI",
|
|
44
|
-
/** United States Dollar. **/
|
|
45
|
-
USD = "USD",
|
|
46
|
-
/**
|
|
47
|
-
* 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
|
|
48
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
49
|
-
* *
|
|
50
|
-
*/
|
|
51
|
-
NANOBITCOIN = "NANOBITCOIN",
|
|
52
|
-
/**
|
|
53
|
-
* 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
|
|
54
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
55
|
-
* *
|
|
56
|
-
*/
|
|
57
|
-
MICROBITCOIN = "MICROBITCOIN",
|
|
58
|
-
/**
|
|
59
|
-
* 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
|
|
60
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
61
|
-
* *
|
|
62
|
-
*/
|
|
63
|
-
MILLIBITCOIN = "MILLIBITCOIN"
|
|
64
|
-
}
|
|
65
|
-
/** This object represents the value and unit for an amount of currency. **/
|
|
66
|
-
type CurrencyAmountType = {
|
|
67
|
-
/** The original numeric value for this CurrencyAmount. **/
|
|
16
|
+
declare const CurrencyUnit: {
|
|
17
|
+
readonly FUTURE_VALUE: "FUTURE_VALUE";
|
|
18
|
+
readonly BITCOIN: "BITCOIN";
|
|
19
|
+
readonly SATOSHI: "SATOSHI";
|
|
20
|
+
readonly MILLISATOSHI: "MILLISATOSHI";
|
|
21
|
+
readonly USD: "USD";
|
|
22
|
+
readonly NANOBITCOIN: "NANOBITCOIN";
|
|
23
|
+
readonly MICROBITCOIN: "MICROBITCOIN";
|
|
24
|
+
readonly MILLIBITCOIN: "MILLIBITCOIN";
|
|
25
|
+
readonly Bitcoin: "BITCOIN";
|
|
26
|
+
readonly Microbitcoin: "MICROBITCOIN";
|
|
27
|
+
readonly Millibitcoin: "MILLIBITCOIN";
|
|
28
|
+
readonly Millisatoshi: "MILLISATOSHI";
|
|
29
|
+
readonly Nanobitcoin: "NANOBITCOIN";
|
|
30
|
+
readonly Satoshi: "SATOSHI";
|
|
31
|
+
readonly Usd: "USD";
|
|
32
|
+
};
|
|
33
|
+
type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
|
|
34
|
+
type SDKCurrencyAmountType = {
|
|
68
35
|
originalValue: number;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** The unit of user's preferred currency. **/
|
|
72
|
-
preferredCurrencyUnit: CurrencyUnit;
|
|
73
|
-
/**
|
|
74
|
-
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
75
|
-
* of user's preferred currency. For example, for USD, the value will be in
|
|
76
|
-
* cents.
|
|
77
|
-
**/
|
|
36
|
+
originalUnit: CurrencyUnitType;
|
|
37
|
+
preferredCurrencyUnit: CurrencyUnitType;
|
|
78
38
|
preferredCurrencyValueRounded: number;
|
|
79
|
-
/**
|
|
80
|
-
* The approximate float value for this CurrencyAmount in the very base level
|
|
81
|
-
* of user's preferred currency. For example, for USD, the value will be in
|
|
82
|
-
* cents.
|
|
83
|
-
**/
|
|
84
39
|
preferredCurrencyValueApprox: number;
|
|
85
40
|
};
|
|
86
|
-
declare function convertCurrencyAmountValue(fromUnit:
|
|
87
|
-
declare const convertCurrencyAmount: (from:
|
|
41
|
+
declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, centsPerBtc?: number): number;
|
|
42
|
+
declare const convertCurrencyAmount: (from: SDKCurrencyAmountType, toUnit: CurrencyUnitType) => SDKCurrencyAmountType;
|
|
88
43
|
type CurrencyMap = {
|
|
89
44
|
sats: number;
|
|
90
45
|
msats: number;
|
|
@@ -118,16 +73,21 @@ type CurrencyMap = {
|
|
|
118
73
|
};
|
|
119
74
|
type CurrencyAmountObj = {
|
|
120
75
|
value?: number | string | null;
|
|
121
|
-
unit?:
|
|
122
|
-
__typename?: "CurrencyAmount";
|
|
76
|
+
unit?: CurrencyUnitType;
|
|
77
|
+
__typename?: "CurrencyAmount" | undefined;
|
|
123
78
|
};
|
|
124
|
-
type CurrencyAmountArg = CurrencyAmountObj |
|
|
79
|
+
type CurrencyAmountArg = CurrencyAmountObj | SDKCurrencyAmountType | undefined | null;
|
|
125
80
|
declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
|
|
126
|
-
declare function
|
|
81
|
+
declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
|
|
127
82
|
declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
|
|
128
83
|
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
129
|
-
declare const abbrCurrencyUnit: (unit:
|
|
130
|
-
|
|
84
|
+
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
85
|
+
type FormatCurrencyStrOptions = {
|
|
86
|
+
precision?: number | "full" | undefined;
|
|
87
|
+
compact?: boolean | undefined;
|
|
88
|
+
showBtcSymbol?: boolean | undefined;
|
|
89
|
+
};
|
|
90
|
+
declare function formatCurrencyStr(amount: CurrencyAmountArg, options?: FormatCurrencyStrOptions): string;
|
|
131
91
|
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
132
92
|
symbol: string;
|
|
133
93
|
amount: string;
|
|
@@ -163,6 +123,10 @@ type JSONObject = {
|
|
|
163
123
|
};
|
|
164
124
|
type NN<T> = NonNullable<T>;
|
|
165
125
|
declare function notNullUndefined<TValue>(value: TValue | null | undefined): value is TValue;
|
|
126
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
127
|
+
type Complete<T> = {
|
|
128
|
+
[P in keyof T]-?: NonNullable<T[P]>;
|
|
129
|
+
};
|
|
166
130
|
|
|
167
131
|
declare const isError: (e: unknown) => e is Error;
|
|
168
132
|
type ErrorWithMessage = {
|
|
@@ -274,4 +238,4 @@ declare function lsidToUUID(lsid: string): string;
|
|
|
274
238
|
|
|
275
239
|
declare function isUint8Array(variable: unknown): variable is Uint8Array;
|
|
276
240
|
|
|
277
|
-
export {
|
|
241
|
+
export { isType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, SDKCurrencyAmountType as S, pollUntil as T, sleep as U, lsidToUUID as V, isUint8Array as W, Maybe as X, ExpandRecursively as Y, ById as Z, OmitTypename as _, b64encode as a, DeepPartial as a0, JSONLiteral as a1, JSONType as a2, JSONObject as a3, NN as a4, notNullUndefined as a5, PartialBy as a6, Complete as a7, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyUnitType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isSDKCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
|