@txnlab/use-wallet 0.0.8 → 0.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.
@@ -5,6 +5,6 @@ export declare enum PROVIDER_ID {
5
5
  DEFLY = "Defly",
6
6
  EXODUS = "Exodus"
7
7
  }
8
- export declare const NODE_SERVER = "https://mainnet-api.algonode.cloud";
9
- export declare const NODE_TOKEN = "";
10
- export declare const NODE_PORT = "";
8
+ export declare const NODE_SERVER: string;
9
+ export declare const NODE_TOKEN: string;
10
+ export declare const NODE_PORT: string;
@@ -1,3 +1,6 @@
1
1
  export { useWallet, useConnectWallet } from "./hooks";
2
2
  export * from "./constants";
3
3
  export * from "./types";
4
+ export * from "./utils";
5
+ export * from "./providers";
6
+ export * from "./clients";
package/dist/cjs/index.js CHANGED
@@ -520,9 +520,11 @@ exports.PROVIDER_ID = void 0;
520
520
  PROVIDER_ID["DEFLY"] = "Defly";
521
521
  PROVIDER_ID["EXODUS"] = "Exodus";
522
522
  })(exports.PROVIDER_ID || (exports.PROVIDER_ID = {}));
523
- const NODE_SERVER = "https://mainnet-api.algonode.cloud";
524
- const NODE_TOKEN = "";
525
- const NODE_PORT = "";
523
+ const NODE_SERVER = process.env.REACT_APP_NODE_URL ||
524
+ process.env.NEXT_PUBLIC_NODE_URL ||
525
+ "https://mainnet-api.algonode.cloud";
526
+ const NODE_TOKEN = process.env.REACT_APP_NODE_TOKEN || process.env.NEXT_PUBLIC_NODE_TOKEN || "";
527
+ const NODE_PORT = process.env.REACT_APP_NODE_PORT || process.env.NEXT_PUBLIC_NODE_PORT || "";
526
528
 
527
529
  /*
528
530
  * big.js v6.2.1
@@ -541,13 +543,47 @@ const NODE_PORT = "";
541
543
  * The maximum number of decimal places (DP) of the results of operations involving division:
542
544
  * div and sqrt, and pow with negative exponents.
543
545
  */
544
- var // The maximum value of DP and Big.DP.
546
+ var DP = 20, // 0 to MAX_DP
547
+
548
+ /*
549
+ * The rounding mode (RM) used when rounding to the above decimal places.
550
+ *
551
+ * 0 Towards zero (i.e. truncate, no rounding). (ROUND_DOWN)
552
+ * 1 To nearest neighbour. If equidistant, round up. (ROUND_HALF_UP)
553
+ * 2 To nearest neighbour. If equidistant, to even. (ROUND_HALF_EVEN)
554
+ * 3 Away from zero. (ROUND_UP)
555
+ */
556
+ RM = 1, // 0, 1, 2 or 3
557
+
558
+ // The maximum value of DP and Big.DP.
545
559
  MAX_DP = 1E6, // 0 to 1000000
546
560
 
547
561
  // The maximum magnitude of the exponent argument to the pow method.
548
562
  MAX_POWER = 1E6, // 1 to 1000000
549
563
 
550
- /**************************************************************************************************/
564
+ /*
565
+ * The negative exponent (NE) at and beneath which toString returns exponential notation.
566
+ * (JavaScript numbers: -7)
567
+ * -1000000 is the minimum recommended exponent value of a Big.
568
+ */
569
+ NE = -7, // 0 to -1000000
570
+
571
+ /*
572
+ * The positive exponent (PE) at and above which toString returns exponential notation.
573
+ * (JavaScript numbers: 21)
574
+ * 1000000 is the maximum recommended exponent value of a Big, but this limit is not enforced.
575
+ */
576
+ PE = 21, // 0 to 1000000
577
+
578
+ /*
579
+ * When true, an error will be thrown if a primitive number is passed to the Big constructor,
580
+ * or if valueOf is called, or if toNumber is called on a Big which cannot be converted to a
581
+ * primitive number without a loss of precision.
582
+ */
583
+ STRICT = false, // true or false
584
+
585
+
586
+ /**************************************************************************************************/
551
587
 
552
588
 
553
589
  // Error messages.
@@ -559,7 +595,119 @@ var // The maximum value of DP and Big.DP.
559
595
 
560
596
  // The shared prototype object.
561
597
  P = {},
562
- UNDEFINED = void 0;
598
+ UNDEFINED = void 0,
599
+ NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
600
+
601
+
602
+ /*
603
+ * Create and return a Big constructor.
604
+ */
605
+ function _Big_() {
606
+
607
+ /*
608
+ * The Big constructor and exported function.
609
+ * Create and return a new instance of a Big number object.
610
+ *
611
+ * n {number|string|Big} A numeric value.
612
+ */
613
+ function Big(n) {
614
+ var x = this;
615
+
616
+ // Enable constructor usage without new.
617
+ if (!(x instanceof Big)) return n === UNDEFINED ? _Big_() : new Big(n);
618
+
619
+ // Duplicate.
620
+ if (n instanceof Big) {
621
+ x.s = n.s;
622
+ x.e = n.e;
623
+ x.c = n.c.slice();
624
+ } else {
625
+ if (typeof n !== 'string') {
626
+ if (Big.strict === true && typeof n !== 'bigint') {
627
+ throw TypeError(INVALID + 'value');
628
+ }
629
+
630
+ // Minus zero?
631
+ n = n === 0 && 1 / n < 0 ? '-0' : String(n);
632
+ }
633
+
634
+ parse(x, n);
635
+ }
636
+
637
+ // Retain a reference to this Big constructor.
638
+ // Shadow Big.prototype.constructor which points to Object.
639
+ x.constructor = Big;
640
+ }
641
+
642
+ Big.prototype = P;
643
+ Big.DP = DP;
644
+ Big.RM = RM;
645
+ Big.NE = NE;
646
+ Big.PE = PE;
647
+ Big.strict = STRICT;
648
+ Big.roundDown = 0;
649
+ Big.roundHalfUp = 1;
650
+ Big.roundHalfEven = 2;
651
+ Big.roundUp = 3;
652
+
653
+ return Big;
654
+ }
655
+
656
+
657
+ /*
658
+ * Parse the number or string value passed to a Big constructor.
659
+ *
660
+ * x {Big} A Big number instance.
661
+ * n {number|string} A numeric value.
662
+ */
663
+ function parse(x, n) {
664
+ var e, i, nl;
665
+
666
+ if (!NUMERIC.test(n)) {
667
+ throw Error(INVALID + 'number');
668
+ }
669
+
670
+ // Determine sign.
671
+ x.s = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1;
672
+
673
+ // Decimal point?
674
+ if ((e = n.indexOf('.')) > -1) n = n.replace('.', '');
675
+
676
+ // Exponential form?
677
+ if ((i = n.search(/e/i)) > 0) {
678
+
679
+ // Determine exponent.
680
+ if (e < 0) e = i;
681
+ e += +n.slice(i + 1);
682
+ n = n.substring(0, i);
683
+ } else if (e < 0) {
684
+
685
+ // Integer.
686
+ e = n.length;
687
+ }
688
+
689
+ nl = n.length;
690
+
691
+ // Determine leading zeros.
692
+ for (i = 0; i < nl && n.charAt(i) == '0';) ++i;
693
+
694
+ if (i == nl) {
695
+
696
+ // Zero.
697
+ x.c = [x.e = 0];
698
+ } else {
699
+
700
+ // Determine trailing zeros.
701
+ for (; nl > 0 && n.charAt(--nl) == '0';);
702
+ x.e = e - i - 1;
703
+ x.c = [];
704
+
705
+ // Convert string to array of digits without leading/trailing zeros.
706
+ for (e = 0; i <= nl;) x.c[e++] = +n.charAt(i++);
707
+ }
708
+
709
+ return x;
710
+ }
563
711
 
564
712
 
565
713
  /*
@@ -1395,7 +1543,13 @@ P.valueOf = function () {
1395
1543
  throw Error(NAME + 'valueOf disallowed');
1396
1544
  }
1397
1545
  return stringify(x, x.e <= Big.NE || x.e >= Big.PE, true);
1398
- };
1546
+ };
1547
+
1548
+
1549
+ // Export
1550
+
1551
+
1552
+ var Big = _Big_();
1399
1553
 
1400
1554
  const icon$4 = "data:image/svg+xml;base64," +
1401
1555
  "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNzcgMTg3Ij48cmVjdCB4PSItMTEuMzgiIHk9Ii0yNS45NyIgd2lkdGg9IjIwMC4wMiIgaGVpZ2h0PSIyMzEuNTMiIHN0eWxlPSJmaWxsOiNmZTU7Ii8+PHBhdGggZD0iTTk0LjA1LDU5LjYxYzIuMDUsOC40OCwxLjM2LDE1Ljk0LTEuNTUsMTYuNjYtMi45LC43Mi02LjkxLTUuNTctOC45Ni0xNC4wNS0yLjA1LTguNDgtMS4zNi0xNS45NCwxLjU1LTE2LjY2LDIuOS0uNzIsNi45MSw1LjU3LDguOTYsMTQuMDVaIiBzdHlsZT0iZmlsbDojMWMxYzFjOyIvPjxwYXRoIGQ9Ik0xMjcuODUsNjYuOWMtNC41My00LjgxLTEzLjU1LTMuNS0yMC4xNSwyLjkxLTYuNTksNi40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new Error(`No wallet client found for provider id: ${id}`);
3373
3527
  }
3374
3528
  return client;
3529
+ };
3530
+ const formatPrice = (price, isAlgos, options) => {
3531
+ const algos = isAlgos ? price : convertMicroalgosToAlgos(price);
3532
+ return new Intl.NumberFormat(undefined, options).format(algos);
3533
+ };
3534
+ // Formula: amount / (10 ^ decimals)
3535
+ const convertMicroalgosToAlgos = (amount) => {
3536
+ const divisor = new Big(10).pow(6);
3537
+ return new Big(amount).div(divisor).round(6).toNumber();
3375
3538
  };
3376
3539
 
3377
3540
  function useWallet() {
@@ -3530,6 +3693,11 @@ function useConnectWallet() {
3530
3693
  exports.NODE_PORT = NODE_PORT;
3531
3694
  exports.NODE_SERVER = NODE_SERVER;
3532
3695
  exports.NODE_TOKEN = NODE_TOKEN;
3696
+ exports.clients = clients;
3697
+ exports.convertMicroalgosToAlgos = convertMicroalgosToAlgos;
3698
+ exports.formatPrice = formatPrice;
3699
+ exports.getWalletClient = getWalletClient;
3700
+ exports.providers = providers;
3533
3701
  exports.useConnectWallet = useConnectWallet;
3534
3702
  exports.useWallet = useWallet;
3535
3703
  //# sourceMappingURL=index.js.map