zh-web-sdk 2.16.1 → 2.17.0
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/README.md +225 -32
- package/package.json +6 -1
- package/.eslintrc.js +0 -12
- package/.github/CHANGELOG_TEMPLATE.md +0 -73
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
- package/.github/backup/publish-tag.yaml +0 -14
- package/.github/workflows/build.yaml +0 -13
- package/.github/workflows/pr.yaml +0 -14
- package/.github/workflows/publish.yaml +0 -13
- package/.github/workflows/security.yml +0 -15
- package/.github/workflows/tag.yaml +0 -14
- package/RELEASING.md +0 -39
- package/jest.config.js +0 -8
- package/jest.setup.js +0 -24
- package/scripts/build.js +0 -34
- package/scripts/zip.js +0 -49
- package/src/__tests__/jwt-auth-detection.test.ts +0 -96
- package/src/api/convert-token.ts +0 -23
- package/src/constants.ts +0 -2
- package/src/hooks/__tests__/use-window-size.test.tsx +0 -26
- package/src/hooks/use-window-size.ts +0 -19
- package/src/iframe-container/AppContainer.tsx +0 -495
- package/src/iframe-container/__tests__/AppContainer.test.tsx +0 -300
- package/src/iframe-container/hooks/__tests__/use-style-updates.test.ts +0 -430
- package/src/iframe-container/hooks/use-style-updates.ts +0 -82
- package/src/index.tsx +0 -645
- package/src/redux/actions/index.ts +0 -27
- package/src/redux/reducers/constants.ts +0 -10
- package/src/redux/reducers/crypto-account-link-payouts.ts +0 -60
- package/src/redux/reducers/crypto-account-link.ts +0 -60
- package/src/redux/reducers/crypto-buy.ts +0 -75
- package/src/redux/reducers/crypto-sell.ts +0 -64
- package/src/redux/reducers/crypto-withdrawals.ts +0 -64
- package/src/redux/reducers/fiat-account-link.ts +0 -60
- package/src/redux/reducers/fiat-deposits.ts +0 -64
- package/src/redux/reducers/fiat-withdrawals.ts +0 -64
- package/src/redux/reducers/fund.ts +0 -75
- package/src/redux/reducers/index.ts +0 -35
- package/src/redux/reducers/onboarding.ts +0 -74
- package/src/redux/reducers/pay.ts +0 -64
- package/src/redux/reducers/payouts.ts +0 -64
- package/src/redux/reducers/profile.ts +0 -63
- package/src/redux/store/index.ts +0 -10
- package/src/styles.ts +0 -108
- package/src/types.ts +0 -578
- package/src/utils/auth-to-fund-mapper.ts +0 -174
- package/src/utils/strings.ts +0 -19
- package/src/utils/test-utils.tsx +0 -36
- package/src/utils/world-app-utils.ts +0 -8
- package/src/utils.ts +0 -27
- package/tsconfig.json +0 -26
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { screen, waitFor } from "@testing-library/react";
|
|
3
|
-
import AppContainer from "../AppContainer";
|
|
4
|
-
import { AppIdentifier } from "../../types";
|
|
5
|
-
import { renderWithProviders } from "../../utils/test-utils";
|
|
6
|
-
|
|
7
|
-
// Mock @connect-xyz/auth-react
|
|
8
|
-
jest.mock("@connect-xyz/auth-react", () => ({
|
|
9
|
-
Auth: () => React.createElement("div", { "data-testid": "auth-component" }, "Auth Component"),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
// Mock auth-to-fund-mapper
|
|
13
|
-
jest.mock("../../utils/auth-to-fund-mapper", () => ({
|
|
14
|
-
createAuthToFundCallbacks: () => ({
|
|
15
|
-
onLoaded: jest.fn(),
|
|
16
|
-
onClose: jest.fn(),
|
|
17
|
-
onDeposit: jest.fn(),
|
|
18
|
-
onError: jest.fn(),
|
|
19
|
-
onEvent: jest.fn(),
|
|
20
|
-
}),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
describe("AppContainer", () => {
|
|
24
|
-
test.each([
|
|
25
|
-
[AppIdentifier.CRYPTO_WITHDRAWALS, "Crypto Withdrawals"],
|
|
26
|
-
[AppIdentifier.FIAT_DEPOSITS, "Fiat Deposits"],
|
|
27
|
-
[AppIdentifier.FIAT_WITHDRAWALS, "Fiat Withdrawals"],
|
|
28
|
-
[AppIdentifier.CRYPTO_BUY, "Crypto Buy"],
|
|
29
|
-
[AppIdentifier.CRYPTO_SELL, "Crypto Sell"],
|
|
30
|
-
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS, "CBP Crypto Withdrawals"],
|
|
31
|
-
[AppIdentifier.CSP_FIAT_WITHDRAWALS, "CBP Fiat Withdrawals"],
|
|
32
|
-
[AppIdentifier.CSP_CRYPTO_SELL, "Crypto Sell"],
|
|
33
|
-
[AppIdentifier.FUND, "Fund"],
|
|
34
|
-
[AppIdentifier.PROFILE, "Profile"],
|
|
35
|
-
[AppIdentifier.CRYPTO_ACCOUNT_LINK, "Crypto Account Link"],
|
|
36
|
-
[AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, "Crypto Account Link Payouts"],
|
|
37
|
-
[AppIdentifier.PAYOUTS, "Payouts"],
|
|
38
|
-
[AppIdentifier.PAY, "Pay"],
|
|
39
|
-
[AppIdentifier.FIAT_ACCOUNT_LINK, "Fiat Account Link"],
|
|
40
|
-
])(
|
|
41
|
-
"should render AppContainer correctly for %s",
|
|
42
|
-
async (appIdentifier, title) => {
|
|
43
|
-
renderWithProviders(
|
|
44
|
-
<AppContainer
|
|
45
|
-
appIdentifier={appIdentifier}
|
|
46
|
-
zeroHashAppURL={"https://testurl.com/"}
|
|
47
|
-
/>,
|
|
48
|
-
{
|
|
49
|
-
preloadedState: {
|
|
50
|
-
[appIdentifier]: {
|
|
51
|
-
isAppActive: true,
|
|
52
|
-
isAppLoaded: true,
|
|
53
|
-
jwt: "jwt",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
// Trigger STYLE_CONFIG to load the iframe
|
|
60
|
-
const event = new MessageEvent("message", {
|
|
61
|
-
data: {
|
|
62
|
-
type: "STYLE_CONFIG",
|
|
63
|
-
modalStyle: { padding: 0, backgroundColor: "#FFF" },
|
|
64
|
-
appWrapperStyle: {},
|
|
65
|
-
iframeWrapperStyle: {},
|
|
66
|
-
iframeStyle: { width: "100%", height: "100%", border: "none", margin: 0, padding: 0, overflow: "hidden" },
|
|
67
|
-
},
|
|
68
|
-
origin: "https://testurl.com",
|
|
69
|
-
});
|
|
70
|
-
window.dispatchEvent(event);
|
|
71
|
-
|
|
72
|
-
// Wait for iframe to appear after styles are loaded
|
|
73
|
-
await waitFor(() => {
|
|
74
|
-
const iframe = screen.getByTitle(title);
|
|
75
|
-
expect(iframe).toBeDefined();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const iframe = screen.getByTitle(title);
|
|
79
|
-
expect(iframe.style.width).toBe("100%");
|
|
80
|
-
expect(iframe.style.height).toBe("100%");
|
|
81
|
-
|
|
82
|
-
const iframeSrc = new URL(iframe.getAttribute("src") as string);
|
|
83
|
-
expect(iframeSrc.origin).toBe("https://testurl.com");
|
|
84
|
-
expect(iframeSrc.searchParams.get("origin")).toBe("http://localhost");
|
|
85
|
-
expect(screen.getByTitle(title)).toBeDefined();
|
|
86
|
-
|
|
87
|
-
// Verify that postMessage has been called
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
describe("Fund App - useAuth toggle", () => {
|
|
92
|
-
it("should render iframe when useAuth is false", () => {
|
|
93
|
-
renderWithProviders(
|
|
94
|
-
<AppContainer
|
|
95
|
-
appIdentifier={AppIdentifier.FUND}
|
|
96
|
-
zeroHashAppURL="https://testurl.com/"
|
|
97
|
-
/>,
|
|
98
|
-
{
|
|
99
|
-
preloadedState: {
|
|
100
|
-
fund: {
|
|
101
|
-
isAppActive: true,
|
|
102
|
-
isAppLoaded: true,
|
|
103
|
-
jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6ZXJvaGFzaCJ9.test",
|
|
104
|
-
useAuth: false,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const iframe = screen.getByTitle("Fund");
|
|
111
|
-
expect(iframe).toBeDefined();
|
|
112
|
-
expect(iframe.tagName).toBe("IFRAME");
|
|
113
|
-
|
|
114
|
-
expect(screen.queryByTestId("auth-component")).toBeNull();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should render Auth component when useAuth is true", () => {
|
|
118
|
-
renderWithProviders(
|
|
119
|
-
<AppContainer
|
|
120
|
-
appIdentifier={AppIdentifier.FUND}
|
|
121
|
-
zeroHashAppURL="https://testurl.com/"
|
|
122
|
-
/>,
|
|
123
|
-
{
|
|
124
|
-
preloadedState: {
|
|
125
|
-
fund: {
|
|
126
|
-
isAppActive: true,
|
|
127
|
-
isAppLoaded: true,
|
|
128
|
-
jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2Nvbm5lY3QteHl6LnVzLmF1dGgwLmNvbS8ifQ.test",
|
|
129
|
-
useAuth: true,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const authComponent = screen.getByTestId("auth-component");
|
|
136
|
-
expect(authComponent).toBeDefined();
|
|
137
|
-
expect(authComponent.textContent).toBe("Auth Component");
|
|
138
|
-
|
|
139
|
-
expect(screen.queryByTitle("Fund")).toBeNull();
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("Dynamic Styling via postMessage", () => {
|
|
144
|
-
it("should apply styles from STYLE_CONFIG postMessage event", async () => {
|
|
145
|
-
renderWithProviders(
|
|
146
|
-
<AppContainer
|
|
147
|
-
appIdentifier={AppIdentifier.CRYPTO_WITHDRAWALS}
|
|
148
|
-
zeroHashAppURL="https://testurl.com/"
|
|
149
|
-
/>,
|
|
150
|
-
{
|
|
151
|
-
preloadedState: {
|
|
152
|
-
["crypto-withdrawals"]: {
|
|
153
|
-
isAppActive: true,
|
|
154
|
-
isAppLoaded: true,
|
|
155
|
-
jwt: "jwt",
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
}
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
// Send STYLE_CONFIG postMessage with custom styles using the correct origin
|
|
162
|
-
const event = new MessageEvent("message", {
|
|
163
|
-
data: {
|
|
164
|
-
type: "STYLE_CONFIG",
|
|
165
|
-
modalStyle: {
|
|
166
|
-
padding: "20px",
|
|
167
|
-
backgroundColor: "#000",
|
|
168
|
-
height: "calc(100% - 50px)",
|
|
169
|
-
maxWidth: "calc(100% - 60px)",
|
|
170
|
-
},
|
|
171
|
-
appWrapperStyle: { zIndex: 9999 },
|
|
172
|
-
iframeWrapperStyle: { overflow: "visible" },
|
|
173
|
-
iframeStyle: { borderRadius: "8px" },
|
|
174
|
-
},
|
|
175
|
-
origin: "https://testurl.com",
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
window.dispatchEvent(event);
|
|
179
|
-
|
|
180
|
-
// Wait for iframe to appear and styles to be applied
|
|
181
|
-
await waitFor(() => {
|
|
182
|
-
const iframe = screen.getByTitle("Crypto Withdrawals");
|
|
183
|
-
expect(iframe).toBeDefined();
|
|
184
|
-
expect(iframe.style.borderRadius).toBe("8px");
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("should reject STYLE_CONFIG event from mismatched origin", async () => {
|
|
189
|
-
renderWithProviders(
|
|
190
|
-
<AppContainer
|
|
191
|
-
appIdentifier={AppIdentifier.CRYPTO_WITHDRAWALS}
|
|
192
|
-
zeroHashAppURL="https://testurl.com/"
|
|
193
|
-
/>,
|
|
194
|
-
{
|
|
195
|
-
preloadedState: {
|
|
196
|
-
["crypto-withdrawals"]: {
|
|
197
|
-
isAppActive: true,
|
|
198
|
-
isAppLoaded: true,
|
|
199
|
-
jwt: "jwt",
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
}
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
const iframe = screen.getByTitle("Crypto Withdrawals");
|
|
206
|
-
const initialBorderRadius = iframe.style.borderRadius;
|
|
207
|
-
|
|
208
|
-
// Send STYLE_CONFIG from wrong origin
|
|
209
|
-
const event = new MessageEvent("message", {
|
|
210
|
-
data: {
|
|
211
|
-
type: "STYLE_CONFIG",
|
|
212
|
-
modalStyle: { backgroundColor: "#000" },
|
|
213
|
-
appWrapperStyle: {},
|
|
214
|
-
iframeWrapperStyle: {},
|
|
215
|
-
iframeStyle: { borderRadius: "16px" },
|
|
216
|
-
},
|
|
217
|
-
origin: "https://untrusted.com",
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
window.dispatchEvent(event);
|
|
221
|
-
|
|
222
|
-
// Verify styles from untrusted origin were not applied (should keep initial value)
|
|
223
|
-
expect(iframe.style.borderRadius).toBe(initialBorderRadius);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("should update iframe styles when STYLE_CONFIG event is received", async () => {
|
|
227
|
-
renderWithProviders(
|
|
228
|
-
<AppContainer
|
|
229
|
-
appIdentifier={AppIdentifier.CRYPTO_WITHDRAWALS}
|
|
230
|
-
zeroHashAppURL="https://testurl.com/"
|
|
231
|
-
/>,
|
|
232
|
-
{
|
|
233
|
-
preloadedState: {
|
|
234
|
-
["crypto-withdrawals"]: {
|
|
235
|
-
isAppActive: true,
|
|
236
|
-
isAppLoaded: true,
|
|
237
|
-
jwt: "jwt",
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
const iframe = screen.getByTitle("Crypto Withdrawals");
|
|
244
|
-
|
|
245
|
-
// Send STYLE_CONFIG with borderRadius
|
|
246
|
-
const event = new MessageEvent("message", {
|
|
247
|
-
data: {
|
|
248
|
-
type: "STYLE_CONFIG",
|
|
249
|
-
iframeStyle: {
|
|
250
|
-
width: "100%",
|
|
251
|
-
height: "100%",
|
|
252
|
-
border: "none",
|
|
253
|
-
margin: 0,
|
|
254
|
-
padding: 0,
|
|
255
|
-
overflow: "hidden",
|
|
256
|
-
borderRadius: "16px",
|
|
257
|
-
},
|
|
258
|
-
modalStyle: { padding: 0, backgroundColor: "#FFF" },
|
|
259
|
-
appWrapperStyle: {},
|
|
260
|
-
iframeWrapperStyle: {},
|
|
261
|
-
},
|
|
262
|
-
origin: "https://testurl.com",
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
window.dispatchEvent(event);
|
|
266
|
-
|
|
267
|
-
// Wait for borderRadius to be applied
|
|
268
|
-
await waitFor(() => {
|
|
269
|
-
expect(iframe.style.borderRadius).toBe("16px");
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it("should initialize state with default styles from styles.ts", () => {
|
|
274
|
-
renderWithProviders(
|
|
275
|
-
<AppContainer
|
|
276
|
-
appIdentifier={AppIdentifier.CRYPTO_WITHDRAWALS}
|
|
277
|
-
zeroHashAppURL="https://testurl.com/"
|
|
278
|
-
/>,
|
|
279
|
-
{
|
|
280
|
-
preloadedState: {
|
|
281
|
-
["crypto-withdrawals"]: {
|
|
282
|
-
isAppActive: true,
|
|
283
|
-
isAppLoaded: true,
|
|
284
|
-
jwt: "jwt",
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
}
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const wrapperDiv = screen.getByTitle("Crypto Withdrawals").closest("div")?.parentElement?.parentElement;
|
|
291
|
-
|
|
292
|
-
// Verify wrapper has default appWrapperStyle applied
|
|
293
|
-
if (wrapperDiv) {
|
|
294
|
-
expect(wrapperDiv.style.position).toBe("fixed");
|
|
295
|
-
expect(wrapperDiv.style.zIndex).toBe("999999");
|
|
296
|
-
expect(wrapperDiv.style.display).toBe("flex");
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|