@portal-hq/web 0.0.2 → 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/{src/index.js → index.js} +31 -4
- package/lib/commonjs/{src/mpc → mpc}/index.js +197 -49
- package/lib/esm/{src/index.js → index.js} +31 -4
- package/lib/esm/{src/mpc → mpc}/index.js +197 -49
- package/package.json +7 -24
- package/src/index.ts +38 -5
- package/src/mpc/index.ts +214 -37
- package/tsconfig.json +5 -10
- package/types.d.ts +40 -20
- package/CHANGELOG.md +0 -19
- package/README.md +0 -38
- /package/lib/commonjs/{src/mpc → mpc}/errors/index.js +0 -0
- /package/lib/commonjs/{src/provider → provider}/errors/index.js +0 -0
- /package/lib/commonjs/{src/provider → provider}/errors/provider-rpc-error.js +0 -0
- /package/lib/commonjs/{src/provider → provider}/index.js +0 -0
- /package/lib/esm/{src/mpc → mpc}/errors/index.js +0 -0
- /package/lib/esm/{src/provider → provider}/errors/index.js +0 -0
- /package/lib/esm/{src/provider → provider}/errors/provider-rpc-error.js +0 -0
- /package/lib/esm/{src/provider → provider}/index.js +0 -0
|
@@ -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
|
***************************/
|
|
@@ -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
|
/*******************************
|