@lightsparkdev/core 1.4.3 → 1.4.5

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,18 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 8fd199a: - Add USDT to supported currencies
8
+
9
+ ## 1.4.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 031eb1b: - Resolve circular dependencies
14
+ - React Native compatible entrypoint
15
+
3
16
  ## 1.4.3
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -11,5 +11,3 @@ To use the package, you'll need to install it from npm:
11
11
  ```bash
12
12
  $ npm install @lightsparkdev/core
13
13
  ```
14
-
15
- TODO
@@ -51,6 +51,7 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
51
51
  var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
52
52
  var isTest = isNode && process.env.NODE_ENV === "test";
53
53
  var isBare = typeof Bare !== "undefined";
54
+ var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
54
55
 
55
56
  // src/utils/hex.ts
56
57
  var bytesToHex = (bytes) => {
@@ -412,6 +413,7 @@ var CurrencyUnit = {
412
413
  EUR: "EUR",
413
414
  GBP: "GBP",
414
415
  INR: "INR",
416
+ USDT: "USDT",
415
417
  Bitcoin: "BITCOIN",
416
418
  Microbitcoin: "MICROBITCOIN",
417
419
  Millibitcoin: "MILLIBITCOIN",
@@ -422,7 +424,8 @@ var CurrencyUnit = {
422
424
  Mxn: "MXN",
423
425
  Php: "PHP",
424
426
  Gbp: "GBP",
425
- Inr: "INR"
427
+ Inr: "INR",
428
+ Usdt: "USDT"
426
429
  };
427
430
  var standardUnitConversionObj = {
428
431
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -437,7 +440,8 @@ var standardUnitConversionObj = {
437
440
  [CurrencyUnit.PHP]: (v) => v,
438
441
  [CurrencyUnit.EUR]: (v) => v,
439
442
  [CurrencyUnit.GBP]: (v) => v,
440
- [CurrencyUnit.INR]: (v) => v
443
+ [CurrencyUnit.INR]: (v) => v,
444
+ [CurrencyUnit.USDT]: (v) => v
441
445
  };
442
446
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
443
447
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -458,7 +462,8 @@ var CONVERSION_MAP = {
458
462
  [CurrencyUnit.PHP]: toBitcoinConversion,
459
463
  [CurrencyUnit.EUR]: toBitcoinConversion,
460
464
  [CurrencyUnit.GBP]: toBitcoinConversion,
461
- [CurrencyUnit.INR]: toBitcoinConversion
465
+ [CurrencyUnit.INR]: toBitcoinConversion,
466
+ [CurrencyUnit.USDT]: toBitcoinConversion
462
467
  },
463
468
  [CurrencyUnit.MICROBITCOIN]: {
464
469
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -472,7 +477,8 @@ var CONVERSION_MAP = {
472
477
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
473
478
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
474
479
  [CurrencyUnit.GBP]: toMicrobitcoinConversion,
475
- [CurrencyUnit.INR]: toMicrobitcoinConversion
480
+ [CurrencyUnit.INR]: toMicrobitcoinConversion,
481
+ [CurrencyUnit.USDT]: toMicrobitcoinConversion
476
482
  },
477
483
  [CurrencyUnit.MILLIBITCOIN]: {
478
484
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -486,7 +492,8 @@ var CONVERSION_MAP = {
486
492
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
487
493
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
488
494
  [CurrencyUnit.GBP]: toMillibitcoinConversion,
489
- [CurrencyUnit.INR]: toMillibitcoinConversion
495
+ [CurrencyUnit.INR]: toMillibitcoinConversion,
496
+ [CurrencyUnit.USDT]: toMillibitcoinConversion
490
497
  },
491
498
  [CurrencyUnit.MILLISATOSHI]: {
492
499
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -500,7 +507,8 @@ var CONVERSION_MAP = {
500
507
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
501
508
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
502
509
  [CurrencyUnit.GBP]: toMillisatoshiConversion,
503
- [CurrencyUnit.INR]: toMillisatoshiConversion
510
+ [CurrencyUnit.INR]: toMillisatoshiConversion,
511
+ [CurrencyUnit.USDT]: toMillisatoshiConversion
504
512
  },
505
513
  [CurrencyUnit.NANOBITCOIN]: {
506
514
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -514,7 +522,8 @@ var CONVERSION_MAP = {
514
522
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
515
523
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
516
524
  [CurrencyUnit.GBP]: toNanobitcoinConversion,
517
- [CurrencyUnit.INR]: toNanobitcoinConversion
525
+ [CurrencyUnit.INR]: toNanobitcoinConversion,
526
+ [CurrencyUnit.USDT]: toNanobitcoinConversion
518
527
  },
519
528
  [CurrencyUnit.SATOSHI]: {
520
529
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -528,14 +537,16 @@ var CONVERSION_MAP = {
528
537
  [CurrencyUnit.PHP]: toSatoshiConversion,
529
538
  [CurrencyUnit.EUR]: toSatoshiConversion,
530
539
  [CurrencyUnit.GBP]: toSatoshiConversion,
531
- [CurrencyUnit.INR]: toSatoshiConversion
540
+ [CurrencyUnit.INR]: toSatoshiConversion,
541
+ [CurrencyUnit.USDT]: toSatoshiConversion
532
542
  },
533
543
  [CurrencyUnit.USD]: standardUnitConversionObj,
534
544
  [CurrencyUnit.MXN]: standardUnitConversionObj,
535
545
  [CurrencyUnit.PHP]: standardUnitConversionObj,
536
546
  [CurrencyUnit.EUR]: standardUnitConversionObj,
537
547
  [CurrencyUnit.GBP]: standardUnitConversionObj,
538
- [CurrencyUnit.INR]: standardUnitConversionObj
548
+ [CurrencyUnit.INR]: standardUnitConversionObj,
549
+ [CurrencyUnit.USDT]: standardUnitConversionObj
539
550
  };
540
551
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
541
552
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -623,7 +634,8 @@ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversi
623
634
  inr: CurrencyUnit.INR,
624
635
  mibtc: CurrencyUnit.MICROBITCOIN,
625
636
  mlbtc: CurrencyUnit.MILLIBITCOIN,
626
- nbtc: CurrencyUnit.NANOBITCOIN
637
+ nbtc: CurrencyUnit.NANOBITCOIN,
638
+ usdt: CurrencyUnit.USDT
627
639
  };
628
640
  return Object.entries(namesToUnits).reduce(
629
641
  (acc, [name, unit]) => {
@@ -659,7 +671,21 @@ function getPreferredConversionOverride(currencyAmountArg) {
659
671
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
660
672
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
661
673
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
662
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
674
+ const {
675
+ sats,
676
+ msats,
677
+ btc,
678
+ usd,
679
+ mxn,
680
+ php,
681
+ mibtc,
682
+ mlbtc,
683
+ nbtc,
684
+ eur,
685
+ gbp,
686
+ inr,
687
+ usdt
688
+ } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
663
689
  const mapWithCurrencyUnits = {
664
690
  [CurrencyUnit.BITCOIN]: btc,
665
691
  [CurrencyUnit.SATOSHI]: sats,
@@ -673,6 +699,7 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
673
699
  [CurrencyUnit.MICROBITCOIN]: mibtc,
674
700
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
675
701
  [CurrencyUnit.NANOBITCOIN]: nbtc,
702
+ [CurrencyUnit.USDT]: usdt,
676
703
  [CurrencyUnit.FUTURE_VALUE]: NaN,
677
704
  formatted: {
678
705
  [CurrencyUnit.BITCOIN]: formatCurrencyStr({
@@ -723,6 +750,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
723
750
  value: inr,
724
751
  unit: CurrencyUnit.INR
725
752
  }),
753
+ [CurrencyUnit.USDT]: formatCurrencyStr({
754
+ value: usdt,
755
+ unit: CurrencyUnit.USDT
756
+ }),
726
757
  [CurrencyUnit.FUTURE_VALUE]: "-"
727
758
  }
728
759
  };
@@ -793,6 +824,8 @@ var abbrCurrencyUnit = (unit) => {
793
824
  return "GBP";
794
825
  case CurrencyUnit.INR:
795
826
  return "INR";
827
+ case CurrencyUnit.USDT:
828
+ return "USDT";
796
829
  }
797
830
  return "Unsupported CurrencyUnit";
798
831
  };
@@ -2225,18 +2258,23 @@ function zipcodeToState(zipcode) {
2225
2258
  }
2226
2259
 
2227
2260
  export {
2228
- LightsparkException_default,
2229
- b64decode,
2230
- urlsafe_b64decode,
2231
- b64encode,
2232
- ensureArray,
2233
2261
  isBrowser,
2234
2262
  isNode,
2235
2263
  isTest,
2236
2264
  isBare,
2265
+ isReactNative,
2266
+ LightsparkException_default,
2267
+ b64decode,
2268
+ urlsafe_b64decode,
2269
+ b64encode,
2270
+ getLocalStorageConfigItem,
2271
+ getLocalStorageBoolean,
2272
+ setLocalStorageBoolean,
2273
+ deleteLocalStorageItem,
2237
2274
  bytesToHex,
2238
2275
  hexToBytes,
2239
2276
  createSha256Hash,
2277
+ ensureArray,
2240
2278
  getCurrentLocale,
2241
2279
  countryCodesToCurrencyCodes,
2242
2280
  localeToCurrencyCode,
@@ -2270,10 +2308,6 @@ export {
2270
2308
  getErrorMsg,
2271
2309
  isErrorMsg,
2272
2310
  errorToJSON,
2273
- getLocalStorageConfigItem,
2274
- getLocalStorageBoolean,
2275
- setLocalStorageBoolean,
2276
- deleteLocalStorageItem,
2277
2311
  sleep,
2278
2312
  pollUntil,
2279
2313
  lsidToUUID,