@portal-hq/web 3.4.1 → 3.4.2
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 +1 -1
- 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
package/lib/commonjs/index.js
CHANGED
|
@@ -39,6 +39,7 @@ exports.ChainNamespace = exports.PortalCurve = exports.GetTransactionsOrder = ex
|
|
|
39
39
|
const web3_js_1 = require("@solana/web3.js");
|
|
40
40
|
const mpc_1 = __importDefault(require("./mpc"));
|
|
41
41
|
const provider_1 = __importStar(require("./provider"));
|
|
42
|
+
const yield_1 = __importDefault(require("./integrations/yield"));
|
|
42
43
|
class Portal {
|
|
43
44
|
get ready() {
|
|
44
45
|
return this.mpc.ready;
|
|
@@ -81,6 +82,7 @@ class Portal {
|
|
|
81
82
|
this.mpc = new mpc_1.default({
|
|
82
83
|
portal: this,
|
|
83
84
|
});
|
|
85
|
+
this.yield = new yield_1.default({ mpc: this.mpc });
|
|
84
86
|
this.provider = new provider_1.default({
|
|
85
87
|
portal: this,
|
|
86
88
|
chainId: chainId ? Number(chainId) : undefined,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const yieldxyz_1 = __importDefault(require("./yieldxyz"));
|
|
7
|
+
/**
|
|
8
|
+
* This class is a container for the YieldXyz class.
|
|
9
|
+
* In the future, Yield domain logic should be here.
|
|
10
|
+
*/
|
|
11
|
+
class Yield {
|
|
12
|
+
constructor({ mpc }) {
|
|
13
|
+
this.yieldXyz = new yieldxyz_1.default({ mpc });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = Yield;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class YieldXyz {
|
|
13
|
+
constructor({ mpc }) {
|
|
14
|
+
this.mpc = mpc;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves yield balances for specified addresses and networks.
|
|
18
|
+
* @param data - The parameters for the yield balances request.
|
|
19
|
+
* @returns A `YieldXyzGetBalancesResponse` promise, resolving to balance information.
|
|
20
|
+
* @throws An error if the operation fails.
|
|
21
|
+
*/
|
|
22
|
+
getBalances(data) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getYieldXyzBalances(data);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves historical yield actions with optional filtering.
|
|
30
|
+
* @param data - The parameters for the historical yield actions request.
|
|
31
|
+
* @returns A `YieldXyzGetHistoricalActionsResponse` promise, resolving to historical actions.
|
|
32
|
+
* @throws An error if the operation fails.
|
|
33
|
+
*/
|
|
34
|
+
getHistoricalActions(data) {
|
|
35
|
+
var _a;
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getYieldXyzHistoricalActions(data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Manages a yield opportunity with the specified parameters.
|
|
42
|
+
* @param data - The parameters for managing a yield opportunity.
|
|
43
|
+
* @returns A `YieldXyzManageYieldResponse` promise, resolving to the action details.
|
|
44
|
+
* @throws An error if the operation fails.
|
|
45
|
+
*/
|
|
46
|
+
manage(data) {
|
|
47
|
+
var _a;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.manageYieldXyzYield(data);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Enters a yield opportunity with the specified parameters.
|
|
54
|
+
* @param data - The parameters for entering a yield opportunity.
|
|
55
|
+
* @returns A `YieldXyzEnterYieldResponse` promise, resolving to the action details.
|
|
56
|
+
* @throws An error if the operation fails.
|
|
57
|
+
*/
|
|
58
|
+
enter(data) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.enterYieldXyzYield(data);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Exits a yield opportunity with the specified parameters.
|
|
66
|
+
* @param data - The parameters for exiting a yield opportunity.
|
|
67
|
+
* @returns A `YieldXyzExitResponse` promise, resolving to the action details.
|
|
68
|
+
* @throws An error if the operation fails.
|
|
69
|
+
*/
|
|
70
|
+
exit(data) {
|
|
71
|
+
var _a;
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.exitYieldXyzYield(data);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Discovers yield opportunities based on the provided parameters.
|
|
78
|
+
* @param data - Optional parameters for yield discovery. If undefined, uses default parameters.
|
|
79
|
+
* @returns A `YieldXyzGetYieldsResponse` promise, resolving to available yield opportunities.
|
|
80
|
+
* @throws An error if the operation fails.
|
|
81
|
+
*/
|
|
82
|
+
discover(data) {
|
|
83
|
+
var _a;
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getYieldXyzYields(data);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Tracks a transaction by submitting its hash to the Yield.xyz integration.
|
|
90
|
+
* @param data - The parameters for tracking a transaction:
|
|
91
|
+
* - transactionId: The ID of the transaction to track.
|
|
92
|
+
* - txHash: The hash of the transaction to submit.
|
|
93
|
+
* @returns A `YieldXyzTrackTransactionResponse` promise.
|
|
94
|
+
* @throws An error if the operation fails.
|
|
95
|
+
*/
|
|
96
|
+
track(data) {
|
|
97
|
+
var _a;
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.trackYieldXyzTransaction(data);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves a single yield action transaction by its ID.
|
|
104
|
+
* @param transactionId - The ID of the transaction to retrieve.
|
|
105
|
+
* @returns A `YieldXyzGetTransactionResponse` promise, resolving to transaction details.
|
|
106
|
+
* @throws An error if the operation fails.
|
|
107
|
+
*/
|
|
108
|
+
getTransaction(transactionId) {
|
|
109
|
+
var _a;
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getYieldXyzTransaction(transactionId);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.default = YieldXyz;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @jest-environment jsdom
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const yieldxyz_1 = __importDefault(require("./yieldxyz"));
|
|
19
|
+
const mpc_1 = __importDefault(require("../../mpc"));
|
|
20
|
+
const portal_1 = __importDefault(require("../../__mocks/portal/portal"));
|
|
21
|
+
const constants_1 = require("../../__mocks/constants");
|
|
22
|
+
describe('YieldXyz', () => {
|
|
23
|
+
let yieldXyz;
|
|
24
|
+
let mpc;
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
jest.clearAllMocks();
|
|
27
|
+
portal_1.default.host = constants_1.mockHost;
|
|
28
|
+
mpc = new mpc_1.default({
|
|
29
|
+
portal: portal_1.default,
|
|
30
|
+
});
|
|
31
|
+
yieldXyz = new yieldxyz_1.default({ mpc });
|
|
32
|
+
});
|
|
33
|
+
describe('discover', () => {
|
|
34
|
+
it('should call mpc.getYieldXyzYields with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const spy = jest
|
|
36
|
+
.spyOn(mpc, 'getYieldXyzYields')
|
|
37
|
+
.mockResolvedValue(constants_1.mockYieldXyzGetYieldsResponse);
|
|
38
|
+
const result = yield yieldXyz.discover(constants_1.mockYieldXyzGetYieldsRequest);
|
|
39
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzGetYieldsRequest);
|
|
40
|
+
expect(result).toEqual(constants_1.mockYieldXyzGetYieldsResponse);
|
|
41
|
+
}));
|
|
42
|
+
it('should propagate errors from mpc.getYieldXyzYields', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const error = new Error('Test error');
|
|
44
|
+
jest.spyOn(mpc, 'getYieldXyzYields').mockRejectedValue(error);
|
|
45
|
+
yield expect(yieldXyz.discover(constants_1.mockYieldXyzGetYieldsRequest)).rejects.toThrow('Test error');
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
describe('enter', () => {
|
|
49
|
+
it('should call mpc.enterYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const spy = jest
|
|
51
|
+
.spyOn(mpc, 'enterYieldXyzYield')
|
|
52
|
+
.mockResolvedValue(constants_1.mockYieldXyzEnterResponse);
|
|
53
|
+
const result = yield yieldXyz.enter(constants_1.mockYieldXyzEnterRequest);
|
|
54
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzEnterRequest);
|
|
55
|
+
expect(result).toEqual(constants_1.mockYieldXyzEnterResponse);
|
|
56
|
+
}));
|
|
57
|
+
it('should propagate errors from mpc.enterYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
const error = new Error('Test error');
|
|
59
|
+
jest.spyOn(mpc, 'enterYieldXyzYield').mockRejectedValue(error);
|
|
60
|
+
yield expect(yieldXyz.enter(constants_1.mockYieldXyzEnterRequest)).rejects.toThrow('Test error');
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
describe('exit', () => {
|
|
64
|
+
it('should call mpc.exitYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const spy = jest
|
|
66
|
+
.spyOn(mpc, 'exitYieldXyzYield')
|
|
67
|
+
.mockResolvedValue(constants_1.mockYieldXyzExitResponse);
|
|
68
|
+
const result = yield yieldXyz.exit(constants_1.mockYieldXyzExitRequest);
|
|
69
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzExitRequest);
|
|
70
|
+
expect(result).toEqual(constants_1.mockYieldXyzExitResponse);
|
|
71
|
+
}));
|
|
72
|
+
it('should propagate errors from mpc.exitYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const error = new Error('Test error');
|
|
74
|
+
jest.spyOn(mpc, 'exitYieldXyzYield').mockRejectedValue(error);
|
|
75
|
+
yield expect(yieldXyz.exit(constants_1.mockYieldXyzExitRequest)).rejects.toThrow('Test error');
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
describe('getBalances', () => {
|
|
79
|
+
it('should call mpc.getYieldXyzBalances with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const spy = jest
|
|
81
|
+
.spyOn(mpc, 'getYieldXyzBalances')
|
|
82
|
+
.mockResolvedValue(constants_1.mockYieldXyzGetBalancesResponse);
|
|
83
|
+
const result = yield yieldXyz.getBalances(constants_1.mockYieldXyzGetBalancesRequest);
|
|
84
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzGetBalancesRequest);
|
|
85
|
+
expect(result).toEqual(constants_1.mockYieldXyzGetBalancesResponse);
|
|
86
|
+
}));
|
|
87
|
+
it('should propagate errors from mpc.getYieldXyzBalances', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const error = new Error('Test error');
|
|
89
|
+
jest.spyOn(mpc, 'getYieldXyzBalances').mockRejectedValue(error);
|
|
90
|
+
yield expect(yieldXyz.getBalances(constants_1.mockYieldXyzGetBalancesRequest)).rejects.toThrow('Test error');
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
describe('getHistoricalActions', () => {
|
|
94
|
+
it('should call mpc.getYieldXyzHistoricalActions with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const spy = jest
|
|
96
|
+
.spyOn(mpc, 'getYieldXyzHistoricalActions')
|
|
97
|
+
.mockResolvedValue(constants_1.mockYieldXyzGetHistoricalActionsResponse);
|
|
98
|
+
const result = yield yieldXyz.getHistoricalActions(constants_1.mockYieldXyzGetHistoricalActionsRequest);
|
|
99
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzGetHistoricalActionsRequest);
|
|
100
|
+
expect(result).toEqual(constants_1.mockYieldXyzGetHistoricalActionsResponse);
|
|
101
|
+
}));
|
|
102
|
+
it('should propagate errors from mpc.getYieldXyzHistoricalActions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
const error = new Error('Test error');
|
|
104
|
+
jest.spyOn(mpc, 'getYieldXyzHistoricalActions').mockRejectedValue(error);
|
|
105
|
+
yield expect(yieldXyz.getHistoricalActions(constants_1.mockYieldXyzGetHistoricalActionsRequest)).rejects.toThrow('Test error');
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
describe('manage', () => {
|
|
109
|
+
it('should call mpc.manageYieldXyzYield with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
const spy = jest
|
|
111
|
+
.spyOn(mpc, 'manageYieldXyzYield')
|
|
112
|
+
.mockResolvedValue(constants_1.mockYieldXyzManageYieldResponse);
|
|
113
|
+
const result = yield yieldXyz.manage(constants_1.mockYieldXyzManageYieldRequest);
|
|
114
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzManageYieldRequest);
|
|
115
|
+
expect(result).toEqual(constants_1.mockYieldXyzManageYieldResponse);
|
|
116
|
+
}));
|
|
117
|
+
it('should propagate errors from mpc.manageYieldXyzYield', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const error = new Error('Test error');
|
|
119
|
+
jest.spyOn(mpc, 'manageYieldXyzYield').mockRejectedValue(error);
|
|
120
|
+
yield expect(yieldXyz.manage(constants_1.mockYieldXyzManageYieldRequest)).rejects.toThrow('Test error');
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
describe('track', () => {
|
|
124
|
+
it('should call mpc.trackYieldXyzTransaction with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const spy = jest
|
|
126
|
+
.spyOn(mpc, 'trackYieldXyzTransaction')
|
|
127
|
+
.mockResolvedValue(constants_1.mockYieldXyzTrackTransactionResponse);
|
|
128
|
+
const result = yield yieldXyz.track(constants_1.mockYieldXyzTrackTransactionRequest);
|
|
129
|
+
expect(spy).toHaveBeenCalledWith(constants_1.mockYieldXyzTrackTransactionRequest);
|
|
130
|
+
expect(result).toEqual(constants_1.mockYieldXyzTrackTransactionResponse);
|
|
131
|
+
}));
|
|
132
|
+
it('should propagate errors from mpc.trackYieldXyzTransaction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const error = new Error('Test error');
|
|
134
|
+
jest.spyOn(mpc, 'trackYieldXyzTransaction').mockRejectedValue(error);
|
|
135
|
+
yield expect(yieldXyz.track(constants_1.mockYieldXyzTrackTransactionRequest)).rejects.toThrow('Test error');
|
|
136
|
+
}));
|
|
137
|
+
});
|
|
138
|
+
describe('getTransaction', () => {
|
|
139
|
+
it('should call mpc.getYieldXyzTransaction with the correct arguments', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const transactionId = 'test-tx-id';
|
|
141
|
+
const spy = jest
|
|
142
|
+
.spyOn(mpc, 'getYieldXyzTransaction')
|
|
143
|
+
.mockResolvedValue(constants_1.mockYieldXyzGetTransactionResponse);
|
|
144
|
+
const result = yield yieldXyz.getTransaction(transactionId);
|
|
145
|
+
expect(spy).toHaveBeenCalledWith(transactionId);
|
|
146
|
+
expect(result).toEqual(constants_1.mockYieldXyzGetTransactionResponse);
|
|
147
|
+
}));
|
|
148
|
+
it('should propagate errors from mpc.getYieldXyzTransaction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
const error = new Error('Test error');
|
|
150
|
+
jest.spyOn(mpc, 'getYieldXyzTransaction').mockRejectedValue(error);
|
|
151
|
+
yield expect(yieldXyz.getTransaction('test-tx-id')).rejects.toThrow('Test error');
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -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 = '3.4.
|
|
15
|
+
const WEB_SDK_VERSION = '3.4.2';
|
|
16
16
|
class Mpc {
|
|
17
17
|
get ready() {
|
|
18
18
|
return this._ready;
|
|
@@ -992,9 +992,125 @@ class Mpc {
|
|
|
992
992
|
});
|
|
993
993
|
});
|
|
994
994
|
}
|
|
995
|
+
getYieldXyzYields(data) {
|
|
996
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
997
|
+
return this.handleRequestToIframeAndPost({
|
|
998
|
+
methodMessage: 'portal:yieldxyz:discover',
|
|
999
|
+
errorMessage: 'portal:yieldxyz:discoverError',
|
|
1000
|
+
resultMessage: 'portal:yieldxyz:discoverResult',
|
|
1001
|
+
data,
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
enterYieldXyzYield(data) {
|
|
1006
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1007
|
+
return this.handleRequestToIframeAndPost({
|
|
1008
|
+
methodMessage: 'portal:yieldxyz:enter',
|
|
1009
|
+
errorMessage: 'portal:yieldxyz:enterError',
|
|
1010
|
+
resultMessage: 'portal:yieldxyz:enterResult',
|
|
1011
|
+
data,
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
exitYieldXyzYield(data) {
|
|
1016
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1017
|
+
return this.handleRequestToIframeAndPost({
|
|
1018
|
+
methodMessage: 'portal:yieldxyz:exit',
|
|
1019
|
+
errorMessage: 'portal:yieldxyz:exitError',
|
|
1020
|
+
resultMessage: 'portal:yieldxyz:exitResult',
|
|
1021
|
+
data,
|
|
1022
|
+
});
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
getYieldXyzBalances(data) {
|
|
1026
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1027
|
+
return this.handleRequestToIframeAndPost({
|
|
1028
|
+
methodMessage: 'portal:yieldxyz:getBalances',
|
|
1029
|
+
errorMessage: 'portal:yieldxyz:getBalancesError',
|
|
1030
|
+
resultMessage: 'portal:yieldxyz:getBalancesResult',
|
|
1031
|
+
data,
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
getYieldXyzHistoricalActions(data) {
|
|
1036
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1037
|
+
return this.handleRequestToIframeAndPost({
|
|
1038
|
+
methodMessage: 'portal:yieldxyz:getHistoricalActions',
|
|
1039
|
+
errorMessage: 'portal:yieldxyz:getHistoricalActionsError',
|
|
1040
|
+
resultMessage: 'portal:yieldxyz:getHistoricalActionsResult',
|
|
1041
|
+
data,
|
|
1042
|
+
});
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
manageYieldXyzYield(data) {
|
|
1046
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1047
|
+
return this.handleRequestToIframeAndPost({
|
|
1048
|
+
methodMessage: 'portal:yieldxyz:manage',
|
|
1049
|
+
errorMessage: 'portal:yieldxyz:manageYieldError',
|
|
1050
|
+
resultMessage: 'portal:yieldxyz:manageYieldResult',
|
|
1051
|
+
data,
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
trackYieldXyzTransaction(data) {
|
|
1056
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1057
|
+
return this.handleRequestToIframeAndPost({
|
|
1058
|
+
methodMessage: 'portal:yieldxyz:track',
|
|
1059
|
+
errorMessage: 'portal:yieldxyz:trackError',
|
|
1060
|
+
resultMessage: 'portal:yieldxyz:trackResult',
|
|
1061
|
+
data,
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
getYieldXyzTransaction(data) {
|
|
1066
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1067
|
+
return this.handleRequestToIframeAndPost({
|
|
1068
|
+
methodMessage: 'portal:yieldxyz:getTransaction',
|
|
1069
|
+
errorMessage: 'portal:yieldxyz:getTransactionError',
|
|
1070
|
+
resultMessage: 'portal:yieldxyz:getTransactionResult',
|
|
1071
|
+
data,
|
|
1072
|
+
});
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
995
1075
|
/***************************
|
|
996
1076
|
* Private Methods
|
|
997
1077
|
***************************/
|
|
1078
|
+
/**
|
|
1079
|
+
* Util to handle requests to the iframe and post the result to the parent
|
|
1080
|
+
*/
|
|
1081
|
+
handleRequestToIframeAndPost({ methodMessage, errorMessage, resultMessage, data, }) {
|
|
1082
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1083
|
+
return new Promise((resolve, reject) => {
|
|
1084
|
+
const handleRequest = (event) => {
|
|
1085
|
+
const { type, data: result } = event.data;
|
|
1086
|
+
const { origin } = event;
|
|
1087
|
+
// ignore any broadcast postMessages
|
|
1088
|
+
if (origin !== this.getOrigin()) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
if (type === errorMessage) {
|
|
1092
|
+
// Remove the event listener
|
|
1093
|
+
window.removeEventListener('message', handleRequest);
|
|
1094
|
+
// Reject the promise with the error
|
|
1095
|
+
return reject(new errors_1.PortalMpcError(result));
|
|
1096
|
+
}
|
|
1097
|
+
else if (type === resultMessage) {
|
|
1098
|
+
// Remove the event listener
|
|
1099
|
+
window.removeEventListener('message', handleRequest);
|
|
1100
|
+
// Resolve the promise with the result
|
|
1101
|
+
resolve(result);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
// Bind the function to the message event
|
|
1105
|
+
window.addEventListener('message', handleRequest);
|
|
1106
|
+
// Send the request to the iframe
|
|
1107
|
+
this.postMessage({
|
|
1108
|
+
type: methodMessage,
|
|
1109
|
+
data,
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
998
1114
|
/**
|
|
999
1115
|
* Appends the iframe to the document body
|
|
1000
1116
|
*/
|
|
@@ -1062,6 +1178,11 @@ class Mpc {
|
|
|
1062
1178
|
window.addEventListener('message', handleError);
|
|
1063
1179
|
}
|
|
1064
1180
|
validateBackupConfig(data) {
|
|
1181
|
+
// Validate that backupMethod is one of the valid BackupMethods
|
|
1182
|
+
const validBackupMethods = Object.values(index_1.BackupMethods);
|
|
1183
|
+
if (!validBackupMethods.includes(data.backupMethod)) {
|
|
1184
|
+
throw new Error(`Invalid backup method: ${data.backupMethod}. Valid methods are: ${validBackupMethods.join(', ')}`);
|
|
1185
|
+
}
|
|
1065
1186
|
if (data.backupMethod === index_1.BackupMethods.password) {
|
|
1066
1187
|
if (!data.backupConfigs.passwordStorage) {
|
|
1067
1188
|
throw new Error('Password storage config is required');
|