@lightsparkdev/core 1.4.2 → 1.4.4

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,19 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 031eb1b: - Resolve circular dependencies
8
+ - React Native compatible entrypoint
9
+
10
+ ## 1.4.3
11
+
12
+ ### Patch Changes
13
+
14
+ - e9152bc: - Add INR support to utils/currency
15
+ - Avoid loading graphql-ws in Bare environment due to lack of support there
16
+
3
17
  ## 1.4.2
4
18
 
5
19
  ### 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
@@ -50,6 +50,8 @@ var b64encode = (data) => {
50
50
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
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
+ var isBare = typeof Bare !== "undefined";
54
+ var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
53
55
 
54
56
  // src/utils/hex.ts
55
57
  var bytesToHex = (bytes) => {
@@ -410,6 +412,7 @@ var CurrencyUnit = {
410
412
  PHP: "PHP",
411
413
  EUR: "EUR",
412
414
  GBP: "GBP",
415
+ INR: "INR",
413
416
  Bitcoin: "BITCOIN",
414
417
  Microbitcoin: "MICROBITCOIN",
415
418
  Millibitcoin: "MILLIBITCOIN",
@@ -419,7 +422,8 @@ var CurrencyUnit = {
419
422
  Usd: "USD",
420
423
  Mxn: "MXN",
421
424
  Php: "PHP",
422
- Gbp: "GBP"
425
+ Gbp: "GBP",
426
+ Inr: "INR"
423
427
  };
424
428
  var standardUnitConversionObj = {
425
429
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -433,7 +437,8 @@ var standardUnitConversionObj = {
433
437
  [CurrencyUnit.MXN]: (v) => v,
434
438
  [CurrencyUnit.PHP]: (v) => v,
435
439
  [CurrencyUnit.EUR]: (v) => v,
436
- [CurrencyUnit.GBP]: (v) => v
440
+ [CurrencyUnit.GBP]: (v) => v,
441
+ [CurrencyUnit.INR]: (v) => v
437
442
  };
438
443
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
439
444
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -453,7 +458,8 @@ var CONVERSION_MAP = {
453
458
  [CurrencyUnit.MXN]: toBitcoinConversion,
454
459
  [CurrencyUnit.PHP]: toBitcoinConversion,
455
460
  [CurrencyUnit.EUR]: toBitcoinConversion,
456
- [CurrencyUnit.GBP]: toBitcoinConversion
461
+ [CurrencyUnit.GBP]: toBitcoinConversion,
462
+ [CurrencyUnit.INR]: toBitcoinConversion
457
463
  },
458
464
  [CurrencyUnit.MICROBITCOIN]: {
459
465
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -466,7 +472,8 @@ var CONVERSION_MAP = {
466
472
  [CurrencyUnit.MXN]: toMicrobitcoinConversion,
467
473
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
468
474
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
469
- [CurrencyUnit.GBP]: toMicrobitcoinConversion
475
+ [CurrencyUnit.GBP]: toMicrobitcoinConversion,
476
+ [CurrencyUnit.INR]: toMicrobitcoinConversion
470
477
  },
471
478
  [CurrencyUnit.MILLIBITCOIN]: {
472
479
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -479,7 +486,8 @@ var CONVERSION_MAP = {
479
486
  [CurrencyUnit.MXN]: toMillibitcoinConversion,
480
487
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
481
488
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
482
- [CurrencyUnit.GBP]: toMillibitcoinConversion
489
+ [CurrencyUnit.GBP]: toMillibitcoinConversion,
490
+ [CurrencyUnit.INR]: toMillibitcoinConversion
483
491
  },
484
492
  [CurrencyUnit.MILLISATOSHI]: {
485
493
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -492,7 +500,8 @@ var CONVERSION_MAP = {
492
500
  [CurrencyUnit.MXN]: toMillisatoshiConversion,
493
501
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
494
502
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
495
- [CurrencyUnit.GBP]: toMillisatoshiConversion
503
+ [CurrencyUnit.GBP]: toMillisatoshiConversion,
504
+ [CurrencyUnit.INR]: toMillisatoshiConversion
496
505
  },
497
506
  [CurrencyUnit.NANOBITCOIN]: {
498
507
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -505,7 +514,8 @@ var CONVERSION_MAP = {
505
514
  [CurrencyUnit.MXN]: toNanobitcoinConversion,
506
515
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
507
516
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
508
- [CurrencyUnit.GBP]: toNanobitcoinConversion
517
+ [CurrencyUnit.GBP]: toNanobitcoinConversion,
518
+ [CurrencyUnit.INR]: toNanobitcoinConversion
509
519
  },
510
520
  [CurrencyUnit.SATOSHI]: {
511
521
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -518,13 +528,15 @@ var CONVERSION_MAP = {
518
528
  [CurrencyUnit.MXN]: toSatoshiConversion,
519
529
  [CurrencyUnit.PHP]: toSatoshiConversion,
520
530
  [CurrencyUnit.EUR]: toSatoshiConversion,
521
- [CurrencyUnit.GBP]: toSatoshiConversion
531
+ [CurrencyUnit.GBP]: toSatoshiConversion,
532
+ [CurrencyUnit.INR]: toSatoshiConversion
522
533
  },
523
534
  [CurrencyUnit.USD]: standardUnitConversionObj,
524
535
  [CurrencyUnit.MXN]: standardUnitConversionObj,
525
536
  [CurrencyUnit.PHP]: standardUnitConversionObj,
526
537
  [CurrencyUnit.EUR]: standardUnitConversionObj,
527
- [CurrencyUnit.GBP]: standardUnitConversionObj
538
+ [CurrencyUnit.GBP]: standardUnitConversionObj,
539
+ [CurrencyUnit.INR]: standardUnitConversionObj
528
540
  };
529
541
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
530
542
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -609,6 +621,7 @@ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversi
609
621
  php: CurrencyUnit.PHP,
610
622
  eur: CurrencyUnit.EUR,
611
623
  gbp: CurrencyUnit.GBP,
624
+ inr: CurrencyUnit.INR,
612
625
  mibtc: CurrencyUnit.MICROBITCOIN,
613
626
  mlbtc: CurrencyUnit.MILLIBITCOIN,
614
627
  nbtc: CurrencyUnit.NANOBITCOIN
@@ -647,7 +660,7 @@ function getPreferredConversionOverride(currencyAmountArg) {
647
660
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
648
661
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
649
662
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
650
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
663
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
651
664
  const mapWithCurrencyUnits = {
652
665
  [CurrencyUnit.BITCOIN]: btc,
653
666
  [CurrencyUnit.SATOSHI]: sats,
@@ -657,6 +670,7 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
657
670
  [CurrencyUnit.PHP]: php,
658
671
  [CurrencyUnit.EUR]: eur,
659
672
  [CurrencyUnit.GBP]: gbp,
673
+ [CurrencyUnit.INR]: inr,
660
674
  [CurrencyUnit.MICROBITCOIN]: mibtc,
661
675
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
662
676
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -706,6 +720,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
706
720
  value: gbp,
707
721
  unit: CurrencyUnit.GBP
708
722
  }),
723
+ [CurrencyUnit.INR]: formatCurrencyStr({
724
+ value: inr,
725
+ unit: CurrencyUnit.INR
726
+ }),
709
727
  [CurrencyUnit.FUTURE_VALUE]: "-"
710
728
  }
711
729
  };
@@ -774,6 +792,8 @@ var abbrCurrencyUnit = (unit) => {
774
792
  return "EUR";
775
793
  case CurrencyUnit.GBP:
776
794
  return "GBP";
795
+ case CurrencyUnit.INR:
796
+ return "INR";
777
797
  }
778
798
  return "Unsupported CurrencyUnit";
779
799
  };
@@ -906,6 +926,15 @@ function localeToCurrencySymbol(locale) {
906
926
  const { symbol } = separateCurrencyStrParts(formatted);
907
927
  return symbol;
908
928
  }
929
+ function formatInviteAmount(amount, currency) {
930
+ if (!amount || !currency) {
931
+ return "";
932
+ }
933
+ const displayAmount = (amount / Math.pow(10, currency.decimals)).toFixed(
934
+ currency.decimals
935
+ );
936
+ return `${displayAmount} ${currency.code}`;
937
+ }
909
938
 
910
939
  // src/utils/typeGuards.ts
911
940
  function isUint8Array(value) {
@@ -2197,17 +2226,23 @@ function zipcodeToState(zipcode) {
2197
2226
  }
2198
2227
 
2199
2228
  export {
2229
+ isBrowser,
2230
+ isNode,
2231
+ isTest,
2232
+ isBare,
2233
+ isReactNative,
2200
2234
  LightsparkException_default,
2201
2235
  b64decode,
2202
2236
  urlsafe_b64decode,
2203
2237
  b64encode,
2204
- ensureArray,
2205
- isBrowser,
2206
- isNode,
2207
- isTest,
2238
+ getLocalStorageConfigItem,
2239
+ getLocalStorageBoolean,
2240
+ setLocalStorageBoolean,
2241
+ deleteLocalStorageItem,
2208
2242
  bytesToHex,
2209
2243
  hexToBytes,
2210
2244
  createSha256Hash,
2245
+ ensureArray,
2211
2246
  getCurrentLocale,
2212
2247
  countryCodesToCurrencyCodes,
2213
2248
  localeToCurrencyCode,
@@ -2232,6 +2267,7 @@ export {
2232
2267
  formatCurrencyStr,
2233
2268
  separateCurrencyStrParts,
2234
2269
  localeToCurrencySymbol,
2270
+ formatInviteAmount,
2235
2271
  isUint8Array,
2236
2272
  isObject,
2237
2273
  isRecord,
@@ -2240,10 +2276,6 @@ export {
2240
2276
  getErrorMsg,
2241
2277
  isErrorMsg,
2242
2278
  errorToJSON,
2243
- getLocalStorageConfigItem,
2244
- getLocalStorageBoolean,
2245
- setLocalStorageBoolean,
2246
- deleteLocalStorageItem,
2247
2279
  sleep,
2248
2280
  pollUntil,
2249
2281
  lsidToUUID,