@portal-hq/web 3.2.3 → 3.3.1
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/README.md +1 -1
- package/lib/commonjs/index.js +147 -19
- package/lib/commonjs/index.test.js +548 -0
- package/lib/commonjs/mpc/errors/index.js +1 -1
- package/lib/commonjs/mpc/index.js +145 -2
- package/lib/commonjs/mpc/index.test.js +1414 -0
- package/lib/commonjs/provider/index.js +172 -39
- package/lib/commonjs/provider/index.test.js +1222 -0
- package/lib/esm/index.js +122 -18
- package/lib/esm/index.test.js +520 -0
- package/lib/esm/mpc/errors/index.js +1 -1
- package/lib/esm/mpc/index.js +145 -2
- package/lib/esm/mpc/index.test.js +1409 -0
- package/lib/esm/provider/index.js +171 -39
- package/lib/esm/provider/index.test.js +1217 -0
- package/package.json +5 -5
- package/src/__mocks/constants.ts +771 -0
- package/src/__mocks/portal/mpc.ts +27 -0
- package/src/__mocks/portal/portal.ts +14 -0
- package/src/__mocks/portal/provider.ts +7 -0
- package/src/index.test.ts +820 -0
- package/src/index.ts +183 -44
- package/src/mpc/errors/index.ts +1 -1
- package/src/mpc/index.test.ts +1716 -0
- package/src/mpc/index.ts +182 -2
- package/src/provider/index.test.ts +1570 -0
- package/src/provider/index.ts +184 -39
- package/types.d.ts +298 -33
|
@@ -12,9 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MpcErrorCodes = exports.MpcError = void 0;
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const index_1 = require("../index");
|
|
15
|
-
const WEB_SDK_VERSION = '3.
|
|
15
|
+
const WEB_SDK_VERSION = '3.3.1';
|
|
16
16
|
class Mpc {
|
|
17
|
+
get ready() {
|
|
18
|
+
return this._ready;
|
|
19
|
+
}
|
|
20
|
+
set ready(newReady) {
|
|
21
|
+
this._ready = newReady;
|
|
22
|
+
}
|
|
17
23
|
constructor({ portal }) {
|
|
24
|
+
this._ready = false;
|
|
18
25
|
this.configureIframe = () => {
|
|
19
26
|
const config = {
|
|
20
27
|
apiKey: this.portal.apiKey,
|
|
@@ -505,6 +512,105 @@ class Mpc {
|
|
|
505
512
|
});
|
|
506
513
|
});
|
|
507
514
|
}
|
|
515
|
+
getNFTAssets(chainId) {
|
|
516
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
517
|
+
return new Promise((resolve, reject) => {
|
|
518
|
+
const handleGetNFTAssets = (event) => {
|
|
519
|
+
const { type, data } = event.data;
|
|
520
|
+
const { origin } = event;
|
|
521
|
+
// ignore any broadcast postMessages
|
|
522
|
+
if (origin !== this.getOrigin()) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (type === 'portal:getNFTAssetsError') {
|
|
526
|
+
// Remove the event listener
|
|
527
|
+
window.removeEventListener('message', handleGetNFTAssets);
|
|
528
|
+
// Reject the promise with the error
|
|
529
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
530
|
+
}
|
|
531
|
+
else if (type === 'portal:getNFTAssetsResult') {
|
|
532
|
+
// Remove the event listener
|
|
533
|
+
window.removeEventListener('message', handleGetNFTAssets);
|
|
534
|
+
// Resolve the promise with the result
|
|
535
|
+
resolve(data);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
// Bind the function to the message event
|
|
539
|
+
window.addEventListener('message', handleGetNFTAssets);
|
|
540
|
+
// Send the request to the iframe
|
|
541
|
+
this.postMessage({
|
|
542
|
+
type: 'portal:getNFTAssets',
|
|
543
|
+
data: { chainId },
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
getAssets(chainId, includeNfts = false) {
|
|
549
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
550
|
+
return new Promise((resolve, reject) => {
|
|
551
|
+
const handleGetAssets = (event) => {
|
|
552
|
+
const { type, data } = event.data;
|
|
553
|
+
const { origin } = event;
|
|
554
|
+
// ignore any broadcast postMessages
|
|
555
|
+
if (origin !== this.getOrigin()) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (type === 'portal:getAssetsError') {
|
|
559
|
+
// Remove the event listener
|
|
560
|
+
window.removeEventListener('message', handleGetAssets);
|
|
561
|
+
// Reject the promise with the error
|
|
562
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
563
|
+
}
|
|
564
|
+
else if (type === 'portal:getAssetsResult') {
|
|
565
|
+
// Remove the event listener
|
|
566
|
+
window.removeEventListener('message', handleGetAssets);
|
|
567
|
+
// Resolve the promise with the result
|
|
568
|
+
resolve(data);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
// Bind the function to the message event
|
|
572
|
+
window.addEventListener('message', handleGetAssets);
|
|
573
|
+
// Send the request to the iframe
|
|
574
|
+
this.postMessage({
|
|
575
|
+
type: 'portal:getAssets',
|
|
576
|
+
data: { chainId, includeNfts },
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
buildTransaction(chainId, to, token, amount) {
|
|
582
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
583
|
+
return new Promise((resolve, reject) => {
|
|
584
|
+
const handlebuildTransaction = (event) => {
|
|
585
|
+
const { type, data } = event.data;
|
|
586
|
+
const { origin } = event;
|
|
587
|
+
// ignore any broadcast postMessages
|
|
588
|
+
if (origin !== this.getOrigin()) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (type === 'portal:buildTransactionError') {
|
|
592
|
+
// Remove the event listener
|
|
593
|
+
window.removeEventListener('message', handlebuildTransaction);
|
|
594
|
+
// Reject the promise with the error
|
|
595
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
596
|
+
}
|
|
597
|
+
else if (type === 'portal:buildTransactionResult') {
|
|
598
|
+
// Remove the event listener
|
|
599
|
+
window.removeEventListener('message', handlebuildTransaction);
|
|
600
|
+
// Resolve the promise with the result
|
|
601
|
+
resolve(data);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
// Bind the function to the message event
|
|
605
|
+
window.addEventListener('message', handlebuildTransaction);
|
|
606
|
+
// Send the request to the iframe
|
|
607
|
+
this.postMessage({
|
|
608
|
+
type: 'portal:buildTransaction',
|
|
609
|
+
data: { chainId, to, token, amount },
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
}
|
|
508
614
|
getQuote(apiKey, args, chainId) {
|
|
509
615
|
return __awaiter(this, void 0, void 0, function* () {
|
|
510
616
|
return new Promise((resolve, reject) => {
|
|
@@ -687,6 +793,43 @@ class Mpc {
|
|
|
687
793
|
});
|
|
688
794
|
});
|
|
689
795
|
}
|
|
796
|
+
evaluateTransaction(chainId, transaction, operationType = 'all') {
|
|
797
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
798
|
+
return new Promise((resolve, reject) => {
|
|
799
|
+
const handleEvaluateTransaction = (event) => {
|
|
800
|
+
const { type, data } = event.data;
|
|
801
|
+
const { origin } = event;
|
|
802
|
+
// ignore any broadcast postMessages
|
|
803
|
+
if (origin !== this.getOrigin()) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (type === 'portal:evaluateTransactionError') {
|
|
807
|
+
// Remove the event listener
|
|
808
|
+
window.removeEventListener('message', handleEvaluateTransaction);
|
|
809
|
+
// Reject the promise with the error
|
|
810
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
811
|
+
}
|
|
812
|
+
else if (type === 'portal:evaluateTransactionResult') {
|
|
813
|
+
// Remove the event listener
|
|
814
|
+
window.removeEventListener('message', handleEvaluateTransaction);
|
|
815
|
+
// Resolve the promise with the result
|
|
816
|
+
resolve(data);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
// Bind the function to the message event
|
|
820
|
+
window.addEventListener('message', handleEvaluateTransaction);
|
|
821
|
+
// Send the request to the iframe
|
|
822
|
+
this.postMessage({
|
|
823
|
+
type: 'portal:evaluateTransaction',
|
|
824
|
+
data: {
|
|
825
|
+
chainId,
|
|
826
|
+
transaction,
|
|
827
|
+
operationType,
|
|
828
|
+
},
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}
|
|
690
833
|
storedClientBackupShare(success, backupMethod) {
|
|
691
834
|
return new Promise((resolve, reject) => {
|
|
692
835
|
const handleStoredClientBackupShare = (event) => {
|
|
@@ -845,7 +988,7 @@ class Mpc {
|
|
|
845
988
|
window.removeEventListener('message', handleReady);
|
|
846
989
|
window.removeEventListener('message', handleError);
|
|
847
990
|
// Update ready state
|
|
848
|
-
this.
|
|
991
|
+
this.ready = true;
|
|
849
992
|
// Update the address
|
|
850
993
|
const address = yield this.getAddress();
|
|
851
994
|
this.portal.address = address;
|