@portal-hq/web 0.0.3 → 0.0.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/lib/commonjs/index.js +31 -4
- package/lib/commonjs/mpc/index.js +197 -49
- package/lib/esm/index.js +31 -4
- package/lib/esm/mpc/index.js +197 -49
- package/package.json +1 -1
- package/src/index.ts +38 -5
- package/src/mpc/index.ts +214 -37
- package/types.d.ts +10 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -208,22 +208,49 @@ class Portal {
|
|
|
208
208
|
/*******************************
|
|
209
209
|
* API Methods
|
|
210
210
|
*******************************/
|
|
211
|
+
getBalances() {
|
|
212
|
+
var _a;
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getBalances());
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
getClient() {
|
|
218
|
+
var _a;
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
getNFTs() {
|
|
224
|
+
var _a;
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTs();
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
getTransactions(limit, offset, order, chainId) {
|
|
230
|
+
var _a;
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(limit, offset, order, chainId);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
211
235
|
simulateTransaction(transaction) {
|
|
212
236
|
var _a;
|
|
213
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
238
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction);
|
|
215
239
|
});
|
|
216
240
|
}
|
|
217
|
-
|
|
241
|
+
/*******************************
|
|
242
|
+
* Swaps Methods
|
|
243
|
+
*******************************/
|
|
244
|
+
getQuote(apiKey, args) {
|
|
218
245
|
var _a;
|
|
219
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
247
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
|
|
221
248
|
});
|
|
222
249
|
}
|
|
223
|
-
|
|
250
|
+
getSources(apiKey) {
|
|
224
251
|
var _a;
|
|
225
252
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
253
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
|
|
227
254
|
});
|
|
228
255
|
}
|
|
229
256
|
/*******************************
|
|
@@ -12,7 +12,7 @@ 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 = '0.0.
|
|
15
|
+
const WEB_SDK_VERSION = '0.0.4';
|
|
16
16
|
class Mpc {
|
|
17
17
|
constructor({ portal }) {
|
|
18
18
|
this.configureIframe = () => {
|
|
@@ -40,6 +40,9 @@ class Mpc {
|
|
|
40
40
|
// Create the iFrame for MPC operations
|
|
41
41
|
this.appendIframe();
|
|
42
42
|
}
|
|
43
|
+
/*******************************
|
|
44
|
+
* Wallet Methods
|
|
45
|
+
*******************************/
|
|
43
46
|
backup(data, progress = () => {
|
|
44
47
|
// Noop
|
|
45
48
|
}) {
|
|
@@ -341,71 +344,180 @@ class Mpc {
|
|
|
341
344
|
});
|
|
342
345
|
});
|
|
343
346
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
347
|
+
/*******************************
|
|
348
|
+
* API Methods
|
|
349
|
+
*******************************/
|
|
350
|
+
getBalances() {
|
|
351
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
352
|
+
return new Promise((resolve, reject) => {
|
|
353
|
+
const handleGetBalances = (event) => {
|
|
354
|
+
const { type, data } = event.data;
|
|
355
|
+
const { origin } = event;
|
|
356
|
+
// ignore any broadcast postMessages
|
|
357
|
+
if (origin !== this.getOrigin()) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (type === 'portal:getBalancesError') {
|
|
361
|
+
// Remove the event listener
|
|
362
|
+
window.removeEventListener('message', handleGetBalances);
|
|
363
|
+
// Reject the promise with the error
|
|
364
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
365
|
+
}
|
|
366
|
+
else if (type === 'portal:getBalancesResult') {
|
|
367
|
+
// Remove the event listener
|
|
368
|
+
window.removeEventListener('message', handleGetBalances);
|
|
369
|
+
// Resolve the promise with the result
|
|
370
|
+
resolve(data);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
// Bind the function to the message event
|
|
374
|
+
window.addEventListener('message', handleGetBalances);
|
|
375
|
+
// Send the request to the iframe
|
|
376
|
+
this.postMessage({
|
|
377
|
+
type: 'portal:getBalances',
|
|
378
|
+
data: {},
|
|
379
|
+
});
|
|
372
380
|
});
|
|
373
381
|
});
|
|
374
382
|
}
|
|
375
|
-
|
|
383
|
+
getClient() {
|
|
376
384
|
return __awaiter(this, void 0, void 0, function* () {
|
|
377
385
|
return new Promise((resolve, reject) => {
|
|
378
|
-
const
|
|
386
|
+
const handleGetClient = (event) => {
|
|
379
387
|
const { type, data } = event.data;
|
|
380
388
|
const { origin } = event;
|
|
381
389
|
// ignore any broadcast postMessages
|
|
382
390
|
if (origin !== this.getOrigin()) {
|
|
383
391
|
return;
|
|
384
392
|
}
|
|
385
|
-
if (type === 'portal:
|
|
393
|
+
if (type === 'portal:getClientError') {
|
|
386
394
|
// Remove the event listener
|
|
387
|
-
window.removeEventListener('message',
|
|
395
|
+
window.removeEventListener('message', handleGetClient);
|
|
388
396
|
// Reject the promise with the error
|
|
389
397
|
return reject(new errors_1.PortalMpcError(data));
|
|
390
398
|
}
|
|
391
|
-
else if (type === 'portal:
|
|
399
|
+
else if (type === 'portal:getClientResult') {
|
|
392
400
|
// Remove the event listener
|
|
393
|
-
window.removeEventListener('message',
|
|
401
|
+
window.removeEventListener('message', handleGetClient);
|
|
394
402
|
// Resolve the promise with the result
|
|
395
403
|
resolve(data);
|
|
396
404
|
}
|
|
397
405
|
};
|
|
398
406
|
// Bind the function to the message event
|
|
399
|
-
window.addEventListener('message',
|
|
407
|
+
window.addEventListener('message', handleGetClient);
|
|
400
408
|
// Send the request to the iframe
|
|
401
409
|
this.postMessage({
|
|
402
|
-
type: 'portal:
|
|
403
|
-
data:
|
|
410
|
+
type: 'portal:getClient',
|
|
411
|
+
data: {},
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
getNFTs() {
|
|
417
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
return new Promise((resolve, reject) => {
|
|
419
|
+
const handleGetNFTs = (event) => {
|
|
420
|
+
const { type, data } = event.data;
|
|
421
|
+
const { origin } = event;
|
|
422
|
+
// ignore any broadcast postMessages
|
|
423
|
+
if (origin !== this.getOrigin()) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (type === 'portal:getNFTsError') {
|
|
427
|
+
// Remove the event listener
|
|
428
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
429
|
+
// Reject the promise with the error
|
|
430
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
431
|
+
}
|
|
432
|
+
else if (type === 'portal:getNFTsResult') {
|
|
433
|
+
// Remove the event listener
|
|
434
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
435
|
+
// Resolve the promise with the result
|
|
436
|
+
resolve(data);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
// Bind the function to the message event
|
|
440
|
+
window.addEventListener('message', handleGetNFTs);
|
|
441
|
+
// Send the request to the iframe
|
|
442
|
+
this.postMessage({
|
|
443
|
+
type: 'portal:getNFTs',
|
|
444
|
+
data: {},
|
|
404
445
|
});
|
|
405
446
|
});
|
|
406
447
|
});
|
|
407
448
|
}
|
|
408
|
-
|
|
449
|
+
getQuote(apiKey, args) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
return new Promise((resolve, reject) => {
|
|
452
|
+
const handleGetQuote = (event) => {
|
|
453
|
+
const { type, data: result } = event.data;
|
|
454
|
+
const { origin } = event;
|
|
455
|
+
// ignore any broadcast postMessages
|
|
456
|
+
if (origin !== this.getOrigin()) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (type === 'portal:swaps:getQuoteError') {
|
|
460
|
+
// Remove the event listener
|
|
461
|
+
window.removeEventListener('message', handleGetQuote);
|
|
462
|
+
// Reject the promise with the error
|
|
463
|
+
return reject(new errors_1.PortalMpcError(result));
|
|
464
|
+
}
|
|
465
|
+
else if (type === 'portal:swaps:getQuoteResult') {
|
|
466
|
+
// Remove the event listener
|
|
467
|
+
window.removeEventListener('message', handleGetQuote);
|
|
468
|
+
// Resolve the promise with the result
|
|
469
|
+
resolve(result);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
// Bind the function to the message event
|
|
473
|
+
window.addEventListener('message', handleGetQuote);
|
|
474
|
+
// Send the request to the iframe
|
|
475
|
+
this.postMessage({
|
|
476
|
+
type: 'portal:swaps:getQuote',
|
|
477
|
+
data: {
|
|
478
|
+
apiKey,
|
|
479
|
+
args,
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
getSources(apiKey) {
|
|
486
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
+
return new Promise((resolve, reject) => {
|
|
488
|
+
const handleGetSources = (event) => {
|
|
489
|
+
const { type, data: result } = event.data;
|
|
490
|
+
const { origin } = event;
|
|
491
|
+
// ignore any broadcast postMessages
|
|
492
|
+
if (origin !== this.getOrigin()) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (type === 'portal:swaps:getSourcesError') {
|
|
496
|
+
// Remove the event listener
|
|
497
|
+
window.removeEventListener('message', handleGetSources);
|
|
498
|
+
// Reject the promise with the error
|
|
499
|
+
return reject(new errors_1.PortalMpcError(result));
|
|
500
|
+
}
|
|
501
|
+
else if (type === 'portal:swaps:getSourcesResult') {
|
|
502
|
+
// Remove the event listener
|
|
503
|
+
window.removeEventListener('message', handleGetSources);
|
|
504
|
+
// Resolve the promise with the result
|
|
505
|
+
resolve(result);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
// Bind the function to the message event
|
|
509
|
+
window.addEventListener('message', handleGetSources);
|
|
510
|
+
// Send the request to the iframe
|
|
511
|
+
this.postMessage({
|
|
512
|
+
type: 'portal:swaps:getSources',
|
|
513
|
+
data: {
|
|
514
|
+
apiKey,
|
|
515
|
+
},
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
getTransactions(limit, offset, order, chainId) {
|
|
409
521
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410
522
|
return new Promise((resolve, reject) => {
|
|
411
523
|
const handleGetTransactions = (event) => {
|
|
@@ -433,44 +545,80 @@ class Mpc {
|
|
|
433
545
|
// Send the request to the iframe
|
|
434
546
|
this.postMessage({
|
|
435
547
|
type: 'portal:getTransactions',
|
|
436
|
-
data: {
|
|
548
|
+
data: {
|
|
549
|
+
limit,
|
|
550
|
+
offset,
|
|
551
|
+
order,
|
|
552
|
+
chainId,
|
|
553
|
+
},
|
|
437
554
|
});
|
|
438
555
|
});
|
|
439
556
|
});
|
|
440
557
|
}
|
|
441
|
-
|
|
558
|
+
simulateTransaction(transaction) {
|
|
442
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
560
|
return new Promise((resolve, reject) => {
|
|
444
|
-
const
|
|
561
|
+
const handleSimulateTransaction = (event) => {
|
|
445
562
|
const { type, data } = event.data;
|
|
446
563
|
const { origin } = event;
|
|
447
564
|
// ignore any broadcast postMessages
|
|
448
565
|
if (origin !== this.getOrigin()) {
|
|
449
566
|
return;
|
|
450
567
|
}
|
|
451
|
-
if (type === 'portal:
|
|
568
|
+
if (type === 'portal:simulateTransactionError') {
|
|
452
569
|
// Remove the event listener
|
|
453
|
-
window.removeEventListener('message',
|
|
570
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
454
571
|
// Reject the promise with the error
|
|
455
572
|
return reject(new errors_1.PortalMpcError(data));
|
|
456
573
|
}
|
|
457
|
-
else if (type === 'portal:
|
|
574
|
+
else if (type === 'portal:simulateTransactionResult') {
|
|
458
575
|
// Remove the event listener
|
|
459
|
-
window.removeEventListener('message',
|
|
576
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
460
577
|
// Resolve the promise with the result
|
|
461
578
|
resolve(data);
|
|
462
579
|
}
|
|
463
580
|
};
|
|
464
581
|
// Bind the function to the message event
|
|
465
|
-
window.addEventListener('message',
|
|
582
|
+
window.addEventListener('message', handleSimulateTransaction);
|
|
466
583
|
// Send the request to the iframe
|
|
467
584
|
this.postMessage({
|
|
468
|
-
type: 'portal:
|
|
469
|
-
data:
|
|
585
|
+
type: 'portal:simulateTransaction',
|
|
586
|
+
data: transaction,
|
|
470
587
|
});
|
|
471
588
|
});
|
|
472
589
|
});
|
|
473
590
|
}
|
|
591
|
+
storedClientBackupShare(success) {
|
|
592
|
+
return new Promise((resolve, reject) => {
|
|
593
|
+
const handleStoredClientBackupShare = (event) => {
|
|
594
|
+
const { type, data } = event.data;
|
|
595
|
+
const { origin } = event;
|
|
596
|
+
// ignore any broadcast postMessages
|
|
597
|
+
if (origin !== this.getOrigin()) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (type === 'portal:storedClientBackupShareError') {
|
|
601
|
+
// Remove the event listener
|
|
602
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
603
|
+
// Reject the promise with the error
|
|
604
|
+
return reject(new errors_1.PortalMpcError(data));
|
|
605
|
+
}
|
|
606
|
+
else if (type === 'portal:storedClientBackupShareResult') {
|
|
607
|
+
// Remove the event listener
|
|
608
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
609
|
+
// Resolve the promise with the result
|
|
610
|
+
resolve();
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
// Bind the function to the message event
|
|
614
|
+
window.addEventListener('message', handleStoredClientBackupShare);
|
|
615
|
+
// Send the request to the iframe
|
|
616
|
+
this.postMessage({
|
|
617
|
+
type: 'portal:storedClientBackupShare',
|
|
618
|
+
data: success,
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
}
|
|
474
622
|
/***************************
|
|
475
623
|
* Private Methods
|
|
476
624
|
***************************/
|
package/lib/esm/index.js
CHANGED
|
@@ -202,22 +202,49 @@ class Portal {
|
|
|
202
202
|
/*******************************
|
|
203
203
|
* API Methods
|
|
204
204
|
*******************************/
|
|
205
|
+
getBalances() {
|
|
206
|
+
var _a;
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
return yield ((_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getBalances());
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
getClient() {
|
|
212
|
+
var _a;
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getClient();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
getNFTs() {
|
|
218
|
+
var _a;
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTs();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
getTransactions(limit, offset, order, chainId) {
|
|
224
|
+
var _a;
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getTransactions(limit, offset, order, chainId);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
205
229
|
simulateTransaction(transaction) {
|
|
206
230
|
var _a;
|
|
207
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
232
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.simulateTransaction(transaction);
|
|
209
233
|
});
|
|
210
234
|
}
|
|
211
|
-
|
|
235
|
+
/*******************************
|
|
236
|
+
* Swaps Methods
|
|
237
|
+
*******************************/
|
|
238
|
+
getQuote(apiKey, args) {
|
|
212
239
|
var _a;
|
|
213
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
241
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args);
|
|
215
242
|
});
|
|
216
243
|
}
|
|
217
|
-
|
|
244
|
+
getSources(apiKey) {
|
|
218
245
|
var _a;
|
|
219
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.
|
|
247
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey);
|
|
221
248
|
});
|
|
222
249
|
}
|
|
223
250
|
/*******************************
|
package/lib/esm/mpc/index.js
CHANGED
|
@@ -9,7 +9,7 @@ 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 = '0.0.
|
|
12
|
+
const WEB_SDK_VERSION = '0.0.4';
|
|
13
13
|
class Mpc {
|
|
14
14
|
constructor({ portal }) {
|
|
15
15
|
this.configureIframe = () => {
|
|
@@ -37,6 +37,9 @@ class Mpc {
|
|
|
37
37
|
// Create the iFrame for MPC operations
|
|
38
38
|
this.appendIframe();
|
|
39
39
|
}
|
|
40
|
+
/*******************************
|
|
41
|
+
* Wallet Methods
|
|
42
|
+
*******************************/
|
|
40
43
|
backup(data, progress = () => {
|
|
41
44
|
// Noop
|
|
42
45
|
}) {
|
|
@@ -338,71 +341,180 @@ class Mpc {
|
|
|
338
341
|
});
|
|
339
342
|
});
|
|
340
343
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
344
|
+
/*******************************
|
|
345
|
+
* API Methods
|
|
346
|
+
*******************************/
|
|
347
|
+
getBalances() {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
return new Promise((resolve, reject) => {
|
|
350
|
+
const handleGetBalances = (event) => {
|
|
351
|
+
const { type, data } = event.data;
|
|
352
|
+
const { origin } = event;
|
|
353
|
+
// ignore any broadcast postMessages
|
|
354
|
+
if (origin !== this.getOrigin()) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (type === 'portal:getBalancesError') {
|
|
358
|
+
// Remove the event listener
|
|
359
|
+
window.removeEventListener('message', handleGetBalances);
|
|
360
|
+
// Reject the promise with the error
|
|
361
|
+
return reject(new PortalMpcError(data));
|
|
362
|
+
}
|
|
363
|
+
else if (type === 'portal:getBalancesResult') {
|
|
364
|
+
// Remove the event listener
|
|
365
|
+
window.removeEventListener('message', handleGetBalances);
|
|
366
|
+
// Resolve the promise with the result
|
|
367
|
+
resolve(data);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
// Bind the function to the message event
|
|
371
|
+
window.addEventListener('message', handleGetBalances);
|
|
372
|
+
// Send the request to the iframe
|
|
373
|
+
this.postMessage({
|
|
374
|
+
type: 'portal:getBalances',
|
|
375
|
+
data: {},
|
|
376
|
+
});
|
|
369
377
|
});
|
|
370
378
|
});
|
|
371
379
|
}
|
|
372
|
-
|
|
380
|
+
getClient() {
|
|
373
381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
374
382
|
return new Promise((resolve, reject) => {
|
|
375
|
-
const
|
|
383
|
+
const handleGetClient = (event) => {
|
|
376
384
|
const { type, data } = event.data;
|
|
377
385
|
const { origin } = event;
|
|
378
386
|
// ignore any broadcast postMessages
|
|
379
387
|
if (origin !== this.getOrigin()) {
|
|
380
388
|
return;
|
|
381
389
|
}
|
|
382
|
-
if (type === 'portal:
|
|
390
|
+
if (type === 'portal:getClientError') {
|
|
383
391
|
// Remove the event listener
|
|
384
|
-
window.removeEventListener('message',
|
|
392
|
+
window.removeEventListener('message', handleGetClient);
|
|
385
393
|
// Reject the promise with the error
|
|
386
394
|
return reject(new PortalMpcError(data));
|
|
387
395
|
}
|
|
388
|
-
else if (type === 'portal:
|
|
396
|
+
else if (type === 'portal:getClientResult') {
|
|
389
397
|
// Remove the event listener
|
|
390
|
-
window.removeEventListener('message',
|
|
398
|
+
window.removeEventListener('message', handleGetClient);
|
|
391
399
|
// Resolve the promise with the result
|
|
392
400
|
resolve(data);
|
|
393
401
|
}
|
|
394
402
|
};
|
|
395
403
|
// Bind the function to the message event
|
|
396
|
-
window.addEventListener('message',
|
|
404
|
+
window.addEventListener('message', handleGetClient);
|
|
397
405
|
// Send the request to the iframe
|
|
398
406
|
this.postMessage({
|
|
399
|
-
type: 'portal:
|
|
400
|
-
data:
|
|
407
|
+
type: 'portal:getClient',
|
|
408
|
+
data: {},
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
getNFTs() {
|
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
+
return new Promise((resolve, reject) => {
|
|
416
|
+
const handleGetNFTs = (event) => {
|
|
417
|
+
const { type, data } = event.data;
|
|
418
|
+
const { origin } = event;
|
|
419
|
+
// ignore any broadcast postMessages
|
|
420
|
+
if (origin !== this.getOrigin()) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (type === 'portal:getNFTsError') {
|
|
424
|
+
// Remove the event listener
|
|
425
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
426
|
+
// Reject the promise with the error
|
|
427
|
+
return reject(new PortalMpcError(data));
|
|
428
|
+
}
|
|
429
|
+
else if (type === 'portal:getNFTsResult') {
|
|
430
|
+
// Remove the event listener
|
|
431
|
+
window.removeEventListener('message', handleGetNFTs);
|
|
432
|
+
// Resolve the promise with the result
|
|
433
|
+
resolve(data);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
// Bind the function to the message event
|
|
437
|
+
window.addEventListener('message', handleGetNFTs);
|
|
438
|
+
// Send the request to the iframe
|
|
439
|
+
this.postMessage({
|
|
440
|
+
type: 'portal:getNFTs',
|
|
441
|
+
data: {},
|
|
401
442
|
});
|
|
402
443
|
});
|
|
403
444
|
});
|
|
404
445
|
}
|
|
405
|
-
|
|
446
|
+
getQuote(apiKey, args) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
return new Promise((resolve, reject) => {
|
|
449
|
+
const handleGetQuote = (event) => {
|
|
450
|
+
const { type, data: result } = event.data;
|
|
451
|
+
const { origin } = event;
|
|
452
|
+
// ignore any broadcast postMessages
|
|
453
|
+
if (origin !== this.getOrigin()) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (type === 'portal:swaps:getQuoteError') {
|
|
457
|
+
// Remove the event listener
|
|
458
|
+
window.removeEventListener('message', handleGetQuote);
|
|
459
|
+
// Reject the promise with the error
|
|
460
|
+
return reject(new PortalMpcError(result));
|
|
461
|
+
}
|
|
462
|
+
else if (type === 'portal:swaps:getQuoteResult') {
|
|
463
|
+
// Remove the event listener
|
|
464
|
+
window.removeEventListener('message', handleGetQuote);
|
|
465
|
+
// Resolve the promise with the result
|
|
466
|
+
resolve(result);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
// Bind the function to the message event
|
|
470
|
+
window.addEventListener('message', handleGetQuote);
|
|
471
|
+
// Send the request to the iframe
|
|
472
|
+
this.postMessage({
|
|
473
|
+
type: 'portal:swaps:getQuote',
|
|
474
|
+
data: {
|
|
475
|
+
apiKey,
|
|
476
|
+
args,
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
getSources(apiKey) {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
return new Promise((resolve, reject) => {
|
|
485
|
+
const handleGetSources = (event) => {
|
|
486
|
+
const { type, data: result } = event.data;
|
|
487
|
+
const { origin } = event;
|
|
488
|
+
// ignore any broadcast postMessages
|
|
489
|
+
if (origin !== this.getOrigin()) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (type === 'portal:swaps:getSourcesError') {
|
|
493
|
+
// Remove the event listener
|
|
494
|
+
window.removeEventListener('message', handleGetSources);
|
|
495
|
+
// Reject the promise with the error
|
|
496
|
+
return reject(new PortalMpcError(result));
|
|
497
|
+
}
|
|
498
|
+
else if (type === 'portal:swaps:getSourcesResult') {
|
|
499
|
+
// Remove the event listener
|
|
500
|
+
window.removeEventListener('message', handleGetSources);
|
|
501
|
+
// Resolve the promise with the result
|
|
502
|
+
resolve(result);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
// Bind the function to the message event
|
|
506
|
+
window.addEventListener('message', handleGetSources);
|
|
507
|
+
// Send the request to the iframe
|
|
508
|
+
this.postMessage({
|
|
509
|
+
type: 'portal:swaps:getSources',
|
|
510
|
+
data: {
|
|
511
|
+
apiKey,
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
getTransactions(limit, offset, order, chainId) {
|
|
406
518
|
return __awaiter(this, void 0, void 0, function* () {
|
|
407
519
|
return new Promise((resolve, reject) => {
|
|
408
520
|
const handleGetTransactions = (event) => {
|
|
@@ -430,44 +542,80 @@ class Mpc {
|
|
|
430
542
|
// Send the request to the iframe
|
|
431
543
|
this.postMessage({
|
|
432
544
|
type: 'portal:getTransactions',
|
|
433
|
-
data: {
|
|
545
|
+
data: {
|
|
546
|
+
limit,
|
|
547
|
+
offset,
|
|
548
|
+
order,
|
|
549
|
+
chainId,
|
|
550
|
+
},
|
|
434
551
|
});
|
|
435
552
|
});
|
|
436
553
|
});
|
|
437
554
|
}
|
|
438
|
-
|
|
555
|
+
simulateTransaction(transaction) {
|
|
439
556
|
return __awaiter(this, void 0, void 0, function* () {
|
|
440
557
|
return new Promise((resolve, reject) => {
|
|
441
|
-
const
|
|
558
|
+
const handleSimulateTransaction = (event) => {
|
|
442
559
|
const { type, data } = event.data;
|
|
443
560
|
const { origin } = event;
|
|
444
561
|
// ignore any broadcast postMessages
|
|
445
562
|
if (origin !== this.getOrigin()) {
|
|
446
563
|
return;
|
|
447
564
|
}
|
|
448
|
-
if (type === 'portal:
|
|
565
|
+
if (type === 'portal:simulateTransactionError') {
|
|
449
566
|
// Remove the event listener
|
|
450
|
-
window.removeEventListener('message',
|
|
567
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
451
568
|
// Reject the promise with the error
|
|
452
569
|
return reject(new PortalMpcError(data));
|
|
453
570
|
}
|
|
454
|
-
else if (type === 'portal:
|
|
571
|
+
else if (type === 'portal:simulateTransactionResult') {
|
|
455
572
|
// Remove the event listener
|
|
456
|
-
window.removeEventListener('message',
|
|
573
|
+
window.removeEventListener('message', handleSimulateTransaction);
|
|
457
574
|
// Resolve the promise with the result
|
|
458
575
|
resolve(data);
|
|
459
576
|
}
|
|
460
577
|
};
|
|
461
578
|
// Bind the function to the message event
|
|
462
|
-
window.addEventListener('message',
|
|
579
|
+
window.addEventListener('message', handleSimulateTransaction);
|
|
463
580
|
// Send the request to the iframe
|
|
464
581
|
this.postMessage({
|
|
465
|
-
type: 'portal:
|
|
466
|
-
data:
|
|
582
|
+
type: 'portal:simulateTransaction',
|
|
583
|
+
data: transaction,
|
|
467
584
|
});
|
|
468
585
|
});
|
|
469
586
|
});
|
|
470
587
|
}
|
|
588
|
+
storedClientBackupShare(success) {
|
|
589
|
+
return new Promise((resolve, reject) => {
|
|
590
|
+
const handleStoredClientBackupShare = (event) => {
|
|
591
|
+
const { type, data } = event.data;
|
|
592
|
+
const { origin } = event;
|
|
593
|
+
// ignore any broadcast postMessages
|
|
594
|
+
if (origin !== this.getOrigin()) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (type === 'portal:storedClientBackupShareError') {
|
|
598
|
+
// Remove the event listener
|
|
599
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
600
|
+
// Reject the promise with the error
|
|
601
|
+
return reject(new PortalMpcError(data));
|
|
602
|
+
}
|
|
603
|
+
else if (type === 'portal:storedClientBackupShareResult') {
|
|
604
|
+
// Remove the event listener
|
|
605
|
+
window.removeEventListener('message', handleStoredClientBackupShare);
|
|
606
|
+
// Resolve the promise with the result
|
|
607
|
+
resolve();
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
// Bind the function to the message event
|
|
611
|
+
window.addEventListener('message', handleStoredClientBackupShare);
|
|
612
|
+
// Send the request to the iframe
|
|
613
|
+
this.postMessage({
|
|
614
|
+
type: 'portal:storedClientBackupShare',
|
|
615
|
+
data: success,
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
}
|
|
471
619
|
/***************************
|
|
472
620
|
* Private Methods
|
|
473
621
|
***************************/
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
ClientWithCustodianData,
|
|
3
2
|
BackupConfigs,
|
|
3
|
+
Balance,
|
|
4
|
+
ClientWithCustodianData,
|
|
4
5
|
EthereumTransaction,
|
|
5
6
|
FeatureFlags,
|
|
6
7
|
GDriveConfig,
|
|
7
8
|
GatewayLike,
|
|
9
|
+
GetTransactionsOrder,
|
|
10
|
+
NFT,
|
|
8
11
|
PortalOptions,
|
|
9
12
|
ProgressCallback,
|
|
13
|
+
QuoteArgs,
|
|
14
|
+
QuoteResponse,
|
|
10
15
|
SimulateTransactionParam,
|
|
11
16
|
SimulatedTransaction,
|
|
12
17
|
Transaction,
|
|
@@ -272,18 +277,46 @@ class Portal {
|
|
|
272
277
|
* API Methods
|
|
273
278
|
*******************************/
|
|
274
279
|
|
|
280
|
+
public async getBalances(): Promise<Balance[]> {
|
|
281
|
+
return await this.mpc?.getBalances()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public async getClient(): Promise<ClientWithCustodianData> {
|
|
285
|
+
return this.mpc?.getClient()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public async getNFTs(): Promise<NFT[]> {
|
|
289
|
+
return this.mpc?.getNFTs()
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public async getTransactions(
|
|
293
|
+
limit?: number,
|
|
294
|
+
offset?: number,
|
|
295
|
+
order?: GetTransactionsOrder,
|
|
296
|
+
chainId?: number,
|
|
297
|
+
): Promise<Transaction[]> {
|
|
298
|
+
return this.mpc?.getTransactions(limit, offset, order, chainId)
|
|
299
|
+
}
|
|
300
|
+
|
|
275
301
|
public async simulateTransaction(
|
|
276
302
|
transaction: SimulateTransactionParam,
|
|
277
303
|
): Promise<SimulatedTransaction> {
|
|
278
304
|
return this.mpc?.simulateTransaction(transaction)
|
|
279
305
|
}
|
|
280
306
|
|
|
281
|
-
|
|
282
|
-
|
|
307
|
+
/*******************************
|
|
308
|
+
* Swaps Methods
|
|
309
|
+
*******************************/
|
|
310
|
+
|
|
311
|
+
public async getQuote(
|
|
312
|
+
apiKey: string,
|
|
313
|
+
args: QuoteArgs,
|
|
314
|
+
): Promise<QuoteResponse> {
|
|
315
|
+
return this.mpc?.getQuote(apiKey, args)
|
|
283
316
|
}
|
|
284
317
|
|
|
285
|
-
public async
|
|
286
|
-
return this.mpc?.
|
|
318
|
+
public async getSources(apiKey: string): Promise<Record<string, string>> {
|
|
319
|
+
return this.mpc?.getSources(apiKey)
|
|
287
320
|
}
|
|
288
321
|
|
|
289
322
|
/*******************************
|
package/src/mpc/index.ts
CHANGED
|
@@ -3,14 +3,19 @@ import { PortalMpcError } from './errors'
|
|
|
3
3
|
import Portal, { BackupMethods } from '../index'
|
|
4
4
|
import type {
|
|
5
5
|
BackupArgs,
|
|
6
|
+
Balance,
|
|
6
7
|
ClientWithCustodianData,
|
|
7
8
|
GenerateArgs,
|
|
9
|
+
GetTransactionsOrder,
|
|
8
10
|
IframeConfigurationOptions,
|
|
9
11
|
LegacyRecoverArgs,
|
|
10
12
|
MpcOptions,
|
|
11
13
|
MpcStatus,
|
|
14
|
+
NFT,
|
|
12
15
|
PortalError,
|
|
13
16
|
ProgressCallback,
|
|
17
|
+
QuoteArgs,
|
|
18
|
+
QuoteResponse,
|
|
14
19
|
RecoverArgs,
|
|
15
20
|
SignArgs,
|
|
16
21
|
SimulateTransactionParam,
|
|
@@ -19,7 +24,7 @@ import type {
|
|
|
19
24
|
WorkerResult,
|
|
20
25
|
} from '../../types'
|
|
21
26
|
|
|
22
|
-
const WEB_SDK_VERSION = '0.0.
|
|
27
|
+
const WEB_SDK_VERSION = '0.0.4'
|
|
23
28
|
|
|
24
29
|
class Mpc {
|
|
25
30
|
public iframe?: HTMLIFrameElement
|
|
@@ -36,6 +41,10 @@ class Mpc {
|
|
|
36
41
|
this.appendIframe()
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
/*******************************
|
|
45
|
+
* Wallet Methods
|
|
46
|
+
*******************************/
|
|
47
|
+
|
|
39
48
|
public async backup(
|
|
40
49
|
data: BackupArgs,
|
|
41
50
|
progress: ProgressCallback = () => {
|
|
@@ -402,11 +411,13 @@ class Mpc {
|
|
|
402
411
|
})
|
|
403
412
|
}
|
|
404
413
|
|
|
405
|
-
|
|
414
|
+
/*******************************
|
|
415
|
+
* API Methods
|
|
416
|
+
*******************************/
|
|
417
|
+
|
|
418
|
+
public async getBalances(): Promise<Balance[]> {
|
|
406
419
|
return new Promise((resolve, reject) => {
|
|
407
|
-
const
|
|
408
|
-
event: MessageEvent<WorkerResult>,
|
|
409
|
-
) => {
|
|
420
|
+
const handleGetBalances = (event: MessageEvent<WorkerResult>) => {
|
|
410
421
|
const { type, data } = event.data
|
|
411
422
|
const { origin } = event
|
|
412
423
|
|
|
@@ -415,37 +426,35 @@ class Mpc {
|
|
|
415
426
|
return
|
|
416
427
|
}
|
|
417
428
|
|
|
418
|
-
if (type === 'portal:
|
|
429
|
+
if (type === 'portal:getBalancesError') {
|
|
419
430
|
// Remove the event listener
|
|
420
|
-
window.removeEventListener('message',
|
|
431
|
+
window.removeEventListener('message', handleGetBalances)
|
|
421
432
|
|
|
422
433
|
// Reject the promise with the error
|
|
423
434
|
return reject(new PortalMpcError(data as PortalError))
|
|
424
|
-
} else if (type === 'portal:
|
|
435
|
+
} else if (type === 'portal:getBalancesResult') {
|
|
425
436
|
// Remove the event listener
|
|
426
|
-
window.removeEventListener('message',
|
|
437
|
+
window.removeEventListener('message', handleGetBalances)
|
|
427
438
|
|
|
428
439
|
// Resolve the promise with the result
|
|
429
|
-
resolve()
|
|
440
|
+
resolve(data as Balance[])
|
|
430
441
|
}
|
|
431
442
|
}
|
|
432
443
|
|
|
433
444
|
// Bind the function to the message event
|
|
434
|
-
window.addEventListener('message',
|
|
445
|
+
window.addEventListener('message', handleGetBalances)
|
|
435
446
|
|
|
436
447
|
// Send the request to the iframe
|
|
437
448
|
this.postMessage({
|
|
438
|
-
type: 'portal:
|
|
439
|
-
data:
|
|
449
|
+
type: 'portal:getBalances',
|
|
450
|
+
data: {},
|
|
440
451
|
})
|
|
441
452
|
})
|
|
442
453
|
}
|
|
443
454
|
|
|
444
|
-
public async
|
|
445
|
-
transaction: SimulateTransactionParam,
|
|
446
|
-
): Promise<SimulatedTransaction> {
|
|
455
|
+
public async getClient(): Promise<ClientWithCustodianData> {
|
|
447
456
|
return new Promise((resolve, reject) => {
|
|
448
|
-
const
|
|
457
|
+
const handleGetClient = (event: MessageEvent<WorkerResult>) => {
|
|
449
458
|
const { type, data } = event.data
|
|
450
459
|
const { origin } = event
|
|
451
460
|
|
|
@@ -454,33 +463,155 @@ class Mpc {
|
|
|
454
463
|
return
|
|
455
464
|
}
|
|
456
465
|
|
|
457
|
-
if (type === 'portal:
|
|
466
|
+
if (type === 'portal:getClientError') {
|
|
458
467
|
// Remove the event listener
|
|
459
|
-
window.removeEventListener('message',
|
|
468
|
+
window.removeEventListener('message', handleGetClient)
|
|
460
469
|
|
|
461
470
|
// Reject the promise with the error
|
|
462
471
|
return reject(new PortalMpcError(data as PortalError))
|
|
463
|
-
} else if (type === 'portal:
|
|
472
|
+
} else if (type === 'portal:getClientResult') {
|
|
464
473
|
// Remove the event listener
|
|
465
|
-
window.removeEventListener('message',
|
|
474
|
+
window.removeEventListener('message', handleGetClient)
|
|
466
475
|
|
|
467
476
|
// Resolve the promise with the result
|
|
468
|
-
resolve(data as
|
|
477
|
+
resolve(data as ClientWithCustodianData)
|
|
469
478
|
}
|
|
470
479
|
}
|
|
471
480
|
|
|
472
481
|
// Bind the function to the message event
|
|
473
|
-
window.addEventListener('message',
|
|
482
|
+
window.addEventListener('message', handleGetClient)
|
|
474
483
|
|
|
475
484
|
// Send the request to the iframe
|
|
476
485
|
this.postMessage({
|
|
477
|
-
type: 'portal:
|
|
478
|
-
data:
|
|
486
|
+
type: 'portal:getClient',
|
|
487
|
+
data: {},
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
public async getNFTs(): Promise<NFT[]> {
|
|
493
|
+
return new Promise((resolve, reject) => {
|
|
494
|
+
const handleGetNFTs = (event: MessageEvent<WorkerResult>) => {
|
|
495
|
+
const { type, data } = event.data
|
|
496
|
+
const { origin } = event
|
|
497
|
+
|
|
498
|
+
// ignore any broadcast postMessages
|
|
499
|
+
if (origin !== this.getOrigin()) {
|
|
500
|
+
return
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (type === 'portal:getNFTsError') {
|
|
504
|
+
// Remove the event listener
|
|
505
|
+
window.removeEventListener('message', handleGetNFTs)
|
|
506
|
+
|
|
507
|
+
// Reject the promise with the error
|
|
508
|
+
return reject(new PortalMpcError(data as PortalError))
|
|
509
|
+
} else if (type === 'portal:getNFTsResult') {
|
|
510
|
+
// Remove the event listener
|
|
511
|
+
window.removeEventListener('message', handleGetNFTs)
|
|
512
|
+
|
|
513
|
+
// Resolve the promise with the result
|
|
514
|
+
resolve(data as NFT[])
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Bind the function to the message event
|
|
519
|
+
window.addEventListener('message', handleGetNFTs)
|
|
520
|
+
|
|
521
|
+
// Send the request to the iframe
|
|
522
|
+
this.postMessage({
|
|
523
|
+
type: 'portal:getNFTs',
|
|
524
|
+
data: {},
|
|
479
525
|
})
|
|
480
526
|
})
|
|
481
527
|
}
|
|
482
528
|
|
|
483
|
-
public async
|
|
529
|
+
public async getQuote(
|
|
530
|
+
apiKey: string,
|
|
531
|
+
args: QuoteArgs,
|
|
532
|
+
): Promise<QuoteResponse> {
|
|
533
|
+
return new Promise((resolve, reject) => {
|
|
534
|
+
const handleGetQuote = (event: MessageEvent<WorkerResult>) => {
|
|
535
|
+
const { type, data: result } = event.data
|
|
536
|
+
const { origin } = event
|
|
537
|
+
|
|
538
|
+
// ignore any broadcast postMessages
|
|
539
|
+
if (origin !== this.getOrigin()) {
|
|
540
|
+
return
|
|
541
|
+
}
|
|
542
|
+
if (type === 'portal:swaps:getQuoteError') {
|
|
543
|
+
// Remove the event listener
|
|
544
|
+
window.removeEventListener('message', handleGetQuote)
|
|
545
|
+
|
|
546
|
+
// Reject the promise with the error
|
|
547
|
+
return reject(new PortalMpcError(result as PortalError))
|
|
548
|
+
} else if (type === 'portal:swaps:getQuoteResult') {
|
|
549
|
+
// Remove the event listener
|
|
550
|
+
window.removeEventListener('message', handleGetQuote)
|
|
551
|
+
|
|
552
|
+
// Resolve the promise with the result
|
|
553
|
+
resolve(result as QuoteResponse)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Bind the function to the message event
|
|
558
|
+
window.addEventListener('message', handleGetQuote)
|
|
559
|
+
|
|
560
|
+
// Send the request to the iframe
|
|
561
|
+
this.postMessage({
|
|
562
|
+
type: 'portal:swaps:getQuote',
|
|
563
|
+
data: {
|
|
564
|
+
apiKey,
|
|
565
|
+
args,
|
|
566
|
+
},
|
|
567
|
+
})
|
|
568
|
+
})
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
public async getSources(apiKey: string): Promise<Record<string, string>> {
|
|
572
|
+
return new Promise((resolve, reject) => {
|
|
573
|
+
const handleGetSources = (event: MessageEvent<WorkerResult>) => {
|
|
574
|
+
const { type, data: result } = event.data
|
|
575
|
+
const { origin } = event
|
|
576
|
+
|
|
577
|
+
// ignore any broadcast postMessages
|
|
578
|
+
if (origin !== this.getOrigin()) {
|
|
579
|
+
return
|
|
580
|
+
}
|
|
581
|
+
if (type === 'portal:swaps:getSourcesError') {
|
|
582
|
+
// Remove the event listener
|
|
583
|
+
window.removeEventListener('message', handleGetSources)
|
|
584
|
+
|
|
585
|
+
// Reject the promise with the error
|
|
586
|
+
return reject(new PortalMpcError(result as PortalError))
|
|
587
|
+
} else if (type === 'portal:swaps:getSourcesResult') {
|
|
588
|
+
// Remove the event listener
|
|
589
|
+
window.removeEventListener('message', handleGetSources)
|
|
590
|
+
|
|
591
|
+
// Resolve the promise with the result
|
|
592
|
+
resolve(result as Record<string, string>)
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Bind the function to the message event
|
|
597
|
+
window.addEventListener('message', handleGetSources)
|
|
598
|
+
|
|
599
|
+
// Send the request to the iframe
|
|
600
|
+
this.postMessage({
|
|
601
|
+
type: 'portal:swaps:getSources',
|
|
602
|
+
data: {
|
|
603
|
+
apiKey,
|
|
604
|
+
},
|
|
605
|
+
})
|
|
606
|
+
})
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
public async getTransactions(
|
|
610
|
+
limit?: number,
|
|
611
|
+
offset?: number,
|
|
612
|
+
order?: GetTransactionsOrder,
|
|
613
|
+
chainId?: number,
|
|
614
|
+
): Promise<Transaction[]> {
|
|
484
615
|
return new Promise((resolve, reject) => {
|
|
485
616
|
const handleGetTransactions = (event: MessageEvent<WorkerResult>) => {
|
|
486
617
|
const { type, data } = event.data
|
|
@@ -512,14 +643,21 @@ class Mpc {
|
|
|
512
643
|
// Send the request to the iframe
|
|
513
644
|
this.postMessage({
|
|
514
645
|
type: 'portal:getTransactions',
|
|
515
|
-
data: {
|
|
646
|
+
data: {
|
|
647
|
+
limit,
|
|
648
|
+
offset,
|
|
649
|
+
order,
|
|
650
|
+
chainId,
|
|
651
|
+
},
|
|
516
652
|
})
|
|
517
653
|
})
|
|
518
654
|
}
|
|
519
655
|
|
|
520
|
-
public async
|
|
656
|
+
public async simulateTransaction(
|
|
657
|
+
transaction: SimulateTransactionParam,
|
|
658
|
+
): Promise<SimulatedTransaction> {
|
|
521
659
|
return new Promise((resolve, reject) => {
|
|
522
|
-
const
|
|
660
|
+
const handleSimulateTransaction = (event: MessageEvent<WorkerResult>) => {
|
|
523
661
|
const { type, data } = event.data
|
|
524
662
|
const { origin } = event
|
|
525
663
|
|
|
@@ -528,28 +666,67 @@ class Mpc {
|
|
|
528
666
|
return
|
|
529
667
|
}
|
|
530
668
|
|
|
531
|
-
if (type === 'portal:
|
|
669
|
+
if (type === 'portal:simulateTransactionError') {
|
|
532
670
|
// Remove the event listener
|
|
533
|
-
window.removeEventListener('message',
|
|
671
|
+
window.removeEventListener('message', handleSimulateTransaction)
|
|
534
672
|
|
|
535
673
|
// Reject the promise with the error
|
|
536
674
|
return reject(new PortalMpcError(data as PortalError))
|
|
537
|
-
} else if (type === 'portal:
|
|
675
|
+
} else if (type === 'portal:simulateTransactionResult') {
|
|
538
676
|
// Remove the event listener
|
|
539
|
-
window.removeEventListener('message',
|
|
677
|
+
window.removeEventListener('message', handleSimulateTransaction)
|
|
540
678
|
|
|
541
679
|
// Resolve the promise with the result
|
|
542
|
-
resolve(data as
|
|
680
|
+
resolve(data as SimulatedTransaction)
|
|
543
681
|
}
|
|
544
682
|
}
|
|
545
683
|
|
|
546
684
|
// Bind the function to the message event
|
|
547
|
-
window.addEventListener('message',
|
|
685
|
+
window.addEventListener('message', handleSimulateTransaction)
|
|
548
686
|
|
|
549
687
|
// Send the request to the iframe
|
|
550
688
|
this.postMessage({
|
|
551
|
-
type: 'portal:
|
|
552
|
-
data:
|
|
689
|
+
type: 'portal:simulateTransaction',
|
|
690
|
+
data: transaction,
|
|
691
|
+
})
|
|
692
|
+
})
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
public storedClientBackupShare(success: boolean): Promise<void> {
|
|
696
|
+
return new Promise((resolve, reject) => {
|
|
697
|
+
const handleStoredClientBackupShare = (
|
|
698
|
+
event: MessageEvent<WorkerResult>,
|
|
699
|
+
) => {
|
|
700
|
+
const { type, data } = event.data
|
|
701
|
+
const { origin } = event
|
|
702
|
+
|
|
703
|
+
// ignore any broadcast postMessages
|
|
704
|
+
if (origin !== this.getOrigin()) {
|
|
705
|
+
return
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (type === 'portal:storedClientBackupShareError') {
|
|
709
|
+
// Remove the event listener
|
|
710
|
+
window.removeEventListener('message', handleStoredClientBackupShare)
|
|
711
|
+
|
|
712
|
+
// Reject the promise with the error
|
|
713
|
+
return reject(new PortalMpcError(data as PortalError))
|
|
714
|
+
} else if (type === 'portal:storedClientBackupShareResult') {
|
|
715
|
+
// Remove the event listener
|
|
716
|
+
window.removeEventListener('message', handleStoredClientBackupShare)
|
|
717
|
+
|
|
718
|
+
// Resolve the promise with the result
|
|
719
|
+
resolve()
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Bind the function to the message event
|
|
724
|
+
window.addEventListener('message', handleStoredClientBackupShare)
|
|
725
|
+
|
|
726
|
+
// Send the request to the iframe
|
|
727
|
+
this.postMessage({
|
|
728
|
+
type: 'portal:storedClientBackupShare',
|
|
729
|
+
data: success,
|
|
553
730
|
})
|
|
554
731
|
})
|
|
555
732
|
}
|
package/types.d.ts
CHANGED
|
@@ -328,6 +328,7 @@ export interface QuoteArgs {
|
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
export interface QuoteResponse {
|
|
331
|
+
allowanceTarget: string
|
|
331
332
|
cost: string
|
|
332
333
|
transaction: Eip1559 | LegacyTx
|
|
333
334
|
}
|
|
@@ -427,14 +428,23 @@ export interface SimulatedTransaction {
|
|
|
427
428
|
requestError?: SimulatedTransactionError
|
|
428
429
|
}
|
|
429
430
|
|
|
431
|
+
export enum GetTransactionsOrder {
|
|
432
|
+
ASC = 'asc',
|
|
433
|
+
DESC = 'desc',
|
|
434
|
+
}
|
|
435
|
+
|
|
430
436
|
export interface Transaction {
|
|
431
437
|
asset: string
|
|
432
438
|
blockNum: string
|
|
433
439
|
category: string
|
|
440
|
+
chainId: number
|
|
434
441
|
erc1155Metadata: null | string
|
|
435
442
|
erc721TokenId: null | string
|
|
436
443
|
from: string
|
|
437
444
|
hash: string
|
|
445
|
+
metadata: {
|
|
446
|
+
blockTimestamp: string
|
|
447
|
+
}
|
|
438
448
|
rawContract: {
|
|
439
449
|
address: string
|
|
440
450
|
decimal: string
|