@portal-hq/web 3.5.2 → 3.6.0-alpha
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 +11 -1
- package/lib/commonjs/integrations/trading/index.js +18 -0
- package/lib/commonjs/integrations/trading/lifi/index.js +65 -0
- package/lib/commonjs/integrations/trading/lifi/index.test.js +93 -0
- package/lib/commonjs/integrations/trading/zero-x/index.js +44 -0
- package/lib/commonjs/integrations/trading/zero-x/index.test.js +65 -0
- package/lib/commonjs/mpc/index.js +41 -1
- package/lib/commonjs/mpc/index.test.js +260 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/integrations/trading/index.js +12 -0
- package/lib/esm/integrations/trading/lifi/index.js +62 -0
- package/lib/esm/integrations/trading/lifi/index.test.js +88 -0
- package/lib/esm/integrations/trading/zero-x/index.js +41 -0
- package/lib/esm/integrations/trading/zero-x/index.test.js +60 -0
- package/lib/esm/mpc/index.js +41 -1
- package/lib/esm/mpc/index.test.js +261 -1
- package/package.json +3 -2
- package/src/__mocks/constants.ts +216 -0
- package/src/index.ts +13 -0
- package/src/integrations/trading/index.ts +17 -0
- package/src/integrations/trading/lifi/index.test.ts +122 -0
- package/src/integrations/trading/lifi/index.ts +61 -0
- package/src/integrations/trading/zero-x/index.test.ts +75 -0
- package/src/integrations/trading/zero-x/index.ts +40 -0
- package/src/mpc/index.test.ts +312 -0
- package/src/mpc/index.ts +56 -2
- package/tsconfig.json +1 -1
- package/types.d.ts +1 -1
package/lib/esm/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { Connection, PublicKey, Transaction as SolanaTransaction, SystemProgram,
|
|
|
11
11
|
import Mpc from './mpc';
|
|
12
12
|
import Provider, { RequestMethod } from './provider';
|
|
13
13
|
import Yield from './integrations/yield';
|
|
14
|
+
import Trading from './integrations/trading';
|
|
14
15
|
class Portal {
|
|
15
16
|
get ready() {
|
|
16
17
|
return this.mpc.ready;
|
|
@@ -54,6 +55,7 @@ class Portal {
|
|
|
54
55
|
portal: this,
|
|
55
56
|
});
|
|
56
57
|
this.yield = new Yield({ mpc: this.mpc });
|
|
58
|
+
this.trading = new Trading({ mpc: this.mpc });
|
|
57
59
|
this.provider = new Provider({
|
|
58
60
|
portal: this,
|
|
59
61
|
chainId: chainId ? Number(chainId) : undefined,
|
|
@@ -674,12 +676,18 @@ class Portal {
|
|
|
674
676
|
/*******************************
|
|
675
677
|
* Swaps Methods
|
|
676
678
|
*******************************/
|
|
679
|
+
/**
|
|
680
|
+
* @deprecated This method is deprecated. Use `portal.trading.zeroX.getQuote` instead.
|
|
681
|
+
*/
|
|
677
682
|
getQuote(apiKey, args, chainId) {
|
|
678
683
|
var _a;
|
|
679
684
|
return __awaiter(this, void 0, void 0, function* () {
|
|
680
685
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args, chainId);
|
|
681
686
|
});
|
|
682
687
|
}
|
|
688
|
+
/**
|
|
689
|
+
* @deprecated This method is deprecated. Use `portal.trading.zeroX.getSources` instead.
|
|
690
|
+
*/
|
|
683
691
|
getSources(apiKey, chainId) {
|
|
684
692
|
var _a;
|
|
685
693
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -773,6 +781,7 @@ class Portal {
|
|
|
773
781
|
}
|
|
774
782
|
}
|
|
775
783
|
export { MpcError, MpcErrorCodes } from './mpc';
|
|
784
|
+
export { PortalMpcError } from './mpc/errors';
|
|
776
785
|
export { RequestMethod } from './provider';
|
|
777
786
|
export var MpcStatuses;
|
|
778
787
|
(function (MpcStatuses) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ZeroX from './zero-x';
|
|
2
|
+
import LiFi from './lifi';
|
|
3
|
+
/**
|
|
4
|
+
* This class is a container for the LiFi class.
|
|
5
|
+
* In the future, Trading domain logic should be here.
|
|
6
|
+
*/
|
|
7
|
+
export default class Trading {
|
|
8
|
+
constructor({ mpc }) {
|
|
9
|
+
this.lifi = new LiFi({ mpc });
|
|
10
|
+
this.zeroX = new ZeroX({ mpc });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default class LiFi {
|
|
11
|
+
constructor({ mpc }) {
|
|
12
|
+
this.mpc = mpc;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves routes from the Li.Fi integration.
|
|
16
|
+
* @param data - The parameters for the routes request.
|
|
17
|
+
* @returns A `LifiRoutesResponse` promise.
|
|
18
|
+
* @throws An error if the operation fails.
|
|
19
|
+
*/
|
|
20
|
+
getRoutes(data) {
|
|
21
|
+
var _a;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getLifiRoutes(data);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves a quote from the Li.Fi integration.
|
|
28
|
+
* @param data - The parameters for the quote request.
|
|
29
|
+
* @returns A `LifiQuoteResponse` promise.
|
|
30
|
+
* @throws An error if the operation fails.
|
|
31
|
+
*/
|
|
32
|
+
getQuote(data) {
|
|
33
|
+
var _a;
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getLifiQuote(data);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the status of a transaction from the Li.Fi integration.
|
|
40
|
+
* @param data - The parameters for the status request.
|
|
41
|
+
* @returns A `LifiStatusResponse` promise.
|
|
42
|
+
* @throws An error if the operation fails.
|
|
43
|
+
*/
|
|
44
|
+
getStatus(data) {
|
|
45
|
+
var _a;
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getLifiStatus(data);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves an unsigned transaction from the Li.Fi integration that has yet to be signed/submitted.
|
|
52
|
+
* @param data - The step transaction request containing the step details.
|
|
53
|
+
* @returns A `LifiStepTransactionResponse` promise.
|
|
54
|
+
* @throws An error if the operation fails.
|
|
55
|
+
*/
|
|
56
|
+
getRouteStep(data) {
|
|
57
|
+
var _a;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getLifiRouteStep(data);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
import LiFi from '.';
|
|
14
|
+
import Mpc from '../../../mpc';
|
|
15
|
+
import portalMock from '../../../__mocks/portal/portal';
|
|
16
|
+
import { mockHost, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, } from '../../../__mocks/constants';
|
|
17
|
+
describe('LiFi', () => {
|
|
18
|
+
let lifi;
|
|
19
|
+
let mpc;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
portalMock.host = mockHost;
|
|
23
|
+
mpc = new Mpc({
|
|
24
|
+
portal: portalMock,
|
|
25
|
+
});
|
|
26
|
+
lifi = new LiFi({ mpc });
|
|
27
|
+
});
|
|
28
|
+
describe('getRoutes', () => {
|
|
29
|
+
it('should call mpc.getLifiRoutes with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const spy = jest
|
|
31
|
+
.spyOn(mpc, 'getLifiRoutes')
|
|
32
|
+
.mockResolvedValue(mockLifiGetRoutesResponse);
|
|
33
|
+
const result = yield lifi.getRoutes(mockLifiGetRoutesRequest);
|
|
34
|
+
expect(spy).toHaveBeenCalledWith(mockLifiGetRoutesRequest);
|
|
35
|
+
expect(result).toEqual(mockLifiGetRoutesResponse);
|
|
36
|
+
}));
|
|
37
|
+
it('should propagate errors from mpc.getLifiRoutes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const error = new Error('Test error');
|
|
39
|
+
jest.spyOn(mpc, 'getLifiRoutes').mockRejectedValue(error);
|
|
40
|
+
yield expect(lifi.getRoutes(mockLifiGetRoutesRequest)).rejects.toThrow('Test error');
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
describe('getQuote', () => {
|
|
44
|
+
it('should call mpc.getLifiQuote with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const spy = jest
|
|
46
|
+
.spyOn(mpc, 'getLifiQuote')
|
|
47
|
+
.mockResolvedValue(mockLifiGetQuoteResponse);
|
|
48
|
+
const result = yield lifi.getQuote(mockLifiGetQuoteRequest);
|
|
49
|
+
expect(spy).toHaveBeenCalledWith(mockLifiGetQuoteRequest);
|
|
50
|
+
expect(result).toEqual(mockLifiGetQuoteResponse);
|
|
51
|
+
}));
|
|
52
|
+
it('should propagate errors from mpc.getLifiQuote', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const error = new Error('Test error');
|
|
54
|
+
jest.spyOn(mpc, 'getLifiQuote').mockRejectedValue(error);
|
|
55
|
+
yield expect(lifi.getQuote(mockLifiGetQuoteRequest)).rejects.toThrow('Test error');
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
describe('getStatus', () => {
|
|
59
|
+
it('should call mpc.getLifiStatus with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const spy = jest
|
|
61
|
+
.spyOn(mpc, 'getLifiStatus')
|
|
62
|
+
.mockResolvedValue(mockLifiGetStatusResponse);
|
|
63
|
+
const result = yield lifi.getStatus(mockLifiGetStatusRequest);
|
|
64
|
+
expect(spy).toHaveBeenCalledWith(mockLifiGetStatusRequest);
|
|
65
|
+
expect(result).toEqual(mockLifiGetStatusResponse);
|
|
66
|
+
}));
|
|
67
|
+
it('should propagate errors from mpc.getLifiStatus', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const error = new Error('Test error');
|
|
69
|
+
jest.spyOn(mpc, 'getLifiStatus').mockRejectedValue(error);
|
|
70
|
+
yield expect(lifi.getStatus(mockLifiGetStatusRequest)).rejects.toThrow('Test error');
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
describe('getRouteStep', () => {
|
|
74
|
+
it('should call mpc.getLifiRouteStep with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const spy = jest
|
|
76
|
+
.spyOn(mpc, 'getLifiRouteStep')
|
|
77
|
+
.mockResolvedValue(mockLifiGetRouteStepResponse);
|
|
78
|
+
const result = yield lifi.getRouteStep(mockLifiGetRouteStepRequest);
|
|
79
|
+
expect(spy).toHaveBeenCalledWith(mockLifiGetRouteStepRequest);
|
|
80
|
+
expect(result).toEqual(mockLifiGetRouteStepResponse);
|
|
81
|
+
}));
|
|
82
|
+
it('should propagate errors from mpc.getLifiRouteStep', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const error = new Error('Test error');
|
|
84
|
+
jest.spyOn(mpc, 'getLifiRouteStep').mockRejectedValue(error);
|
|
85
|
+
yield expect(lifi.getRouteStep(mockLifiGetRouteStepRequest)).rejects.toThrow('Test error');
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default class ZeroX {
|
|
11
|
+
constructor({ mpc }) {
|
|
12
|
+
this.mpc = mpc;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get a quote from the Swaps API.
|
|
16
|
+
*
|
|
17
|
+
* @param apiKey - The API key for the Swaps API.
|
|
18
|
+
* @param args - The arguments for the quote.
|
|
19
|
+
* @param chainId - The chain ID for the quote.
|
|
20
|
+
* @returns The quote response.
|
|
21
|
+
*/
|
|
22
|
+
getQuote(apiKey, args, chainId) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getQuote(apiKey, args, chainId);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the valid, swappable token sources that can be used with your Portal MPC Wallet.
|
|
30
|
+
*
|
|
31
|
+
* @param apiKey - The API key for the Swaps API.
|
|
32
|
+
* @param chainId - The chain ID for the sources.
|
|
33
|
+
* @returns The sources response.
|
|
34
|
+
*/
|
|
35
|
+
getSources(apiKey, chainId) {
|
|
36
|
+
var _a;
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getSources(apiKey, chainId);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
import ZeroX from '.';
|
|
14
|
+
import Mpc from '../../../mpc';
|
|
15
|
+
import portalMock from '../../../__mocks/portal/portal';
|
|
16
|
+
import { mockHost, mockQuoteArgs, mockSourcesRes, mockZeroXQuoteResponse, } from '../../../__mocks/constants';
|
|
17
|
+
describe('ZeroX', () => {
|
|
18
|
+
let zeroX;
|
|
19
|
+
let mpc;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
portalMock.host = mockHost;
|
|
23
|
+
mpc = new Mpc({
|
|
24
|
+
portal: portalMock,
|
|
25
|
+
});
|
|
26
|
+
zeroX = new ZeroX({ mpc });
|
|
27
|
+
});
|
|
28
|
+
describe('getQuote', () => {
|
|
29
|
+
it('should correctly call mpc.getQuote', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const spy = jest
|
|
31
|
+
.spyOn(mpc, 'getQuote')
|
|
32
|
+
.mockResolvedValue(mockZeroXQuoteResponse);
|
|
33
|
+
const result = yield zeroX.getQuote('test', mockQuoteArgs, 'eip155:1');
|
|
34
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(spy).toHaveBeenCalledWith('test', mockQuoteArgs, 'eip155:1');
|
|
36
|
+
expect(result).toEqual(mockZeroXQuoteResponse);
|
|
37
|
+
}));
|
|
38
|
+
it('should propagate errors from mpc.getQuote', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const error = new Error('Test error');
|
|
40
|
+
jest.spyOn(mpc, 'getQuote').mockRejectedValue(error);
|
|
41
|
+
yield expect(zeroX.getQuote('test', mockQuoteArgs, 'eip155:1')).rejects.toThrow('Test error');
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
describe('getSources', () => {
|
|
45
|
+
it('should correctly call mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const spy = jest
|
|
47
|
+
.spyOn(mpc, 'getSources')
|
|
48
|
+
.mockResolvedValue(mockSourcesRes);
|
|
49
|
+
const result = yield zeroX.getSources('test', 'eip155:1');
|
|
50
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(spy).toHaveBeenCalledWith('test', 'eip155:1');
|
|
52
|
+
expect(result).toEqual(mockSourcesRes);
|
|
53
|
+
}));
|
|
54
|
+
it('should propagate errors from mpc.getSources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const error = new Error('Test error');
|
|
56
|
+
jest.spyOn(mpc, 'getSources').mockRejectedValue(error);
|
|
57
|
+
yield expect(zeroX.getSources('test', 'eip155:1')).rejects.toThrow('Test error');
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
60
|
+
});
|
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 = '3.
|
|
12
|
+
const WEB_SDK_VERSION = '3.6.0-alpha';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -1069,6 +1069,46 @@ class Mpc {
|
|
|
1069
1069
|
});
|
|
1070
1070
|
});
|
|
1071
1071
|
}
|
|
1072
|
+
getLifiRoutes(data) {
|
|
1073
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1074
|
+
return this.handleRequestToIframeAndPost({
|
|
1075
|
+
methodMessage: 'portal:lifi:getRoutes',
|
|
1076
|
+
errorMessage: 'portal:lifi:getRoutesError',
|
|
1077
|
+
resultMessage: 'portal:lifi:getRoutesResult',
|
|
1078
|
+
data,
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
getLifiQuote(data) {
|
|
1083
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1084
|
+
return this.handleRequestToIframeAndPost({
|
|
1085
|
+
methodMessage: 'portal:lifi:getQuote',
|
|
1086
|
+
errorMessage: 'portal:lifi:getQuoteError',
|
|
1087
|
+
resultMessage: 'portal:lifi:getQuoteResult',
|
|
1088
|
+
data,
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
getLifiStatus(data) {
|
|
1093
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1094
|
+
return this.handleRequestToIframeAndPost({
|
|
1095
|
+
methodMessage: 'portal:lifi:getStatus',
|
|
1096
|
+
errorMessage: 'portal:lifi:getStatusError',
|
|
1097
|
+
resultMessage: 'portal:lifi:getStatusResult',
|
|
1098
|
+
data,
|
|
1099
|
+
});
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
getLifiRouteStep(data) {
|
|
1103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1104
|
+
return this.handleRequestToIframeAndPost({
|
|
1105
|
+
methodMessage: 'portal:lifi:getRouteStep',
|
|
1106
|
+
errorMessage: 'portal:lifi:getRouteStepError',
|
|
1107
|
+
resultMessage: 'portal:lifi:getRouteStepResult',
|
|
1108
|
+
data,
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1072
1112
|
/***************************
|
|
1073
1113
|
* Private Methods
|
|
1074
1114
|
***************************/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BackupMethods, MpcStatuses, PortalCurve } from '../index';
|
|
5
5
|
import Mpc from '.';
|
|
6
|
-
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, } from '../__mocks/constants';
|
|
6
|
+
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, } from '../__mocks/constants';
|
|
7
7
|
import portalMock from '../__mocks/portal/portal';
|
|
8
8
|
import { PortalMpcError } from './errors';
|
|
9
9
|
describe('Mpc', () => {
|
|
@@ -2233,4 +2233,264 @@ describe('Mpc', () => {
|
|
|
2233
2233
|
});
|
|
2234
2234
|
});
|
|
2235
2235
|
});
|
|
2236
|
+
describe('getLifiRoutes', () => {
|
|
2237
|
+
const args = mockLifiGetRoutesRequest;
|
|
2238
|
+
const res = mockLifiGetRoutesResponse;
|
|
2239
|
+
it('should successfully return the routes', (done) => {
|
|
2240
|
+
var _a;
|
|
2241
|
+
jest
|
|
2242
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2243
|
+
.mockImplementation((message, origin) => {
|
|
2244
|
+
const { type, data } = message;
|
|
2245
|
+
expect(type).toEqual('portal:lifi:getRoutes');
|
|
2246
|
+
expect(data).toEqual(args);
|
|
2247
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2248
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2249
|
+
origin: mockHostOrigin,
|
|
2250
|
+
data: {
|
|
2251
|
+
type: 'portal:lifi:getRoutesResult',
|
|
2252
|
+
data: res,
|
|
2253
|
+
},
|
|
2254
|
+
}));
|
|
2255
|
+
});
|
|
2256
|
+
mpc
|
|
2257
|
+
.getLifiRoutes(args)
|
|
2258
|
+
.then((data) => {
|
|
2259
|
+
expect(data).toEqual(res);
|
|
2260
|
+
done();
|
|
2261
|
+
})
|
|
2262
|
+
.catch((_) => {
|
|
2263
|
+
expect(0).toEqual(1);
|
|
2264
|
+
done();
|
|
2265
|
+
});
|
|
2266
|
+
});
|
|
2267
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2268
|
+
var _a;
|
|
2269
|
+
jest
|
|
2270
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2271
|
+
.mockImplementationOnce((message, origin) => {
|
|
2272
|
+
const { type, data } = message;
|
|
2273
|
+
expect(type).toEqual('portal:lifi:getRoutes');
|
|
2274
|
+
expect(data).toEqual(args);
|
|
2275
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2276
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2277
|
+
origin: mockHostOrigin,
|
|
2278
|
+
data: {
|
|
2279
|
+
type: 'portal:lifi:getRoutesError',
|
|
2280
|
+
data: {
|
|
2281
|
+
code: 1,
|
|
2282
|
+
message: 'test',
|
|
2283
|
+
},
|
|
2284
|
+
},
|
|
2285
|
+
}));
|
|
2286
|
+
});
|
|
2287
|
+
mpc
|
|
2288
|
+
.getLifiRoutes(args)
|
|
2289
|
+
.then(() => {
|
|
2290
|
+
expect(0).toEqual(1);
|
|
2291
|
+
done();
|
|
2292
|
+
})
|
|
2293
|
+
.catch((e) => {
|
|
2294
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2295
|
+
expect(e.message).toEqual('test');
|
|
2296
|
+
expect(e.code).toEqual(1);
|
|
2297
|
+
done();
|
|
2298
|
+
});
|
|
2299
|
+
});
|
|
2300
|
+
});
|
|
2301
|
+
describe('getLifiQuote', () => {
|
|
2302
|
+
const args = mockLifiGetQuoteRequest;
|
|
2303
|
+
const res = mockLifiGetQuoteResponse;
|
|
2304
|
+
it('should successfully return the quote', (done) => {
|
|
2305
|
+
var _a;
|
|
2306
|
+
jest
|
|
2307
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2308
|
+
.mockImplementation((message, origin) => {
|
|
2309
|
+
const { type, data } = message;
|
|
2310
|
+
expect(type).toEqual('portal:lifi:getQuote');
|
|
2311
|
+
expect(data).toEqual(args);
|
|
2312
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2313
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2314
|
+
origin: mockHostOrigin,
|
|
2315
|
+
data: {
|
|
2316
|
+
type: 'portal:lifi:getQuoteResult',
|
|
2317
|
+
data: res,
|
|
2318
|
+
},
|
|
2319
|
+
}));
|
|
2320
|
+
});
|
|
2321
|
+
mpc
|
|
2322
|
+
.getLifiQuote(args)
|
|
2323
|
+
.then((data) => {
|
|
2324
|
+
expect(data).toEqual(res);
|
|
2325
|
+
done();
|
|
2326
|
+
})
|
|
2327
|
+
.catch((_) => {
|
|
2328
|
+
expect(0).toEqual(1);
|
|
2329
|
+
done();
|
|
2330
|
+
});
|
|
2331
|
+
});
|
|
2332
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2333
|
+
var _a;
|
|
2334
|
+
jest
|
|
2335
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2336
|
+
.mockImplementationOnce((message, origin) => {
|
|
2337
|
+
const { type, data } = message;
|
|
2338
|
+
expect(type).toEqual('portal:lifi:getQuote');
|
|
2339
|
+
expect(data).toEqual(args);
|
|
2340
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2341
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2342
|
+
origin: mockHostOrigin,
|
|
2343
|
+
data: {
|
|
2344
|
+
type: 'portal:lifi:getQuoteError',
|
|
2345
|
+
data: {
|
|
2346
|
+
code: 1,
|
|
2347
|
+
message: 'test',
|
|
2348
|
+
},
|
|
2349
|
+
},
|
|
2350
|
+
}));
|
|
2351
|
+
});
|
|
2352
|
+
mpc
|
|
2353
|
+
.getLifiQuote(args)
|
|
2354
|
+
.then(() => {
|
|
2355
|
+
expect(0).toEqual(1);
|
|
2356
|
+
done();
|
|
2357
|
+
})
|
|
2358
|
+
.catch((e) => {
|
|
2359
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2360
|
+
expect(e.message).toEqual('test');
|
|
2361
|
+
expect(e.code).toEqual(1);
|
|
2362
|
+
done();
|
|
2363
|
+
});
|
|
2364
|
+
});
|
|
2365
|
+
});
|
|
2366
|
+
describe('getLifiStatus', () => {
|
|
2367
|
+
const args = mockLifiGetStatusRequest;
|
|
2368
|
+
const res = mockLifiGetStatusResponse;
|
|
2369
|
+
it('should successfully return the status', (done) => {
|
|
2370
|
+
var _a;
|
|
2371
|
+
jest
|
|
2372
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2373
|
+
.mockImplementation((message, origin) => {
|
|
2374
|
+
const { type, data } = message;
|
|
2375
|
+
expect(type).toEqual('portal:lifi:getStatus');
|
|
2376
|
+
expect(data).toEqual(args);
|
|
2377
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2378
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2379
|
+
origin: mockHostOrigin,
|
|
2380
|
+
data: {
|
|
2381
|
+
type: 'portal:lifi:getStatusResult',
|
|
2382
|
+
data: res,
|
|
2383
|
+
},
|
|
2384
|
+
}));
|
|
2385
|
+
});
|
|
2386
|
+
mpc
|
|
2387
|
+
.getLifiStatus(args)
|
|
2388
|
+
.then((data) => {
|
|
2389
|
+
expect(data).toEqual(res);
|
|
2390
|
+
done();
|
|
2391
|
+
})
|
|
2392
|
+
.catch((_) => {
|
|
2393
|
+
expect(0).toEqual(1);
|
|
2394
|
+
done();
|
|
2395
|
+
});
|
|
2396
|
+
});
|
|
2397
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2398
|
+
var _a;
|
|
2399
|
+
jest
|
|
2400
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2401
|
+
.mockImplementationOnce((message, origin) => {
|
|
2402
|
+
const { type, data } = message;
|
|
2403
|
+
expect(type).toEqual('portal:lifi:getStatus');
|
|
2404
|
+
expect(data).toEqual(args);
|
|
2405
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2406
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2407
|
+
origin: mockHostOrigin,
|
|
2408
|
+
data: {
|
|
2409
|
+
type: 'portal:lifi:getStatusError',
|
|
2410
|
+
data: {
|
|
2411
|
+
code: 1,
|
|
2412
|
+
message: 'test',
|
|
2413
|
+
},
|
|
2414
|
+
},
|
|
2415
|
+
}));
|
|
2416
|
+
});
|
|
2417
|
+
mpc
|
|
2418
|
+
.getLifiStatus(args)
|
|
2419
|
+
.then(() => {
|
|
2420
|
+
expect(0).toEqual(1);
|
|
2421
|
+
done();
|
|
2422
|
+
})
|
|
2423
|
+
.catch((e) => {
|
|
2424
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2425
|
+
expect(e.message).toEqual('test');
|
|
2426
|
+
expect(e.code).toEqual(1);
|
|
2427
|
+
done();
|
|
2428
|
+
});
|
|
2429
|
+
});
|
|
2430
|
+
});
|
|
2431
|
+
describe('getLifiRouteStep', () => {
|
|
2432
|
+
const args = mockLifiGetRouteStepRequest;
|
|
2433
|
+
const res = mockLifiGetRouteStepResponse;
|
|
2434
|
+
it('should successfully return the route step', (done) => {
|
|
2435
|
+
var _a;
|
|
2436
|
+
jest
|
|
2437
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2438
|
+
.mockImplementation((message, origin) => {
|
|
2439
|
+
const { type, data } = message;
|
|
2440
|
+
expect(type).toEqual('portal:lifi:getRouteStep');
|
|
2441
|
+
expect(data).toEqual(args);
|
|
2442
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2443
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2444
|
+
origin: mockHostOrigin,
|
|
2445
|
+
data: {
|
|
2446
|
+
type: 'portal:lifi:getRouteStepResult',
|
|
2447
|
+
data: res,
|
|
2448
|
+
},
|
|
2449
|
+
}));
|
|
2450
|
+
});
|
|
2451
|
+
mpc
|
|
2452
|
+
.getLifiRouteStep(args)
|
|
2453
|
+
.then((data) => {
|
|
2454
|
+
expect(data).toEqual(res);
|
|
2455
|
+
done();
|
|
2456
|
+
})
|
|
2457
|
+
.catch((_) => {
|
|
2458
|
+
expect(0).toEqual(1);
|
|
2459
|
+
done();
|
|
2460
|
+
});
|
|
2461
|
+
});
|
|
2462
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2463
|
+
var _a;
|
|
2464
|
+
jest
|
|
2465
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2466
|
+
.mockImplementationOnce((message, origin) => {
|
|
2467
|
+
const { type, data } = message;
|
|
2468
|
+
expect(type).toEqual('portal:lifi:getRouteStep');
|
|
2469
|
+
expect(data).toEqual(args);
|
|
2470
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2471
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2472
|
+
origin: mockHostOrigin,
|
|
2473
|
+
data: {
|
|
2474
|
+
type: 'portal:lifi:getRouteStepError',
|
|
2475
|
+
data: {
|
|
2476
|
+
code: 1,
|
|
2477
|
+
message: 'test',
|
|
2478
|
+
},
|
|
2479
|
+
},
|
|
2480
|
+
}));
|
|
2481
|
+
});
|
|
2482
|
+
mpc
|
|
2483
|
+
.getLifiRouteStep(args)
|
|
2484
|
+
.then(() => {
|
|
2485
|
+
expect(0).toEqual(1);
|
|
2486
|
+
done();
|
|
2487
|
+
})
|
|
2488
|
+
.catch((e) => {
|
|
2489
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2490
|
+
expect(e.message).toEqual('test');
|
|
2491
|
+
expect(e.code).toEqual(1);
|
|
2492
|
+
done();
|
|
2493
|
+
});
|
|
2494
|
+
});
|
|
2495
|
+
});
|
|
2236
2496
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Portal MPC Support for Web",
|
|
4
4
|
"author": "Portal Labs, Inc.",
|
|
5
5
|
"homepage": "https://portalhq.io/",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.6.0-alpha",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "lib/commonjs/index",
|
|
9
9
|
"module": "lib/esm/index",
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@solana/web3.js": "^1.91.8"
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"stableVersion": "3.5.2"
|
|
53
54
|
}
|