@portal-hq/web 3.4.2-beta.2 → 3.5.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 +2 -0
- package/lib/commonjs/integrations/yield/index.js +16 -0
- package/lib/commonjs/integrations/yield/yieldxyz.js +115 -0
- package/lib/commonjs/integrations/yield/yieldxyz.test.js +154 -0
- package/lib/commonjs/mpc/index.js +122 -1
- package/lib/commonjs/mpc/index.test.js +539 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/integrations/yield/index.js +10 -0
- package/lib/esm/integrations/yield/yieldxyz.js +112 -0
- package/lib/esm/integrations/yield/yieldxyz.test.js +149 -0
- package/lib/esm/mpc/index.js +122 -1
- package/lib/esm/mpc/index.test.js +540 -1
- package/package.json +2 -2
- package/src/__mocks/constants.ts +319 -0
- package/src/index.ts +25 -2
- package/src/integrations/yield/index.ts +14 -0
- package/src/integrations/yield/yieldxyz.test.ts +220 -0
- package/src/integrations/yield/yieldxyz.ts +122 -0
- package/src/mpc/index.test.ts +645 -0
- package/src/mpc/index.ts +170 -5
- package/tsconfig.json +1 -1
- package/types.d.ts +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
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 YieldXyz from './yieldxyz';
|
|
14
|
+
import Mpc from '../../mpc';
|
|
15
|
+
import portalMock from '../../__mocks/portal/portal';
|
|
16
|
+
import { mockHost, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, } from '../../__mocks/constants';
|
|
17
|
+
describe('YieldXyz', () => {
|
|
18
|
+
let yieldXyz;
|
|
19
|
+
let mpc;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
portalMock.host = mockHost;
|
|
23
|
+
mpc = new Mpc({
|
|
24
|
+
portal: portalMock,
|
|
25
|
+
});
|
|
26
|
+
yieldXyz = new YieldXyz({ mpc });
|
|
27
|
+
});
|
|
28
|
+
describe('discover', () => {
|
|
29
|
+
it('should call mpc.getYieldXyzYields with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const spy = jest
|
|
31
|
+
.spyOn(mpc, 'getYieldXyzYields')
|
|
32
|
+
.mockResolvedValue(mockYieldXyzGetYieldsResponse);
|
|
33
|
+
const result = yield yieldXyz.discover(mockYieldXyzGetYieldsRequest);
|
|
34
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzGetYieldsRequest);
|
|
35
|
+
expect(result).toEqual(mockYieldXyzGetYieldsResponse);
|
|
36
|
+
}));
|
|
37
|
+
it('should propagate errors from mpc.getYieldXyzYields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const error = new Error('Test error');
|
|
39
|
+
jest.spyOn(mpc, 'getYieldXyzYields').mockRejectedValue(error);
|
|
40
|
+
yield expect(yieldXyz.discover(mockYieldXyzGetYieldsRequest)).rejects.toThrow('Test error');
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
describe('enter', () => {
|
|
44
|
+
it('should call mpc.enterYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const spy = jest
|
|
46
|
+
.spyOn(mpc, 'enterYieldXyzYield')
|
|
47
|
+
.mockResolvedValue(mockYieldXyzEnterResponse);
|
|
48
|
+
const result = yield yieldXyz.enter(mockYieldXyzEnterRequest);
|
|
49
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzEnterRequest);
|
|
50
|
+
expect(result).toEqual(mockYieldXyzEnterResponse);
|
|
51
|
+
}));
|
|
52
|
+
it('should propagate errors from mpc.enterYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const error = new Error('Test error');
|
|
54
|
+
jest.spyOn(mpc, 'enterYieldXyzYield').mockRejectedValue(error);
|
|
55
|
+
yield expect(yieldXyz.enter(mockYieldXyzEnterRequest)).rejects.toThrow('Test error');
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
describe('exit', () => {
|
|
59
|
+
it('should call mpc.exitYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const spy = jest
|
|
61
|
+
.spyOn(mpc, 'exitYieldXyzYield')
|
|
62
|
+
.mockResolvedValue(mockYieldXyzExitResponse);
|
|
63
|
+
const result = yield yieldXyz.exit(mockYieldXyzExitRequest);
|
|
64
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzExitRequest);
|
|
65
|
+
expect(result).toEqual(mockYieldXyzExitResponse);
|
|
66
|
+
}));
|
|
67
|
+
it('should propagate errors from mpc.exitYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const error = new Error('Test error');
|
|
69
|
+
jest.spyOn(mpc, 'exitYieldXyzYield').mockRejectedValue(error);
|
|
70
|
+
yield expect(yieldXyz.exit(mockYieldXyzExitRequest)).rejects.toThrow('Test error');
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
describe('getBalances', () => {
|
|
74
|
+
it('should call mpc.getYieldXyzBalances with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const spy = jest
|
|
76
|
+
.spyOn(mpc, 'getYieldXyzBalances')
|
|
77
|
+
.mockResolvedValue(mockYieldXyzGetBalancesResponse);
|
|
78
|
+
const result = yield yieldXyz.getBalances(mockYieldXyzGetBalancesRequest);
|
|
79
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzGetBalancesRequest);
|
|
80
|
+
expect(result).toEqual(mockYieldXyzGetBalancesResponse);
|
|
81
|
+
}));
|
|
82
|
+
it('should propagate errors from mpc.getYieldXyzBalances', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const error = new Error('Test error');
|
|
84
|
+
jest.spyOn(mpc, 'getYieldXyzBalances').mockRejectedValue(error);
|
|
85
|
+
yield expect(yieldXyz.getBalances(mockYieldXyzGetBalancesRequest)).rejects.toThrow('Test error');
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
describe('getHistoricalActions', () => {
|
|
89
|
+
it('should call mpc.getYieldXyzHistoricalActions with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const spy = jest
|
|
91
|
+
.spyOn(mpc, 'getYieldXyzHistoricalActions')
|
|
92
|
+
.mockResolvedValue(mockYieldXyzGetHistoricalActionsResponse);
|
|
93
|
+
const result = yield yieldXyz.getHistoricalActions(mockYieldXyzGetHistoricalActionsRequest);
|
|
94
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzGetHistoricalActionsRequest);
|
|
95
|
+
expect(result).toEqual(mockYieldXyzGetHistoricalActionsResponse);
|
|
96
|
+
}));
|
|
97
|
+
it('should propagate errors from mpc.getYieldXyzHistoricalActions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const error = new Error('Test error');
|
|
99
|
+
jest.spyOn(mpc, 'getYieldXyzHistoricalActions').mockRejectedValue(error);
|
|
100
|
+
yield expect(yieldXyz.getHistoricalActions(mockYieldXyzGetHistoricalActionsRequest)).rejects.toThrow('Test error');
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
describe('manage', () => {
|
|
104
|
+
it('should call mpc.manageYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const spy = jest
|
|
106
|
+
.spyOn(mpc, 'manageYieldXyzYield')
|
|
107
|
+
.mockResolvedValue(mockYieldXyzManageYieldResponse);
|
|
108
|
+
const result = yield yieldXyz.manage(mockYieldXyzManageYieldRequest);
|
|
109
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzManageYieldRequest);
|
|
110
|
+
expect(result).toEqual(mockYieldXyzManageYieldResponse);
|
|
111
|
+
}));
|
|
112
|
+
it('should propagate errors from mpc.manageYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const error = new Error('Test error');
|
|
114
|
+
jest.spyOn(mpc, 'manageYieldXyzYield').mockRejectedValue(error);
|
|
115
|
+
yield expect(yieldXyz.manage(mockYieldXyzManageYieldRequest)).rejects.toThrow('Test error');
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
describe('track', () => {
|
|
119
|
+
it('should call mpc.trackYieldXyzTransaction with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
|
+
const spy = jest
|
|
121
|
+
.spyOn(mpc, 'trackYieldXyzTransaction')
|
|
122
|
+
.mockResolvedValue(mockYieldXyzTrackTransactionResponse);
|
|
123
|
+
const result = yield yieldXyz.track(mockYieldXyzTrackTransactionRequest);
|
|
124
|
+
expect(spy).toHaveBeenCalledWith(mockYieldXyzTrackTransactionRequest);
|
|
125
|
+
expect(result).toEqual(mockYieldXyzTrackTransactionResponse);
|
|
126
|
+
}));
|
|
127
|
+
it('should propagate errors from mpc.trackYieldXyzTransaction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
const error = new Error('Test error');
|
|
129
|
+
jest.spyOn(mpc, 'trackYieldXyzTransaction').mockRejectedValue(error);
|
|
130
|
+
yield expect(yieldXyz.track(mockYieldXyzTrackTransactionRequest)).rejects.toThrow('Test error');
|
|
131
|
+
}));
|
|
132
|
+
});
|
|
133
|
+
describe('getTransaction', () => {
|
|
134
|
+
it('should call mpc.getYieldXyzTransaction with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const transactionId = 'test-tx-id';
|
|
136
|
+
const spy = jest
|
|
137
|
+
.spyOn(mpc, 'getYieldXyzTransaction')
|
|
138
|
+
.mockResolvedValue(mockYieldXyzGetTransactionResponse);
|
|
139
|
+
const result = yield yieldXyz.getTransaction(transactionId);
|
|
140
|
+
expect(spy).toHaveBeenCalledWith(transactionId);
|
|
141
|
+
expect(result).toEqual(mockYieldXyzGetTransactionResponse);
|
|
142
|
+
}));
|
|
143
|
+
it('should propagate errors from mpc.getYieldXyzTransaction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
const error = new Error('Test error');
|
|
145
|
+
jest.spyOn(mpc, 'getYieldXyzTransaction').mockRejectedValue(error);
|
|
146
|
+
yield expect(yieldXyz.getTransaction('test-tx-id')).rejects.toThrow('Test error');
|
|
147
|
+
}));
|
|
148
|
+
});
|
|
149
|
+
});
|
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.5.0-alpha';
|
|
13
13
|
class Mpc {
|
|
14
14
|
get ready() {
|
|
15
15
|
return this._ready;
|
|
@@ -989,9 +989,125 @@ class Mpc {
|
|
|
989
989
|
});
|
|
990
990
|
});
|
|
991
991
|
}
|
|
992
|
+
getYieldXyzYields(data) {
|
|
993
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
994
|
+
return this.handleRequestToIframeAndPost({
|
|
995
|
+
methodMessage: 'portal:yieldxyz:discover',
|
|
996
|
+
errorMessage: 'portal:yieldxyz:discoverError',
|
|
997
|
+
resultMessage: 'portal:yieldxyz:discoverResult',
|
|
998
|
+
data,
|
|
999
|
+
});
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
enterYieldXyzYield(data) {
|
|
1003
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1004
|
+
return this.handleRequestToIframeAndPost({
|
|
1005
|
+
methodMessage: 'portal:yieldxyz:enter',
|
|
1006
|
+
errorMessage: 'portal:yieldxyz:enterError',
|
|
1007
|
+
resultMessage: 'portal:yieldxyz:enterResult',
|
|
1008
|
+
data,
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
exitYieldXyzYield(data) {
|
|
1013
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1014
|
+
return this.handleRequestToIframeAndPost({
|
|
1015
|
+
methodMessage: 'portal:yieldxyz:exit',
|
|
1016
|
+
errorMessage: 'portal:yieldxyz:exitError',
|
|
1017
|
+
resultMessage: 'portal:yieldxyz:exitResult',
|
|
1018
|
+
data,
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
getYieldXyzBalances(data) {
|
|
1023
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1024
|
+
return this.handleRequestToIframeAndPost({
|
|
1025
|
+
methodMessage: 'portal:yieldxyz:getBalances',
|
|
1026
|
+
errorMessage: 'portal:yieldxyz:getBalancesError',
|
|
1027
|
+
resultMessage: 'portal:yieldxyz:getBalancesResult',
|
|
1028
|
+
data,
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
getYieldXyzHistoricalActions(data) {
|
|
1033
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1034
|
+
return this.handleRequestToIframeAndPost({
|
|
1035
|
+
methodMessage: 'portal:yieldxyz:getHistoricalActions',
|
|
1036
|
+
errorMessage: 'portal:yieldxyz:getHistoricalActionsError',
|
|
1037
|
+
resultMessage: 'portal:yieldxyz:getHistoricalActionsResult',
|
|
1038
|
+
data,
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
manageYieldXyzYield(data) {
|
|
1043
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1044
|
+
return this.handleRequestToIframeAndPost({
|
|
1045
|
+
methodMessage: 'portal:yieldxyz:manage',
|
|
1046
|
+
errorMessage: 'portal:yieldxyz:manageYieldError',
|
|
1047
|
+
resultMessage: 'portal:yieldxyz:manageYieldResult',
|
|
1048
|
+
data,
|
|
1049
|
+
});
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
trackYieldXyzTransaction(data) {
|
|
1053
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1054
|
+
return this.handleRequestToIframeAndPost({
|
|
1055
|
+
methodMessage: 'portal:yieldxyz:track',
|
|
1056
|
+
errorMessage: 'portal:yieldxyz:trackError',
|
|
1057
|
+
resultMessage: 'portal:yieldxyz:trackResult',
|
|
1058
|
+
data,
|
|
1059
|
+
});
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
getYieldXyzTransaction(data) {
|
|
1063
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1064
|
+
return this.handleRequestToIframeAndPost({
|
|
1065
|
+
methodMessage: 'portal:yieldxyz:getTransaction',
|
|
1066
|
+
errorMessage: 'portal:yieldxyz:getTransactionError',
|
|
1067
|
+
resultMessage: 'portal:yieldxyz:getTransactionResult',
|
|
1068
|
+
data,
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
992
1072
|
/***************************
|
|
993
1073
|
* Private Methods
|
|
994
1074
|
***************************/
|
|
1075
|
+
/**
|
|
1076
|
+
* Util to handle requests to the iframe and post the result to the parent
|
|
1077
|
+
*/
|
|
1078
|
+
handleRequestToIframeAndPost({ methodMessage, errorMessage, resultMessage, data, }) {
|
|
1079
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1080
|
+
return new Promise((resolve, reject) => {
|
|
1081
|
+
const handleRequest = (event) => {
|
|
1082
|
+
const { type, data: result } = event.data;
|
|
1083
|
+
const { origin } = event;
|
|
1084
|
+
// ignore any broadcast postMessages
|
|
1085
|
+
if (origin !== this.getOrigin()) {
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
if (type === errorMessage) {
|
|
1089
|
+
// Remove the event listener
|
|
1090
|
+
window.removeEventListener('message', handleRequest);
|
|
1091
|
+
// Reject the promise with the error
|
|
1092
|
+
return reject(new PortalMpcError(result));
|
|
1093
|
+
}
|
|
1094
|
+
else if (type === resultMessage) {
|
|
1095
|
+
// Remove the event listener
|
|
1096
|
+
window.removeEventListener('message', handleRequest);
|
|
1097
|
+
// Resolve the promise with the result
|
|
1098
|
+
resolve(result);
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
// Bind the function to the message event
|
|
1102
|
+
window.addEventListener('message', handleRequest);
|
|
1103
|
+
// Send the request to the iframe
|
|
1104
|
+
this.postMessage({
|
|
1105
|
+
type: methodMessage,
|
|
1106
|
+
data,
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
995
1111
|
/**
|
|
996
1112
|
* Appends the iframe to the document body
|
|
997
1113
|
*/
|
|
@@ -1059,6 +1175,11 @@ class Mpc {
|
|
|
1059
1175
|
window.addEventListener('message', handleError);
|
|
1060
1176
|
}
|
|
1061
1177
|
validateBackupConfig(data) {
|
|
1178
|
+
// Validate that backupMethod is one of the valid BackupMethods
|
|
1179
|
+
const validBackupMethods = Object.values(BackupMethods);
|
|
1180
|
+
if (!validBackupMethods.includes(data.backupMethod)) {
|
|
1181
|
+
throw new Error(`Invalid backup method: ${data.backupMethod}. Valid methods are: ${validBackupMethods.join(', ')}`);
|
|
1182
|
+
}
|
|
1062
1183
|
if (data.backupMethod === BackupMethods.password) {
|
|
1063
1184
|
if (!data.backupConfigs.passwordStorage) {
|
|
1064
1185
|
throw new Error('Password storage config is required');
|