@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/src/mpc/index.test.ts
CHANGED
|
@@ -41,6 +41,14 @@ import {
|
|
|
41
41
|
mockYieldXyzTrackTransactionRequest,
|
|
42
42
|
mockYieldXyzTrackTransactionResponse,
|
|
43
43
|
mockYieldXyzGetTransactionResponse,
|
|
44
|
+
mockLifiGetRoutesRequest,
|
|
45
|
+
mockLifiGetRoutesResponse,
|
|
46
|
+
mockLifiGetQuoteRequest,
|
|
47
|
+
mockLifiGetQuoteResponse,
|
|
48
|
+
mockLifiGetStatusRequest,
|
|
49
|
+
mockLifiGetStatusResponse,
|
|
50
|
+
mockLifiGetRouteStepRequest,
|
|
51
|
+
mockLifiGetRouteStepResponse,
|
|
44
52
|
} from '../__mocks/constants'
|
|
45
53
|
import portalMock from '../__mocks/portal/portal'
|
|
46
54
|
import { PortalMpcError } from './errors'
|
|
@@ -2633,4 +2641,308 @@ describe('Mpc', () => {
|
|
|
2633
2641
|
})
|
|
2634
2642
|
})
|
|
2635
2643
|
})
|
|
2644
|
+
|
|
2645
|
+
describe('getLifiRoutes', () => {
|
|
2646
|
+
const args = mockLifiGetRoutesRequest
|
|
2647
|
+
const res = mockLifiGetRoutesResponse
|
|
2648
|
+
|
|
2649
|
+
it('should successfully return the routes', (done) => {
|
|
2650
|
+
jest
|
|
2651
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2652
|
+
.mockImplementation((message: any, origin?) => {
|
|
2653
|
+
const { type, data } = message
|
|
2654
|
+
|
|
2655
|
+
expect(type).toEqual('portal:lifi:getRoutes')
|
|
2656
|
+
expect(data).toEqual(args)
|
|
2657
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2658
|
+
|
|
2659
|
+
window.dispatchEvent(
|
|
2660
|
+
new MessageEvent('message', {
|
|
2661
|
+
origin: mockHostOrigin,
|
|
2662
|
+
data: {
|
|
2663
|
+
type: 'portal:lifi:getRoutesResult',
|
|
2664
|
+
data: res,
|
|
2665
|
+
},
|
|
2666
|
+
}),
|
|
2667
|
+
)
|
|
2668
|
+
})
|
|
2669
|
+
|
|
2670
|
+
mpc
|
|
2671
|
+
.getLifiRoutes(args)
|
|
2672
|
+
.then((data) => {
|
|
2673
|
+
expect(data).toEqual(res)
|
|
2674
|
+
done()
|
|
2675
|
+
})
|
|
2676
|
+
.catch((_) => {
|
|
2677
|
+
expect(0).toEqual(1)
|
|
2678
|
+
done()
|
|
2679
|
+
})
|
|
2680
|
+
})
|
|
2681
|
+
|
|
2682
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2683
|
+
jest
|
|
2684
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2685
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2686
|
+
const { type, data } = message
|
|
2687
|
+
|
|
2688
|
+
expect(type).toEqual('portal:lifi:getRoutes')
|
|
2689
|
+
expect(data).toEqual(args)
|
|
2690
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2691
|
+
|
|
2692
|
+
window.dispatchEvent(
|
|
2693
|
+
new MessageEvent('message', {
|
|
2694
|
+
origin: mockHostOrigin,
|
|
2695
|
+
data: {
|
|
2696
|
+
type: 'portal:lifi:getRoutesError',
|
|
2697
|
+
data: {
|
|
2698
|
+
code: 1,
|
|
2699
|
+
message: 'test',
|
|
2700
|
+
},
|
|
2701
|
+
},
|
|
2702
|
+
}),
|
|
2703
|
+
)
|
|
2704
|
+
})
|
|
2705
|
+
|
|
2706
|
+
mpc
|
|
2707
|
+
.getLifiRoutes(args)
|
|
2708
|
+
.then(() => {
|
|
2709
|
+
expect(0).toEqual(1)
|
|
2710
|
+
done()
|
|
2711
|
+
})
|
|
2712
|
+
.catch((e) => {
|
|
2713
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2714
|
+
expect(e.message).toEqual('test')
|
|
2715
|
+
expect(e.code).toEqual(1)
|
|
2716
|
+
done()
|
|
2717
|
+
})
|
|
2718
|
+
})
|
|
2719
|
+
})
|
|
2720
|
+
|
|
2721
|
+
describe('getLifiQuote', () => {
|
|
2722
|
+
const args = mockLifiGetQuoteRequest
|
|
2723
|
+
const res = mockLifiGetQuoteResponse
|
|
2724
|
+
|
|
2725
|
+
it('should successfully return the quote', (done) => {
|
|
2726
|
+
jest
|
|
2727
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2728
|
+
.mockImplementation((message: any, origin?) => {
|
|
2729
|
+
const { type, data } = message
|
|
2730
|
+
|
|
2731
|
+
expect(type).toEqual('portal:lifi:getQuote')
|
|
2732
|
+
expect(data).toEqual(args)
|
|
2733
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2734
|
+
|
|
2735
|
+
window.dispatchEvent(
|
|
2736
|
+
new MessageEvent('message', {
|
|
2737
|
+
origin: mockHostOrigin,
|
|
2738
|
+
data: {
|
|
2739
|
+
type: 'portal:lifi:getQuoteResult',
|
|
2740
|
+
data: res,
|
|
2741
|
+
},
|
|
2742
|
+
}),
|
|
2743
|
+
)
|
|
2744
|
+
})
|
|
2745
|
+
|
|
2746
|
+
mpc
|
|
2747
|
+
.getLifiQuote(args)
|
|
2748
|
+
.then((data) => {
|
|
2749
|
+
expect(data).toEqual(res)
|
|
2750
|
+
done()
|
|
2751
|
+
})
|
|
2752
|
+
.catch((_) => {
|
|
2753
|
+
expect(0).toEqual(1)
|
|
2754
|
+
done()
|
|
2755
|
+
})
|
|
2756
|
+
})
|
|
2757
|
+
|
|
2758
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2759
|
+
jest
|
|
2760
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2761
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2762
|
+
const { type, data } = message
|
|
2763
|
+
|
|
2764
|
+
expect(type).toEqual('portal:lifi:getQuote')
|
|
2765
|
+
expect(data).toEqual(args)
|
|
2766
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2767
|
+
|
|
2768
|
+
window.dispatchEvent(
|
|
2769
|
+
new MessageEvent('message', {
|
|
2770
|
+
origin: mockHostOrigin,
|
|
2771
|
+
data: {
|
|
2772
|
+
type: 'portal:lifi:getQuoteError',
|
|
2773
|
+
data: {
|
|
2774
|
+
code: 1,
|
|
2775
|
+
message: 'test',
|
|
2776
|
+
},
|
|
2777
|
+
},
|
|
2778
|
+
}),
|
|
2779
|
+
)
|
|
2780
|
+
})
|
|
2781
|
+
|
|
2782
|
+
mpc
|
|
2783
|
+
.getLifiQuote(args)
|
|
2784
|
+
.then(() => {
|
|
2785
|
+
expect(0).toEqual(1)
|
|
2786
|
+
done()
|
|
2787
|
+
})
|
|
2788
|
+
.catch((e) => {
|
|
2789
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2790
|
+
expect(e.message).toEqual('test')
|
|
2791
|
+
expect(e.code).toEqual(1)
|
|
2792
|
+
done()
|
|
2793
|
+
})
|
|
2794
|
+
})
|
|
2795
|
+
})
|
|
2796
|
+
|
|
2797
|
+
describe('getLifiStatus', () => {
|
|
2798
|
+
const args = mockLifiGetStatusRequest
|
|
2799
|
+
const res = mockLifiGetStatusResponse
|
|
2800
|
+
|
|
2801
|
+
it('should successfully return the status', (done) => {
|
|
2802
|
+
jest
|
|
2803
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2804
|
+
.mockImplementation((message: any, origin?) => {
|
|
2805
|
+
const { type, data } = message
|
|
2806
|
+
|
|
2807
|
+
expect(type).toEqual('portal:lifi:getStatus')
|
|
2808
|
+
expect(data).toEqual(args)
|
|
2809
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2810
|
+
|
|
2811
|
+
window.dispatchEvent(
|
|
2812
|
+
new MessageEvent('message', {
|
|
2813
|
+
origin: mockHostOrigin,
|
|
2814
|
+
data: {
|
|
2815
|
+
type: 'portal:lifi:getStatusResult',
|
|
2816
|
+
data: res,
|
|
2817
|
+
},
|
|
2818
|
+
}),
|
|
2819
|
+
)
|
|
2820
|
+
})
|
|
2821
|
+
|
|
2822
|
+
mpc
|
|
2823
|
+
.getLifiStatus(args)
|
|
2824
|
+
.then((data) => {
|
|
2825
|
+
expect(data).toEqual(res)
|
|
2826
|
+
done()
|
|
2827
|
+
})
|
|
2828
|
+
.catch((_) => {
|
|
2829
|
+
expect(0).toEqual(1)
|
|
2830
|
+
done()
|
|
2831
|
+
})
|
|
2832
|
+
})
|
|
2833
|
+
|
|
2834
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2835
|
+
jest
|
|
2836
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2837
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2838
|
+
const { type, data } = message
|
|
2839
|
+
|
|
2840
|
+
expect(type).toEqual('portal:lifi:getStatus')
|
|
2841
|
+
expect(data).toEqual(args)
|
|
2842
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2843
|
+
|
|
2844
|
+
window.dispatchEvent(
|
|
2845
|
+
new MessageEvent('message', {
|
|
2846
|
+
origin: mockHostOrigin,
|
|
2847
|
+
data: {
|
|
2848
|
+
type: 'portal:lifi:getStatusError',
|
|
2849
|
+
data: {
|
|
2850
|
+
code: 1,
|
|
2851
|
+
message: 'test',
|
|
2852
|
+
},
|
|
2853
|
+
},
|
|
2854
|
+
}),
|
|
2855
|
+
)
|
|
2856
|
+
})
|
|
2857
|
+
|
|
2858
|
+
mpc
|
|
2859
|
+
.getLifiStatus(args)
|
|
2860
|
+
.then(() => {
|
|
2861
|
+
expect(0).toEqual(1)
|
|
2862
|
+
done()
|
|
2863
|
+
})
|
|
2864
|
+
.catch((e) => {
|
|
2865
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2866
|
+
expect(e.message).toEqual('test')
|
|
2867
|
+
expect(e.code).toEqual(1)
|
|
2868
|
+
done()
|
|
2869
|
+
})
|
|
2870
|
+
})
|
|
2871
|
+
})
|
|
2872
|
+
|
|
2873
|
+
describe('getLifiRouteStep', () => {
|
|
2874
|
+
const args = mockLifiGetRouteStepRequest
|
|
2875
|
+
const res = mockLifiGetRouteStepResponse
|
|
2876
|
+
|
|
2877
|
+
it('should successfully return the route step', (done) => {
|
|
2878
|
+
jest
|
|
2879
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2880
|
+
.mockImplementation((message: any, origin?) => {
|
|
2881
|
+
const { type, data } = message
|
|
2882
|
+
|
|
2883
|
+
expect(type).toEqual('portal:lifi:getRouteStep')
|
|
2884
|
+
expect(data).toEqual(args)
|
|
2885
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2886
|
+
|
|
2887
|
+
window.dispatchEvent(
|
|
2888
|
+
new MessageEvent('message', {
|
|
2889
|
+
origin: mockHostOrigin,
|
|
2890
|
+
data: {
|
|
2891
|
+
type: 'portal:lifi:getRouteStepResult',
|
|
2892
|
+
data: res,
|
|
2893
|
+
},
|
|
2894
|
+
}),
|
|
2895
|
+
)
|
|
2896
|
+
})
|
|
2897
|
+
|
|
2898
|
+
mpc
|
|
2899
|
+
.getLifiRouteStep(args)
|
|
2900
|
+
.then((data) => {
|
|
2901
|
+
expect(data).toEqual(res)
|
|
2902
|
+
done()
|
|
2903
|
+
})
|
|
2904
|
+
.catch((_) => {
|
|
2905
|
+
expect(0).toEqual(1)
|
|
2906
|
+
done()
|
|
2907
|
+
})
|
|
2908
|
+
})
|
|
2909
|
+
|
|
2910
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2911
|
+
jest
|
|
2912
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2913
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2914
|
+
const { type, data } = message
|
|
2915
|
+
|
|
2916
|
+
expect(type).toEqual('portal:lifi:getRouteStep')
|
|
2917
|
+
expect(data).toEqual(args)
|
|
2918
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2919
|
+
|
|
2920
|
+
window.dispatchEvent(
|
|
2921
|
+
new MessageEvent('message', {
|
|
2922
|
+
origin: mockHostOrigin,
|
|
2923
|
+
data: {
|
|
2924
|
+
type: 'portal:lifi:getRouteStepError',
|
|
2925
|
+
data: {
|
|
2926
|
+
code: 1,
|
|
2927
|
+
message: 'test',
|
|
2928
|
+
},
|
|
2929
|
+
},
|
|
2930
|
+
}),
|
|
2931
|
+
)
|
|
2932
|
+
})
|
|
2933
|
+
|
|
2934
|
+
mpc
|
|
2935
|
+
.getLifiRouteStep(args)
|
|
2936
|
+
.then(() => {
|
|
2937
|
+
expect(0).toEqual(1)
|
|
2938
|
+
done()
|
|
2939
|
+
})
|
|
2940
|
+
.catch((e) => {
|
|
2941
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2942
|
+
expect(e.message).toEqual('test')
|
|
2943
|
+
expect(e.code).toEqual(1)
|
|
2944
|
+
done()
|
|
2945
|
+
})
|
|
2946
|
+
})
|
|
2947
|
+
})
|
|
2636
2948
|
})
|
package/src/mpc/index.ts
CHANGED
|
@@ -57,8 +57,18 @@ import {
|
|
|
57
57
|
YieldXyzTrackTransactionRequest,
|
|
58
58
|
YieldXyzTrackTransactionResponse,
|
|
59
59
|
} from '../../yieldxyz-types'
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
import {
|
|
61
|
+
LifiQuoteRequest,
|
|
62
|
+
LifiQuoteResponse,
|
|
63
|
+
LifiRoutesRequest,
|
|
64
|
+
LifiRoutesResponse,
|
|
65
|
+
LifiStatusRequest,
|
|
66
|
+
LifiStatusResponse,
|
|
67
|
+
LifiStepTransactionRequest,
|
|
68
|
+
LifiStepTransactionResponse,
|
|
69
|
+
} from '../../lifi-types'
|
|
70
|
+
|
|
71
|
+
const WEB_SDK_VERSION = '3.6.0-alpha'
|
|
62
72
|
|
|
63
73
|
class Mpc {
|
|
64
74
|
public iframe?: HTMLIFrameElement
|
|
@@ -1296,6 +1306,50 @@ class Mpc {
|
|
|
1296
1306
|
})
|
|
1297
1307
|
}
|
|
1298
1308
|
|
|
1309
|
+
public async getLifiRoutes(
|
|
1310
|
+
data: LifiRoutesRequest,
|
|
1311
|
+
): Promise<LifiRoutesResponse> {
|
|
1312
|
+
return this.handleRequestToIframeAndPost({
|
|
1313
|
+
methodMessage: 'portal:lifi:getRoutes',
|
|
1314
|
+
errorMessage: 'portal:lifi:getRoutesError',
|
|
1315
|
+
resultMessage: 'portal:lifi:getRoutesResult',
|
|
1316
|
+
data,
|
|
1317
|
+
})
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
public async getLifiQuote(
|
|
1321
|
+
data: LifiQuoteRequest,
|
|
1322
|
+
): Promise<LifiQuoteResponse> {
|
|
1323
|
+
return this.handleRequestToIframeAndPost({
|
|
1324
|
+
methodMessage: 'portal:lifi:getQuote',
|
|
1325
|
+
errorMessage: 'portal:lifi:getQuoteError',
|
|
1326
|
+
resultMessage: 'portal:lifi:getQuoteResult',
|
|
1327
|
+
data,
|
|
1328
|
+
})
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
public async getLifiStatus(
|
|
1332
|
+
data: LifiStatusRequest,
|
|
1333
|
+
): Promise<LifiStatusResponse> {
|
|
1334
|
+
return this.handleRequestToIframeAndPost({
|
|
1335
|
+
methodMessage: 'portal:lifi:getStatus',
|
|
1336
|
+
errorMessage: 'portal:lifi:getStatusError',
|
|
1337
|
+
resultMessage: 'portal:lifi:getStatusResult',
|
|
1338
|
+
data,
|
|
1339
|
+
})
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
public async getLifiRouteStep(
|
|
1343
|
+
data: LifiStepTransactionRequest,
|
|
1344
|
+
): Promise<LifiStepTransactionResponse> {
|
|
1345
|
+
return this.handleRequestToIframeAndPost({
|
|
1346
|
+
methodMessage: 'portal:lifi:getRouteStep',
|
|
1347
|
+
errorMessage: 'portal:lifi:getRouteStepError',
|
|
1348
|
+
resultMessage: 'portal:lifi:getRouteStepResult',
|
|
1349
|
+
data,
|
|
1350
|
+
})
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1299
1353
|
/***************************
|
|
1300
1354
|
* Private Methods
|
|
1301
1355
|
***************************/
|
package/tsconfig.json
CHANGED