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