@lightsparkdev/core 1.0.21 → 1.0.22

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - baeccd9: - Improve currency functions and types
8
+
3
9
  ## 1.0.21
4
10
 
5
11
  ### 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 = /* @__PURE__ */ ((CurrencyUnit2) => {
396
- CurrencyUnit2["FUTURE_VALUE"] = "FUTURE_VALUE";
397
- CurrencyUnit2["BITCOIN"] = "BITCOIN";
398
- CurrencyUnit2["SATOSHI"] = "SATOSHI";
399
- CurrencyUnit2["MILLISATOSHI"] = "MILLISATOSHI";
400
- CurrencyUnit2["USD"] = "USD";
401
- CurrencyUnit2["NANOBITCOIN"] = "NANOBITCOIN";
402
- CurrencyUnit2["MICROBITCOIN"] = "MICROBITCOIN";
403
- CurrencyUnit2["MILLIBITCOIN"] = "MILLIBITCOIN";
404
- return CurrencyUnit2;
405
- })(CurrencyUnit || {});
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
- ["BITCOIN" /* BITCOIN */]: {
408
- ["BITCOIN" /* BITCOIN */]: (v) => v,
409
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
410
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
411
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
412
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
413
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e8,
414
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["MICROBITCOIN" /* MICROBITCOIN */]: {
420
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e6,
421
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
422
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e3,
423
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
424
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
425
- ["SATOSHI" /* SATOSHI */]: (v) => v * 100,
426
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: {
432
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e3,
433
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
434
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
435
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
436
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
437
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e5,
438
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["MILLISATOSHI" /* MILLISATOSHI */]: {
444
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e11,
445
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e5,
446
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e8,
447
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
448
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v / 100,
449
- ["SATOSHI" /* SATOSHI */]: (v) => v / 1e3,
450
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["NANOBITCOIN" /* NANOBITCOIN */]: {
456
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e9,
457
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e3,
458
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e6,
459
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
460
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
461
- ["SATOSHI" /* SATOSHI */]: (v) => v / 10,
462
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["SATOSHI" /* SATOSHI */]: {
468
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e8,
469
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 100,
470
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e5,
471
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
472
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
473
- ["SATOSHI" /* SATOSHI */]: (v) => v,
474
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
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
- ["USD" /* USD */]: {
480
- ["BITCOIN" /* BITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc,
481
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
482
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
483
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
484
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
485
- ["SATOSHI" /* SATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
486
- ["USD" /* USD */]: (v) => v
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 === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */) {
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 isCurrencyAmount(arg) {
522
- return typeof arg === "object" && arg !== null && "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
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 (isCurrencyAmountObj(currencyAmountArg)) {
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 || "SATOSHI" /* SATOSHI */
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, "SATOSHI" /* SATOSHI */, value, centsPerBtc);
549
- const btc = convert(unit, "BITCOIN" /* BITCOIN */, value, centsPerBtc);
550
- const msats = convert(unit, "MILLISATOSHI" /* MILLISATOSHI */, value, centsPerBtc);
551
- const usd = convert(unit, "USD" /* USD */, value, centsPerBtc);
552
- const mibtc = convert(unit, "MICROBITCOIN" /* MICROBITCOIN */, value, centsPerBtc);
553
- const mlbtc = convert(unit, "MILLIBITCOIN" /* MILLIBITCOIN */, value, centsPerBtc);
554
- const nbtc = convert(unit, "NANOBITCOIN" /* NANOBITCOIN */, value, centsPerBtc);
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
- ["BITCOIN" /* BITCOIN */]: btc,
557
- ["SATOSHI" /* SATOSHI */]: sats,
558
- ["MILLISATOSHI" /* MILLISATOSHI */]: msats,
559
- ["USD" /* USD */]: usd,
560
- ["MICROBITCOIN" /* MICROBITCOIN */]: mibtc,
561
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: mlbtc,
562
- ["NANOBITCOIN" /* NANOBITCOIN */]: nbtc,
563
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: NaN,
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
- ["BITCOIN" /* BITCOIN */]: formatCurrencyStr({
572
+ [CurrencyUnit.BITCOIN]: formatCurrencyStr({
566
573
  value: btc,
567
- unit: "BITCOIN" /* BITCOIN */
574
+ unit: CurrencyUnit.BITCOIN
568
575
  }),
569
- ["SATOSHI" /* SATOSHI */]: formatCurrencyStr({
576
+ [CurrencyUnit.SATOSHI]: formatCurrencyStr({
570
577
  value: sats,
571
- unit: "SATOSHI" /* SATOSHI */
578
+ unit: CurrencyUnit.SATOSHI
572
579
  }),
573
- ["MILLISATOSHI" /* MILLISATOSHI */]: formatCurrencyStr({
580
+ [CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
574
581
  value: msats,
575
- unit: "MILLISATOSHI" /* MILLISATOSHI */
582
+ unit: CurrencyUnit.MILLISATOSHI
576
583
  }),
577
- ["MICROBITCOIN" /* MICROBITCOIN */]: formatCurrencyStr({
584
+ [CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
578
585
  value: mibtc,
579
- unit: "MICROBITCOIN" /* MICROBITCOIN */
586
+ unit: CurrencyUnit.MICROBITCOIN
580
587
  }),
581
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: formatCurrencyStr({
588
+ [CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
582
589
  value: mlbtc,
583
- unit: "MILLIBITCOIN" /* MILLIBITCOIN */
590
+ unit: CurrencyUnit.MILLIBITCOIN
584
591
  }),
585
- ["NANOBITCOIN" /* NANOBITCOIN */]: formatCurrencyStr({
592
+ [CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
586
593
  value: nbtc,
587
- unit: "NANOBITCOIN" /* NANOBITCOIN */
594
+ unit: CurrencyUnit.NANOBITCOIN
588
595
  }),
589
- ["USD" /* USD */]: formatCurrencyStr({
596
+ [CurrencyUnit.USD]: formatCurrencyStr({
590
597
  value: usd,
591
- unit: "USD" /* USD */
598
+ unit: CurrencyUnit.USD
592
599
  }),
593
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: "-"
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["BITCOIN" /* BITCOIN */],
632
- sats: mapWithCurrencyUnits.formatted["SATOSHI" /* SATOSHI */],
633
- msats: mapWithCurrencyUnits.formatted["MILLISATOSHI" /* MILLISATOSHI */]
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,13 +645,13 @@ 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 "BITCOIN" /* BITCOIN */:
648
+ case CurrencyUnit.BITCOIN:
642
649
  return "BTC";
643
- case "SATOSHI" /* SATOSHI */:
650
+ case CurrencyUnit.SATOSHI:
644
651
  return "SAT";
645
- case "MILLISATOSHI" /* MILLISATOSHI */:
652
+ case CurrencyUnit.MILLISATOSHI:
646
653
  return "MSAT";
647
- case "USD" /* USD */:
654
+ case CurrencyUnit.USD:
648
655
  return "USD";
649
656
  }
650
657
  return "Unsupported CurrencyUnit";
@@ -653,33 +660,33 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
653
660
  const currencyAmount = getCurrencyAmount(amount);
654
661
  let { value: num } = currencyAmount;
655
662
  const { unit } = currencyAmount;
656
- if (unit === "USD" /* USD */) {
663
+ if (unit === CurrencyUnit.USD) {
657
664
  num = num / 100;
658
665
  }
659
666
  function getDefaultMaxFractionDigits(defaultDigits) {
660
667
  return typeof maxFractionDigits === "undefined" ? compact ? 1 : defaultDigits : maxFractionDigits;
661
668
  }
662
- const symbol = !showBtcSymbol ? "" : unit === "BITCOIN" /* BITCOIN */ ? "\uE903" : unit === "SATOSHI" /* SATOSHI */ ? "\uE902" : "";
669
+ const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
663
670
  const currentLocale = getCurrentLocale();
664
671
  switch (unit) {
665
- case "BITCOIN" /* BITCOIN */:
672
+ case CurrencyUnit.BITCOIN:
666
673
  return `${symbol}${num.toLocaleString(currentLocale, {
667
674
  notation: compact ? "compact" : void 0,
668
675
  maximumFractionDigits: getDefaultMaxFractionDigits(4),
669
676
  ...options
670
677
  })}`;
671
- case "MILLISATOSHI" /* MILLISATOSHI */:
672
- case "SATOSHI" /* SATOSHI */:
673
- case "MICROBITCOIN" /* MICROBITCOIN */:
674
- case "MILLIBITCOIN" /* MILLIBITCOIN */:
675
- case "NANOBITCOIN" /* NANOBITCOIN */:
678
+ case CurrencyUnit.MILLISATOSHI:
679
+ case CurrencyUnit.SATOSHI:
680
+ case CurrencyUnit.MICROBITCOIN:
681
+ case CurrencyUnit.MILLIBITCOIN:
682
+ case CurrencyUnit.NANOBITCOIN:
676
683
  default:
677
684
  return `${symbol}${num.toLocaleString(currentLocale, {
678
685
  notation: compact ? "compact" : void 0,
679
686
  maximumFractionDigits: getDefaultMaxFractionDigits(0),
680
687
  ...options
681
688
  })}`;
682
- case "USD" /* USD */:
689
+ case CurrencyUnit.USD:
683
690
  return num.toLocaleString(currentLocale, {
684
691
  style: "currency",
685
692
  currency: defaultCurrencyCode,
@@ -930,7 +937,7 @@ export {
930
937
  convertCurrencyAmountValue,
931
938
  convertCurrencyAmount,
932
939
  isCurrencyAmountObj,
933
- isCurrencyAmount,
940
+ isSDKCurrencyAmount,
934
941
  mapCurrencyAmount,
935
942
  isCurrencyMap,
936
943
  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
- * This enum identifies the unit of currency associated with a CurrencyAmount.
18
- * *
19
- */
20
- declare enum CurrencyUnit {
21
- /**
22
- * This is an enum value that represents values that could be added in the
23
- * future. Clients should support unknown values as more of them could be
24
- * added without notice.
25
- */
26
- FUTURE_VALUE = "FUTURE_VALUE",
27
- /**
28
- * Bitcoin is the cryptocurrency native to the Bitcoin network.
29
- * It is used as the native medium for value transfer for the Lightning
30
- * Network. *
31
- */
32
- BITCOIN = "BITCOIN",
33
- /**
34
- * 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
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
- /** The original unit of currency for this CurrencyAmount. **/
70
- originalUnit: CurrencyUnit;
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: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
87
- declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
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,15 +73,15 @@ type CurrencyMap = {
118
73
  };
119
74
  type CurrencyAmountObj = {
120
75
  value?: number | string | null;
121
- unit?: CurrencyUnit;
122
- __typename?: "CurrencyAmount";
76
+ unit?: CurrencyUnitType;
77
+ __typename?: "CurrencyAmount" | undefined;
123
78
  };
124
- type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
79
+ type CurrencyAmountArg = CurrencyAmountObj | SDKCurrencyAmountType | undefined | null;
125
80
  declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
126
- declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
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: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
84
+ declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
130
85
  declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
131
86
  declare function separateCurrencyStrParts(currencyStr: string): {
132
87
  symbol: string;
@@ -274,4 +229,4 @@ declare function lsidToUUID(lsid: string): string;
274
229
 
275
230
  declare function isUint8Array(variable: unknown): variable is Uint8Array;
276
231
 
277
- export { DeepPartial 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, pollUntil as S, sleep as T, lsidToUUID as U, isUint8Array as V, Maybe as W, ExpandRecursively as X, ById as Y, OmitTypename as Z, isType as _, b64encode as a, JSONLiteral as a0, JSONType as a1, JSONObject as a2, NN as a3, notNullUndefined as a4, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyAmountType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isCurrencyAmount 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 };
232
+ 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, 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 };