@portal-hq/web 3.2.3 → 3.3.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.
@@ -9,9 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { PortalMpcError } from './errors';
11
11
  import { BackupMethods, } from '../index';
12
- const WEB_SDK_VERSION = '3.2.3';
12
+ const WEB_SDK_VERSION = '3.3.0';
13
13
  class Mpc {
14
+ get ready() {
15
+ return this._ready;
16
+ }
17
+ set ready(newReady) {
18
+ this._ready = newReady;
19
+ }
14
20
  constructor({ portal }) {
21
+ this._ready = false;
15
22
  this.configureIframe = () => {
16
23
  const config = {
17
24
  apiKey: this.portal.apiKey,
@@ -502,6 +509,105 @@ class Mpc {
502
509
  });
503
510
  });
504
511
  }
512
+ getNFTAssets(chainId) {
513
+ return __awaiter(this, void 0, void 0, function* () {
514
+ return new Promise((resolve, reject) => {
515
+ const handleGetNFTAssets = (event) => {
516
+ const { type, data } = event.data;
517
+ const { origin } = event;
518
+ // ignore any broadcast postMessages
519
+ if (origin !== this.getOrigin()) {
520
+ return;
521
+ }
522
+ if (type === 'portal:getNFTAssetsError') {
523
+ // Remove the event listener
524
+ window.removeEventListener('message', handleGetNFTAssets);
525
+ // Reject the promise with the error
526
+ return reject(new PortalMpcError(data));
527
+ }
528
+ else if (type === 'portal:getNFTAssetsResult') {
529
+ // Remove the event listener
530
+ window.removeEventListener('message', handleGetNFTAssets);
531
+ // Resolve the promise with the result
532
+ resolve(data);
533
+ }
534
+ };
535
+ // Bind the function to the message event
536
+ window.addEventListener('message', handleGetNFTAssets);
537
+ // Send the request to the iframe
538
+ this.postMessage({
539
+ type: 'portal:getNFTAssets',
540
+ data: { chainId },
541
+ });
542
+ });
543
+ });
544
+ }
545
+ getAssets(chainId, includeNfts = false) {
546
+ return __awaiter(this, void 0, void 0, function* () {
547
+ return new Promise((resolve, reject) => {
548
+ const handleGetAssets = (event) => {
549
+ const { type, data } = event.data;
550
+ const { origin } = event;
551
+ // ignore any broadcast postMessages
552
+ if (origin !== this.getOrigin()) {
553
+ return;
554
+ }
555
+ if (type === 'portal:getAssetsError') {
556
+ // Remove the event listener
557
+ window.removeEventListener('message', handleGetAssets);
558
+ // Reject the promise with the error
559
+ return reject(new PortalMpcError(data));
560
+ }
561
+ else if (type === 'portal:getAssetsResult') {
562
+ // Remove the event listener
563
+ window.removeEventListener('message', handleGetAssets);
564
+ // Resolve the promise with the result
565
+ resolve(data);
566
+ }
567
+ };
568
+ // Bind the function to the message event
569
+ window.addEventListener('message', handleGetAssets);
570
+ // Send the request to the iframe
571
+ this.postMessage({
572
+ type: 'portal:getAssets',
573
+ data: { chainId, includeNfts },
574
+ });
575
+ });
576
+ });
577
+ }
578
+ buildTransaction(chainId, to, token, amount) {
579
+ return __awaiter(this, void 0, void 0, function* () {
580
+ return new Promise((resolve, reject) => {
581
+ const handlebuildTransaction = (event) => {
582
+ const { type, data } = event.data;
583
+ const { origin } = event;
584
+ // ignore any broadcast postMessages
585
+ if (origin !== this.getOrigin()) {
586
+ return;
587
+ }
588
+ if (type === 'portal:buildTransactionError') {
589
+ // Remove the event listener
590
+ window.removeEventListener('message', handlebuildTransaction);
591
+ // Reject the promise with the error
592
+ return reject(new PortalMpcError(data));
593
+ }
594
+ else if (type === 'portal:buildTransactionResult') {
595
+ // Remove the event listener
596
+ window.removeEventListener('message', handlebuildTransaction);
597
+ // Resolve the promise with the result
598
+ resolve(data);
599
+ }
600
+ };
601
+ // Bind the function to the message event
602
+ window.addEventListener('message', handlebuildTransaction);
603
+ // Send the request to the iframe
604
+ this.postMessage({
605
+ type: 'portal:buildTransaction',
606
+ data: { chainId, to, token, amount },
607
+ });
608
+ });
609
+ });
610
+ }
505
611
  getQuote(apiKey, args, chainId) {
506
612
  return __awaiter(this, void 0, void 0, function* () {
507
613
  return new Promise((resolve, reject) => {
@@ -684,6 +790,43 @@ class Mpc {
684
790
  });
685
791
  });
686
792
  }
793
+ evaluateTransaction(chainId, transaction, operationType = 'all') {
794
+ return __awaiter(this, void 0, void 0, function* () {
795
+ return new Promise((resolve, reject) => {
796
+ const handleEvaluateTransaction = (event) => {
797
+ const { type, data } = event.data;
798
+ const { origin } = event;
799
+ // ignore any broadcast postMessages
800
+ if (origin !== this.getOrigin()) {
801
+ return;
802
+ }
803
+ if (type === 'portal:evaluateTransactionError') {
804
+ // Remove the event listener
805
+ window.removeEventListener('message', handleEvaluateTransaction);
806
+ // Reject the promise with the error
807
+ return reject(new PortalMpcError(data));
808
+ }
809
+ else if (type === 'portal:evaluateTransactionResult') {
810
+ // Remove the event listener
811
+ window.removeEventListener('message', handleEvaluateTransaction);
812
+ // Resolve the promise with the result
813
+ resolve(data);
814
+ }
815
+ };
816
+ // Bind the function to the message event
817
+ window.addEventListener('message', handleEvaluateTransaction);
818
+ // Send the request to the iframe
819
+ this.postMessage({
820
+ type: 'portal:evaluateTransaction',
821
+ data: {
822
+ chainId,
823
+ transaction,
824
+ operationType,
825
+ },
826
+ });
827
+ });
828
+ });
829
+ }
687
830
  storedClientBackupShare(success, backupMethod) {
688
831
  return new Promise((resolve, reject) => {
689
832
  const handleStoredClientBackupShare = (event) => {
@@ -842,7 +985,7 @@ class Mpc {
842
985
  window.removeEventListener('message', handleReady);
843
986
  window.removeEventListener('message', handleError);
844
987
  // Update ready state
845
- this.portal.ready = true;
988
+ this.ready = true;
846
989
  // Update the address
847
990
  const address = yield this.getAddress();
848
991
  this.portal.address = address;