zh-web-sdk 2.12.0 → 2.12.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/dist/index.d.ts +2 -2
- package/dist/index.js +27 -27
- package/dist/index.js.map +4 -4
- package/dist/redux/reducers/fiat-account-link.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +1 -0
- package/dist/redux/store/index.d.ts +1 -0
- package/dist/styles.d.ts +4 -0
- package/dist/types.d.ts +29 -2
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +22 -15
- package/src/iframe-container/__tests__/AppContainer.test.tsx +35 -31
- package/src/index.tsx +78 -37
- package/src/redux/reducers/fiat-account-link.ts +60 -0
- package/src/redux/reducers/index.ts +2 -0
- package/src/styles.ts +20 -8
- package/src/types.ts +37 -9
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IFiatAccountLinkState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IFiatAccountLinkAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const fiatAccountLinkReducer: (state: IFiatAccountLinkState | undefined, action: IFiatAccountLinkAction) => IFiatAccountLinkState;
|
|
13
|
+
export default fiatAccountLinkReducer;
|
|
@@ -14,5 +14,6 @@ declare const rootReducer: import("redux").Reducer<import("redux").CombinedState
|
|
|
14
14
|
"crypto-account-link-payouts": import("./crypto-account-link-payouts").ICryptoAccountLinkPayoutsState;
|
|
15
15
|
payouts: import("./payouts").IPayoutsState;
|
|
16
16
|
pay: import("./pay").IPayState;
|
|
17
|
+
"fiat-account-link": import("./fiat-account-link").IFiatAccountLinkState;
|
|
17
18
|
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./onboarding").IOnboardingAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
18
19
|
export default rootReducer;
|
|
@@ -16,6 +16,7 @@ declare const store: import("redux").Store<import("redux").EmptyObject & {
|
|
|
16
16
|
"crypto-account-link-payouts": import("../reducers/crypto-account-link-payouts").ICryptoAccountLinkPayoutsState;
|
|
17
17
|
payouts: import("../reducers/payouts").IPayoutsState;
|
|
18
18
|
pay: import("../reducers/pay").IPayState;
|
|
19
|
+
"fiat-account-link": import("../reducers/fiat-account-link").IFiatAccountLinkState;
|
|
19
20
|
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/onboarding").IOnboardingAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
20
21
|
export default store;
|
|
21
22
|
export type RootState = ReturnType<typeof rootReducer>;
|
package/dist/styles.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export declare const screenSizes: {
|
|
|
3
3
|
id: string;
|
|
4
4
|
size: number;
|
|
5
5
|
}[];
|
|
6
|
+
/**
|
|
7
|
+
* When the width is smaller than
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
6
10
|
export declare const minWidthMatcher: () => string;
|
|
7
11
|
export declare const containerStyle: CSSProperties;
|
|
8
12
|
export declare const containerMediaStyles: {
|
package/dist/types.d.ts
CHANGED
|
@@ -109,6 +109,12 @@ export interface IInitializeParameters {
|
|
|
109
109
|
* to perform pay.
|
|
110
110
|
*/
|
|
111
111
|
payJWT?: string;
|
|
112
|
+
/**
|
|
113
|
+
* fiatAccountLinkJWT is the JWT that you received from
|
|
114
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
115
|
+
* create a new Fiat Account.
|
|
116
|
+
*/
|
|
117
|
+
fiatAccountLinkJWT?: string;
|
|
112
118
|
/**
|
|
113
119
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
114
120
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -375,7 +381,27 @@ export declare enum IncomingMessageType {
|
|
|
375
381
|
/**
|
|
376
382
|
* PayFailed is received when the Pay flow has failed.
|
|
377
383
|
*/
|
|
378
|
-
PayFailed = "PAY_FAILED"
|
|
384
|
+
PayFailed = "PAY_FAILED",
|
|
385
|
+
/**
|
|
386
|
+
* FiatAccountLinkAppLoaded is received when the Fiat Account Link
|
|
387
|
+
* app has initialized.
|
|
388
|
+
*/
|
|
389
|
+
FiatAccountLinkAppLoaded = "FIAT_ACCOUNT_LINK_APP_LOADED",
|
|
390
|
+
/**
|
|
391
|
+
* FiatAccountLinkCloseButtonClicked is received when the close button
|
|
392
|
+
* has been clicked in the Fiat Account Link app
|
|
393
|
+
*/
|
|
394
|
+
FiatAccountLinkCloseButtonClicked = "FIAT_ACCOUNT_LINK_CLOSE_BUTTON_CLICKED",
|
|
395
|
+
/**
|
|
396
|
+
* FiatAccountLinkFailed is received when the
|
|
397
|
+
* Fiat Account Link flow has failed.
|
|
398
|
+
*/
|
|
399
|
+
FiatAccountLinkFailed = "FIAT_ACCOUNT_LINK_FAILED",
|
|
400
|
+
/**
|
|
401
|
+
* FiatAccountLinkCompleted is received when the
|
|
402
|
+
* Fiat Account Link flow is completed.
|
|
403
|
+
*/
|
|
404
|
+
FiatAccountLinkCompleted = "FIAT_ACCOUNT_LINK_COMPLETED"
|
|
379
405
|
}
|
|
380
406
|
/**
|
|
381
407
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -422,7 +448,8 @@ export declare enum AppIdentifier {
|
|
|
422
448
|
CRYPTO_ACCOUNT_LINK = "crypto-account-link",
|
|
423
449
|
CRYPTO_ACCOUNT_LINK_PAYOUTS = "crypto-account-link-payouts",
|
|
424
450
|
PAYOUTS = "payouts",
|
|
425
|
-
PAY = "pay"
|
|
451
|
+
PAY = "pay",
|
|
452
|
+
FIAT_ACCOUNT_LINK = "fiat-account-link"
|
|
426
453
|
}
|
|
427
454
|
/**
|
|
428
455
|
* Map that maps the app AppIdentifier to the redux action prefix
|
package/package.json
CHANGED
|
@@ -129,6 +129,12 @@ interface AppContainerMappedProps {
|
|
|
129
129
|
jwt: string;
|
|
130
130
|
filters?: Filters;
|
|
131
131
|
};
|
|
132
|
+
[AppIdentifier.FIAT_ACCOUNT_LINK]: {
|
|
133
|
+
isAppActive: boolean;
|
|
134
|
+
isAppLoaded: boolean;
|
|
135
|
+
jwt: string;
|
|
136
|
+
filters?: Filters;
|
|
137
|
+
};
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
const appLoadTime = Date.now();
|
|
@@ -149,6 +155,7 @@ const mapAppToTitle = {
|
|
|
149
155
|
[AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS]: "Crypto Account Link Payouts",
|
|
150
156
|
[AppIdentifier.PAYOUTS]: "Payouts",
|
|
151
157
|
[AppIdentifier.PAY]: "Pay",
|
|
158
|
+
[AppIdentifier.FIAT_ACCOUNT_LINK]: "Fiat Account Link",
|
|
152
159
|
};
|
|
153
160
|
|
|
154
161
|
const AppContainer = ({
|
|
@@ -192,11 +199,11 @@ const AppContainer = ({
|
|
|
192
199
|
iRef.current?.contentWindow?.postMessage(
|
|
193
200
|
{
|
|
194
201
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
195
|
-
key as AppIdentifier
|
|
202
|
+
key as AppIdentifier
|
|
196
203
|
)}SEND_JWT_TOKEN`,
|
|
197
204
|
jwt: allAppsState[key as AppIdentifier].jwt,
|
|
198
205
|
},
|
|
199
|
-
zeroHashAppURL
|
|
206
|
+
zeroHashAppURL
|
|
200
207
|
);
|
|
201
208
|
|
|
202
209
|
// If the zh-web-sdk is being run inside the WorldApp, we must send the WorldApp object
|
|
@@ -204,7 +211,7 @@ const AppContainer = ({
|
|
|
204
211
|
if (isInsideWorldApp()) {
|
|
205
212
|
iRef.current?.contentWindow?.postMessage(
|
|
206
213
|
{ type: `WORLD_APP_OBJECT`, WorldApp: window.WorldApp },
|
|
207
|
-
zeroHashAppURL
|
|
214
|
+
zeroHashAppURL
|
|
208
215
|
);
|
|
209
216
|
}
|
|
210
217
|
|
|
@@ -213,11 +220,11 @@ const AppContainer = ({
|
|
|
213
220
|
iRef.current?.contentWindow?.postMessage(
|
|
214
221
|
{
|
|
215
222
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
216
|
-
key as AppIdentifier
|
|
223
|
+
key as AppIdentifier
|
|
217
224
|
)}SEND_FILTERS`,
|
|
218
225
|
filters: allAppsState[key as AppIdentifier].filters,
|
|
219
226
|
},
|
|
220
|
-
zeroHashAppURL
|
|
227
|
+
zeroHashAppURL
|
|
221
228
|
);
|
|
222
229
|
}
|
|
223
230
|
// Send navigate to Onboarding App
|
|
@@ -225,11 +232,11 @@ const AppContainer = ({
|
|
|
225
232
|
iRef.current?.contentWindow?.postMessage(
|
|
226
233
|
{
|
|
227
234
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
228
|
-
AppIdentifier.ONBOARDING
|
|
235
|
+
AppIdentifier.ONBOARDING
|
|
229
236
|
)}NAVIGATE`,
|
|
230
237
|
navigate,
|
|
231
238
|
},
|
|
232
|
-
zeroHashAppURL
|
|
239
|
+
zeroHashAppURL
|
|
233
240
|
);
|
|
234
241
|
}
|
|
235
242
|
});
|
|
@@ -274,7 +281,7 @@ const AppContainer = ({
|
|
|
274
281
|
data: event.data,
|
|
275
282
|
},
|
|
276
283
|
},
|
|
277
|
-
zeroHashAppURL
|
|
284
|
+
zeroHashAppURL
|
|
278
285
|
);
|
|
279
286
|
|
|
280
287
|
if (!window.MiniKit) {
|
|
@@ -283,7 +290,7 @@ const AppContainer = ({
|
|
|
283
290
|
type: "MINIKIT_PAY_COMMAND_CANCELED",
|
|
284
291
|
payload: { reason: "window.Minikit not found" },
|
|
285
292
|
},
|
|
286
|
-
zeroHashAppURL
|
|
293
|
+
zeroHashAppURL
|
|
287
294
|
);
|
|
288
295
|
return;
|
|
289
296
|
}
|
|
@@ -299,7 +306,7 @@ const AppContainer = ({
|
|
|
299
306
|
symbol: payload.token as Tokens,
|
|
300
307
|
token_amount: tokenToDecimals(
|
|
301
308
|
Number(payload.amount),
|
|
302
|
-
payload.token
|
|
309
|
+
payload.token
|
|
303
310
|
).toString(),
|
|
304
311
|
},
|
|
305
312
|
],
|
|
@@ -310,14 +317,14 @@ const AppContainer = ({
|
|
|
310
317
|
type: "MINIKIT_PAY_COMMAND_SUBMITTING_PAYMENT",
|
|
311
318
|
payload: { minikitPayload },
|
|
312
319
|
},
|
|
313
|
-
zeroHashAppURL
|
|
320
|
+
zeroHashAppURL
|
|
314
321
|
);
|
|
315
322
|
const { finalPayload } =
|
|
316
323
|
await window.MiniKit.commandsAsync.pay(minikitPayload);
|
|
317
324
|
|
|
318
325
|
iRef.current?.contentWindow?.postMessage(
|
|
319
326
|
{ type: "MINIKIT_PAY_COMMAND_RESULT", payload: { finalPayload } },
|
|
320
|
-
zeroHashAppURL
|
|
327
|
+
zeroHashAppURL
|
|
321
328
|
);
|
|
322
329
|
}
|
|
323
330
|
} catch (error) {
|
|
@@ -326,11 +333,11 @@ const AppContainer = ({
|
|
|
326
333
|
type: "MINIKIT_PAY_COMMAND_ERROR",
|
|
327
334
|
payload: { error, status: "error" },
|
|
328
335
|
},
|
|
329
|
-
zeroHashAppURL
|
|
336
|
+
zeroHashAppURL
|
|
330
337
|
);
|
|
331
338
|
}
|
|
332
339
|
},
|
|
333
|
-
[zeroHashAppURL]
|
|
340
|
+
[zeroHashAppURL]
|
|
334
341
|
);
|
|
335
342
|
|
|
336
343
|
useEffect(() => {
|
|
@@ -379,7 +386,7 @@ const AppContainer = ({
|
|
|
379
386
|
|
|
380
387
|
const mapStateToProps = (
|
|
381
388
|
state: AppContainerMappedProps,
|
|
382
|
-
ownProps: AppContainerProps
|
|
389
|
+
ownProps: AppContainerProps
|
|
383
390
|
) => {
|
|
384
391
|
return {
|
|
385
392
|
isAppActive: state[ownProps.appIdentifier].isAppActive,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {screen} from "@testing-library/react";
|
|
1
|
+
import { screen } from "@testing-library/react";
|
|
2
2
|
import AppContainer from "../AppContainer";
|
|
3
|
-
import {AppIdentifier} from "../../types";
|
|
4
|
-
import {renderWithProviders} from "../../utils/test-utils";
|
|
3
|
+
import { AppIdentifier } from "../../types";
|
|
4
|
+
import { renderWithProviders } from "../../utils/test-utils";
|
|
5
5
|
|
|
6
|
-
describe(
|
|
6
|
+
describe("AppContainer", () => {
|
|
7
7
|
test.each([
|
|
8
8
|
[AppIdentifier.CRYPTO_WITHDRAWALS, "Crypto Withdrawals"],
|
|
9
9
|
[AppIdentifier.FIAT_DEPOSITS, "Fiat Deposits"],
|
|
@@ -19,34 +19,38 @@ describe('AppContainer', () => {
|
|
|
19
19
|
[AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, "Crypto Account Link Payouts"],
|
|
20
20
|
[AppIdentifier.PAYOUTS, "Payouts"],
|
|
21
21
|
[AppIdentifier.PAY, "Pay"],
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
[AppIdentifier.FIAT_ACCOUNT_LINK, "Fiat Account Link"],
|
|
23
|
+
])(
|
|
24
|
+
"should render AppContainer correctly for %s",
|
|
25
|
+
async (appIdentifier, title) => {
|
|
26
|
+
renderWithProviders(
|
|
27
|
+
<AppContainer
|
|
28
|
+
appIdentifier={appIdentifier}
|
|
29
|
+
zeroHashAppURL={"https://testurl.com/"}
|
|
30
|
+
/>,
|
|
31
|
+
{
|
|
32
|
+
preloadedState: {
|
|
33
|
+
[appIdentifier]: {
|
|
34
|
+
isAppActive: true,
|
|
35
|
+
isAppLoaded: true,
|
|
36
|
+
jwt: "jwt",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Expect that a post message event is sent
|
|
40
|
+
);
|
|
41
|
+
// Expect that a post message event is sent
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const iframe = screen.getByTitle(title);
|
|
44
|
+
expect(iframe).toBeDefined();
|
|
45
|
+
expect(iframe.style.width).toBe("100%");
|
|
46
|
+
expect(iframe.style.height).toBe("100%");
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const iframeSrc = new URL(iframe.getAttribute("src") as string);
|
|
49
|
+
expect(iframeSrc.origin).toBe("https://testurl.com");
|
|
50
|
+
expect(iframeSrc.searchParams.get("origin")).toBe("http://localhost");
|
|
51
|
+
expect(screen.getByTitle(title)).toBeDefined();
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
// Verify that postMessage has been called
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
});
|
package/src/index.tsx
CHANGED
|
@@ -19,8 +19,19 @@ import { DEFAULT_ZH_APPS_URL } from "./constants";
|
|
|
19
19
|
import AppContainer from "./iframe-container/AppContainer";
|
|
20
20
|
import { Provider } from "react-redux";
|
|
21
21
|
import store from "./redux/store";
|
|
22
|
-
import {
|
|
23
|
-
|
|
22
|
+
import {
|
|
23
|
+
ACTION_SET_FILTERS,
|
|
24
|
+
ACTION_SET_JWT,
|
|
25
|
+
ACTION_SET_NAVIGATE,
|
|
26
|
+
} from "./redux/reducers/constants";
|
|
27
|
+
import {
|
|
28
|
+
appCompleted,
|
|
29
|
+
appFailed,
|
|
30
|
+
appLoaded,
|
|
31
|
+
appPendingApproval,
|
|
32
|
+
closeModal,
|
|
33
|
+
openModal,
|
|
34
|
+
} from "./redux/actions";
|
|
24
35
|
|
|
25
36
|
let _zeroHashAppsURL: string = DEFAULT_ZH_APPS_URL;
|
|
26
37
|
let _zeroHashAppsOrigin: string = "";
|
|
@@ -139,29 +150,29 @@ const appsMessageHandlers: {
|
|
|
139
150
|
},
|
|
140
151
|
// Crypto Account Link message handlers
|
|
141
152
|
[IncomingMessageType.CryptoAccountLinkAppLoaded]: () => {
|
|
142
|
-
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK)
|
|
153
|
+
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
143
154
|
},
|
|
144
155
|
[IncomingMessageType.CryptoAccountLinkCloseButtonClicked]: () => {
|
|
145
|
-
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK)
|
|
156
|
+
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
146
157
|
},
|
|
147
158
|
[IncomingMessageType.CryptoAccountLinkFailed]: () => {
|
|
148
|
-
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK)
|
|
159
|
+
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
149
160
|
},
|
|
150
161
|
[IncomingMessageType.CryptoAccountLinkCompleted]: () => {
|
|
151
|
-
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK)
|
|
162
|
+
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
152
163
|
},
|
|
153
164
|
// Crypto Account Link Payouts message handlers
|
|
154
165
|
[IncomingMessageType.CryptoAccountLinkPayoutsAppLoaded]: () => {
|
|
155
|
-
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS)
|
|
166
|
+
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
156
167
|
},
|
|
157
168
|
[IncomingMessageType.CryptoAccountLinkPayoutsCloseButtonClicked]: () => {
|
|
158
|
-
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS)
|
|
169
|
+
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
159
170
|
},
|
|
160
171
|
[IncomingMessageType.CryptoAccountLinkPayoutsFailed]: () => {
|
|
161
|
-
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS)
|
|
172
|
+
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
162
173
|
},
|
|
163
174
|
[IncomingMessageType.CryptoAccountLinkPayoutsCompleted]: () => {
|
|
164
|
-
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS)
|
|
175
|
+
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
165
176
|
},
|
|
166
177
|
// Payouts message handlers
|
|
167
178
|
[IncomingMessageType.PayoutsAppLoaded]: () => {
|
|
@@ -189,6 +200,19 @@ const appsMessageHandlers: {
|
|
|
189
200
|
[IncomingMessageType.PayFailed]: () => {
|
|
190
201
|
appFailed(AppIdentifier.PAY);
|
|
191
202
|
},
|
|
203
|
+
// Fiat Account Link message handlers
|
|
204
|
+
[IncomingMessageType.FiatAccountLinkAppLoaded]: () => {
|
|
205
|
+
appLoaded(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
206
|
+
},
|
|
207
|
+
[IncomingMessageType.FiatAccountLinkCloseButtonClicked]: () => {
|
|
208
|
+
closeModal(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
209
|
+
},
|
|
210
|
+
[IncomingMessageType.FiatAccountLinkCompleted]: () => {
|
|
211
|
+
appCompleted(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
212
|
+
},
|
|
213
|
+
[IncomingMessageType.FiatAccountLinkFailed]: () => {
|
|
214
|
+
appFailed(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
215
|
+
},
|
|
192
216
|
};
|
|
193
217
|
|
|
194
218
|
/**
|
|
@@ -233,6 +257,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
233
257
|
[AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, false],
|
|
234
258
|
[AppIdentifier.PAYOUTS, false],
|
|
235
259
|
[AppIdentifier.PAY, false],
|
|
260
|
+
[AppIdentifier.FIAT_ACCOUNT_LINK, false],
|
|
236
261
|
]);
|
|
237
262
|
|
|
238
263
|
/**
|
|
@@ -241,22 +266,23 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
241
266
|
* For more information, see {@code IInitializeParameters}
|
|
242
267
|
*/
|
|
243
268
|
constructor({
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
zeroHashOnboardingURL = DEFAULT_ZH_APPS_URL,
|
|
270
|
+
rootQuerySelector,
|
|
271
|
+
userOnboardingJWT,
|
|
272
|
+
cryptoWithdrawalsJWT,
|
|
273
|
+
fiatDepositsJWT,
|
|
274
|
+
fiatWithdrawalsJWT,
|
|
275
|
+
cryptoBuyJWT,
|
|
276
|
+
cryptoSellJWT,
|
|
277
|
+
fundJWT,
|
|
278
|
+
profileJWT,
|
|
279
|
+
cryptoAccountLinkJWT,
|
|
280
|
+
cryptoAccountLinkPayoutsJWT,
|
|
281
|
+
payoutsJWT,
|
|
282
|
+
payJWT,
|
|
283
|
+
fiatAccountLinkJWT,
|
|
284
|
+
zeroHashAppsURL,
|
|
285
|
+
}: IInitializeParameters) {
|
|
260
286
|
// The || is for backwards compatibility
|
|
261
287
|
_zeroHashAppsURL = zeroHashAppsURL || zeroHashOnboardingURL;
|
|
262
288
|
const onboardingURL = new URL(_zeroHashAppsURL);
|
|
@@ -319,14 +345,14 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
319
345
|
if (cryptoAccountLinkJWT) {
|
|
320
346
|
this.setJWT({
|
|
321
347
|
jwt: cryptoAccountLinkJWT,
|
|
322
|
-
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK
|
|
323
|
-
})
|
|
348
|
+
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK,
|
|
349
|
+
});
|
|
324
350
|
}
|
|
325
351
|
if (cryptoAccountLinkPayoutsJWT) {
|
|
326
352
|
this.setJWT({
|
|
327
353
|
jwt: cryptoAccountLinkPayoutsJWT,
|
|
328
|
-
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS
|
|
329
|
-
})
|
|
354
|
+
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS,
|
|
355
|
+
});
|
|
330
356
|
}
|
|
331
357
|
if (payoutsJWT) {
|
|
332
358
|
this.setJWT({
|
|
@@ -340,6 +366,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
340
366
|
appIdentifier: AppIdentifier.PAY,
|
|
341
367
|
});
|
|
342
368
|
}
|
|
369
|
+
if (fiatAccountLinkJWT) {
|
|
370
|
+
this.setJWT({
|
|
371
|
+
jwt: fiatAccountLinkJWT,
|
|
372
|
+
appIdentifier: AppIdentifier.FIAT_ACCOUNT_LINK,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
343
375
|
}
|
|
344
376
|
|
|
345
377
|
/**
|
|
@@ -357,14 +389,18 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
357
389
|
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_JWT, { jwt });
|
|
358
390
|
}
|
|
359
391
|
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
360
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, {
|
|
392
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, {
|
|
393
|
+
filters,
|
|
394
|
+
});
|
|
361
395
|
}
|
|
362
396
|
/**
|
|
363
|
-
* Sets the navigate field for the appIdentifier provided. Currently this is
|
|
397
|
+
* Sets the navigate field for the appIdentifier provided. Currently this is
|
|
364
398
|
* specific to Onboarding and is used to navigate to a specific page within the App.
|
|
365
399
|
*/
|
|
366
400
|
setNavigate({ appIdentifier, navigate }: ISetNavigateParameters): void {
|
|
367
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_NAVIGATE, {
|
|
401
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_NAVIGATE, {
|
|
402
|
+
navigate,
|
|
403
|
+
});
|
|
368
404
|
}
|
|
369
405
|
/**
|
|
370
406
|
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
@@ -412,12 +448,17 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
412
448
|
/**
|
|
413
449
|
* openModal opens the modal for the appIdentifier provided.
|
|
414
450
|
*/
|
|
415
|
-
openModal({
|
|
451
|
+
openModal({
|
|
452
|
+
jwt,
|
|
453
|
+
appIdentifier,
|
|
454
|
+
filters,
|
|
455
|
+
navigate,
|
|
456
|
+
}: IOpenModalParameters): void {
|
|
416
457
|
if (filters) {
|
|
417
|
-
this.setFilters({filters, appIdentifier})
|
|
458
|
+
this.setFilters({ filters, appIdentifier });
|
|
418
459
|
}
|
|
419
460
|
if (navigate) {
|
|
420
|
-
this.setNavigate({ appIdentifier, navigate })
|
|
461
|
+
this.setNavigate({ appIdentifier, navigate });
|
|
421
462
|
}
|
|
422
463
|
if (jwt) {
|
|
423
464
|
this.setJWT({
|
|
@@ -459,7 +500,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
459
500
|
const shadowRoot = root.attachShadow({ mode: "closed" });
|
|
460
501
|
|
|
461
502
|
// Render the React modal
|
|
462
|
-
const urlWithIdentifier = new URL(appIdentifier, _zeroHashAppsURL).href
|
|
503
|
+
const urlWithIdentifier = new URL(appIdentifier, _zeroHashAppsURL).href;
|
|
463
504
|
ReactDOM.createRoot(shadowRoot).render(
|
|
464
505
|
<Provider store={store}>
|
|
465
506
|
<AppContainer
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AppIdentifier, appIdentifierToActionPrefixMap } from "../../types";
|
|
2
|
+
import { ACTION_APP_LOADED, ACTION_SET_JWT, ACTION_SET_MODAL_STATE } from "./constants";
|
|
3
|
+
|
|
4
|
+
export interface IFiatAccountLinkState {
|
|
5
|
+
jwt: string;
|
|
6
|
+
isAppLoaded: boolean;
|
|
7
|
+
isAppActive: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IFiatAccountLinkAction {
|
|
11
|
+
type: string;
|
|
12
|
+
jwt?: string;
|
|
13
|
+
isAppActive?: boolean;
|
|
14
|
+
isAppLoaded?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const INITIAL_STATE: IFiatAccountLinkState = {
|
|
18
|
+
jwt: "",
|
|
19
|
+
isAppActive: false,
|
|
20
|
+
isAppLoaded: false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const applySetIsAppActive = (state: IFiatAccountLinkState, action: IFiatAccountLinkAction): IFiatAccountLinkState => {
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
isAppActive: !!action.isAppActive,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const applySetSendJWTToApp = (state: IFiatAccountLinkState, action: IFiatAccountLinkAction): IFiatAccountLinkState => {
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const applySetJWT = (state: IFiatAccountLinkState, action: IFiatAccountLinkAction): IFiatAccountLinkState => {
|
|
38
|
+
return {
|
|
39
|
+
...state,
|
|
40
|
+
jwt: action.jwt as string,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const reducerMap: {
|
|
45
|
+
[actionType: string]: (state: IFiatAccountLinkState, action: IFiatAccountLinkAction) => IFiatAccountLinkState
|
|
46
|
+
} = {
|
|
47
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_ACCOUNT_LINK)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
48
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_ACCOUNT_LINK)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
49
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_ACCOUNT_LINK)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const fiatAccountLinkReducer = (state = INITIAL_STATE, action: IFiatAccountLinkAction) => {
|
|
53
|
+
if (!!action.type && !!reducerMap[action.type]) {
|
|
54
|
+
return reducerMap[action.type](state, action);
|
|
55
|
+
} else {
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default fiatAccountLinkReducer;
|
|
@@ -11,6 +11,7 @@ import cryptoAccountLinkReducer from "./crypto-account-link";
|
|
|
11
11
|
import cryptoAccountLinkPayoutsReducer from "./crypto-account-link-payouts";
|
|
12
12
|
import payoutsReducer from "./payouts";
|
|
13
13
|
import payReducer from "./pay";
|
|
14
|
+
import fiatAccountLinkReducer from "./fiat-account-link";
|
|
14
15
|
|
|
15
16
|
const rootReducer = combineReducers({
|
|
16
17
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
@@ -28,6 +29,7 @@ const rootReducer = combineReducers({
|
|
|
28
29
|
["crypto-account-link-payouts"]: cryptoAccountLinkPayoutsReducer,
|
|
29
30
|
["payouts"]: payoutsReducer,
|
|
30
31
|
["pay"]: payReducer,
|
|
32
|
+
["fiat-account-link"]: fiatAccountLinkReducer,
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
export default rootReducer;
|
package/src/styles.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { CSSProperties } from "react";
|
|
2
2
|
|
|
3
|
-
const MTE_SM =
|
|
3
|
+
const MTE_SM = 480;
|
|
4
|
+
const MTE_MD = 720;
|
|
5
|
+
const modalBorderRadius = 24
|
|
4
6
|
|
|
5
7
|
export const screenSizes: { id: string, size: number }[] = [
|
|
6
8
|
{
|
|
7
9
|
id: "MTE_SM",
|
|
8
10
|
size: MTE_SM,
|
|
9
|
-
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "MTE_MD",
|
|
14
|
+
size: MTE_MD,
|
|
15
|
+
},
|
|
10
16
|
]
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* When the width is smaller than
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
12
22
|
export const minWidthMatcher = (): string => {
|
|
13
23
|
for (let i = 0; i < screenSizes.length; i++) {
|
|
14
24
|
const { id, size } = screenSizes[i];
|
|
@@ -24,18 +34,20 @@ export const containerStyle: CSSProperties = {
|
|
|
24
34
|
paddingLeft: 0,
|
|
25
35
|
marginRight: "auto",
|
|
26
36
|
marginLeft: "auto",
|
|
27
|
-
maxHeight:
|
|
37
|
+
maxHeight: 812
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
export const containerMediaStyles: { [id: string]: CSSProperties } = {
|
|
31
41
|
MTE_SM: {
|
|
32
|
-
width:
|
|
42
|
+
width: 480
|
|
43
|
+
},
|
|
44
|
+
MTE_MD: {
|
|
45
|
+
width: 720
|
|
33
46
|
},
|
|
34
47
|
ANY: {
|
|
35
48
|
width: "100%",
|
|
36
49
|
height: "100%",
|
|
37
50
|
maxWidth: "100%",
|
|
38
|
-
borderRadius: 0,
|
|
39
51
|
maxHeight: "100%"
|
|
40
52
|
},
|
|
41
53
|
}
|
|
@@ -51,15 +63,15 @@ export const appWrapperStyle: CSSProperties = {
|
|
|
51
63
|
height: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
|
|
52
64
|
maxHeight: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
|
|
53
65
|
background: "rgba(0,0,0,0.5)",
|
|
54
|
-
cursor: "pointer"
|
|
66
|
+
cursor: "pointer"
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
export const modalStyle: CSSProperties = {
|
|
58
70
|
padding: 0,
|
|
59
|
-
borderRadius: 5,
|
|
60
71
|
backgroundColor: "#FFF",
|
|
61
72
|
height: "calc(100% - 100px)",
|
|
62
73
|
maxWidth: "calc(100% - 30px)",
|
|
74
|
+
borderRadius: modalBorderRadius
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
export const iframeWrapperStyle: CSSProperties = {
|
|
@@ -76,5 +88,5 @@ export const iframeStyle: CSSProperties = {
|
|
|
76
88
|
margin: 0,
|
|
77
89
|
padding: 0,
|
|
78
90
|
overflow: "hidden",
|
|
79
|
-
borderRadius:
|
|
91
|
+
borderRadius: modalBorderRadius
|
|
80
92
|
};
|