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
package/src/index.tsx
DELETED
|
@@ -1,645 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import ReactDOM from "react-dom/client";
|
|
3
|
-
import {
|
|
4
|
-
AppIdentifier,
|
|
5
|
-
IInitializeParameters,
|
|
6
|
-
IncomingMessage,
|
|
7
|
-
IncomingMessageHandler,
|
|
8
|
-
IncomingMessageType,
|
|
9
|
-
IOpenModalParameters,
|
|
10
|
-
IOpenOnboardingModalParameters,
|
|
11
|
-
ISetFiltersParameters,
|
|
12
|
-
ISetJWTParameters,
|
|
13
|
-
ISetNavigateParameters,
|
|
14
|
-
ISetUserOnboardingJWTParameters,
|
|
15
|
-
IZeroHashSDK,
|
|
16
|
-
} from "./types";
|
|
17
|
-
import { dispatchActionBasedOnAppIdentifier, generateRootID } from "./utils";
|
|
18
|
-
import { DEFAULT_ZH_APPS_URL } from "./constants";
|
|
19
|
-
import AppContainer from "./iframe-container/AppContainer";
|
|
20
|
-
import { Provider } from "react-redux";
|
|
21
|
-
import store from "./redux/store";
|
|
22
|
-
import { decodeJWT } from "./api/convert-token";
|
|
23
|
-
import {
|
|
24
|
-
ACTION_SET_FILTERS,
|
|
25
|
-
ACTION_SET_JWT,
|
|
26
|
-
ACTION_SET_NAVIGATE,
|
|
27
|
-
ACTION_SET_USE_AUTH,
|
|
28
|
-
} from "./redux/reducers/constants";
|
|
29
|
-
import {
|
|
30
|
-
appCompleted,
|
|
31
|
-
appFailed,
|
|
32
|
-
appLoaded,
|
|
33
|
-
appPendingApproval,
|
|
34
|
-
closeModal,
|
|
35
|
-
openModal,
|
|
36
|
-
} from "./redux/actions";
|
|
37
|
-
|
|
38
|
-
let _zeroHashAppsURL: string = DEFAULT_ZH_APPS_URL;
|
|
39
|
-
let _zeroHashAppsOrigin: string = "";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* appsMessageHandlers are the message handlers that
|
|
43
|
-
* handle incoming messages from app's iframes.
|
|
44
|
-
* @private - not meant to be invoked publicly
|
|
45
|
-
*/
|
|
46
|
-
const appsMessageHandlers: {
|
|
47
|
-
[messageType in IncomingMessageType]: IncomingMessageHandler;
|
|
48
|
-
} = {
|
|
49
|
-
// Onboarding message handlers
|
|
50
|
-
[IncomingMessageType.OnboardingAppLoaded]: () => {
|
|
51
|
-
appLoaded(AppIdentifier.ONBOARDING);
|
|
52
|
-
},
|
|
53
|
-
[IncomingMessageType.OnboardingCloseButtonClicked]: () => {
|
|
54
|
-
closeModal(AppIdentifier.ONBOARDING);
|
|
55
|
-
},
|
|
56
|
-
[IncomingMessageType.OnboardingPendingApproval]: () => {
|
|
57
|
-
appPendingApproval(AppIdentifier.ONBOARDING);
|
|
58
|
-
},
|
|
59
|
-
[IncomingMessageType.OnboardingCompleted]: () => {
|
|
60
|
-
appCompleted(AppIdentifier.ONBOARDING);
|
|
61
|
-
},
|
|
62
|
-
[IncomingMessageType.OnboardingFailed]: () => {
|
|
63
|
-
appFailed(AppIdentifier.ONBOARDING);
|
|
64
|
-
},
|
|
65
|
-
// Crypto Withdrawals message handlers
|
|
66
|
-
[IncomingMessageType.CryptoWithdrawalsCloseButtonClicked]: () => {
|
|
67
|
-
closeModal(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
68
|
-
},
|
|
69
|
-
[IncomingMessageType.CryptoWithdrawalsAppLoaded]: () => {
|
|
70
|
-
appLoaded(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
71
|
-
},
|
|
72
|
-
[IncomingMessageType.CryptoWithdrawalsCompleted]: () => {
|
|
73
|
-
appCompleted(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
74
|
-
},
|
|
75
|
-
[IncomingMessageType.CryptoWithdrawalsFailed]: () => {
|
|
76
|
-
appFailed(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
77
|
-
},
|
|
78
|
-
// Fiat Deposits message handlers
|
|
79
|
-
[IncomingMessageType.FiatDepositsCloseButtonClicked]: () => {
|
|
80
|
-
closeModal(AppIdentifier.FIAT_DEPOSITS);
|
|
81
|
-
},
|
|
82
|
-
[IncomingMessageType.FiatDepositsAppLoaded]: () => {
|
|
83
|
-
appLoaded(AppIdentifier.FIAT_DEPOSITS);
|
|
84
|
-
},
|
|
85
|
-
[IncomingMessageType.FiatDepositsCompleted]: () => {
|
|
86
|
-
appCompleted(AppIdentifier.FIAT_DEPOSITS);
|
|
87
|
-
},
|
|
88
|
-
[IncomingMessageType.FiatDepositsFailed]: () => {
|
|
89
|
-
appFailed(AppIdentifier.FIAT_DEPOSITS);
|
|
90
|
-
},
|
|
91
|
-
// Fiat Withdrawals message handlers
|
|
92
|
-
[IncomingMessageType.FiatWithdrawalsCloseButtonClicked]: () => {
|
|
93
|
-
closeModal(AppIdentifier.FIAT_WITHDRAWALS);
|
|
94
|
-
},
|
|
95
|
-
[IncomingMessageType.FiatWithdrawalsAppLoaded]: () => {
|
|
96
|
-
appLoaded(AppIdentifier.FIAT_WITHDRAWALS);
|
|
97
|
-
},
|
|
98
|
-
[IncomingMessageType.FiatWithdrawalsCompleted]: () => {
|
|
99
|
-
appCompleted(AppIdentifier.FIAT_WITHDRAWALS);
|
|
100
|
-
},
|
|
101
|
-
[IncomingMessageType.FiatWithdrawalsFailed]: () => {
|
|
102
|
-
appFailed(AppIdentifier.FIAT_WITHDRAWALS);
|
|
103
|
-
},
|
|
104
|
-
// Crypto buy message handlers
|
|
105
|
-
[IncomingMessageType.CryptoBuyCloseButtonClicked]: () => {
|
|
106
|
-
closeModal(AppIdentifier.CRYPTO_BUY);
|
|
107
|
-
},
|
|
108
|
-
[IncomingMessageType.CryptoBuyAppLoaded]: () => {
|
|
109
|
-
appLoaded(AppIdentifier.CRYPTO_BUY);
|
|
110
|
-
},
|
|
111
|
-
[IncomingMessageType.CryptoBuyCompleted]: () => {
|
|
112
|
-
appCompleted(AppIdentifier.CRYPTO_BUY);
|
|
113
|
-
},
|
|
114
|
-
[IncomingMessageType.CryptoBuyFailed]: () => {
|
|
115
|
-
appFailed(AppIdentifier.CRYPTO_BUY);
|
|
116
|
-
},
|
|
117
|
-
// Crypto sell message handlers
|
|
118
|
-
[IncomingMessageType.CryptoSellCloseButtonClicked]: () => {
|
|
119
|
-
closeModal(AppIdentifier.CRYPTO_SELL);
|
|
120
|
-
},
|
|
121
|
-
[IncomingMessageType.CryptoSellAppLoaded]: () => {
|
|
122
|
-
appLoaded(AppIdentifier.CRYPTO_SELL);
|
|
123
|
-
},
|
|
124
|
-
[IncomingMessageType.CryptoSellCompleted]: () => {
|
|
125
|
-
appCompleted(AppIdentifier.CRYPTO_SELL);
|
|
126
|
-
},
|
|
127
|
-
[IncomingMessageType.CryptoSellFailed]: () => {
|
|
128
|
-
appFailed(AppIdentifier.CRYPTO_SELL);
|
|
129
|
-
},
|
|
130
|
-
// Fund message handlers
|
|
131
|
-
[IncomingMessageType.FundAppLoaded]: () => {
|
|
132
|
-
appLoaded(AppIdentifier.FUND);
|
|
133
|
-
},
|
|
134
|
-
[IncomingMessageType.FundCloseButtonClicked]: () => {
|
|
135
|
-
closeModal(AppIdentifier.FUND);
|
|
136
|
-
},
|
|
137
|
-
[IncomingMessageType.FundCompleted]: () => {
|
|
138
|
-
appCompleted(AppIdentifier.FUND);
|
|
139
|
-
},
|
|
140
|
-
[IncomingMessageType.FundFailed]: () => {
|
|
141
|
-
appFailed(AppIdentifier.FUND);
|
|
142
|
-
},
|
|
143
|
-
[IncomingMessageType.FundError]: () => {
|
|
144
|
-
appFailed(AppIdentifier.FUND);
|
|
145
|
-
},
|
|
146
|
-
[IncomingMessageType.FundDepositSubmitted]: () => {
|
|
147
|
-
appCompleted(AppIdentifier.FUND);
|
|
148
|
-
},
|
|
149
|
-
[IncomingMessageType.FundConnectDeposit]: () => {
|
|
150
|
-
// Handler for Connect-specific deposit event
|
|
151
|
-
appCompleted(AppIdentifier.FUND);
|
|
152
|
-
},
|
|
153
|
-
[IncomingMessageType.FundConnectEvent]: () => {
|
|
154
|
-
// Handler for catch-all Connect Auth events
|
|
155
|
-
// No specific action needed
|
|
156
|
-
},
|
|
157
|
-
// Profile message handlers
|
|
158
|
-
[IncomingMessageType.ProfileAppLoaded]: () => {
|
|
159
|
-
appLoaded(AppIdentifier.PROFILE);
|
|
160
|
-
},
|
|
161
|
-
[IncomingMessageType.ProfileCloseButtonClicked]: () => {
|
|
162
|
-
closeModal(AppIdentifier.PROFILE);
|
|
163
|
-
},
|
|
164
|
-
[IncomingMessageType.ProfileFailed]: () => {
|
|
165
|
-
appFailed(AppIdentifier.PROFILE);
|
|
166
|
-
},
|
|
167
|
-
// Crypto Account Link message handlers
|
|
168
|
-
[IncomingMessageType.CryptoAccountLinkAppLoaded]: () => {
|
|
169
|
-
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
170
|
-
},
|
|
171
|
-
[IncomingMessageType.CryptoAccountLinkCloseButtonClicked]: () => {
|
|
172
|
-
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
173
|
-
},
|
|
174
|
-
[IncomingMessageType.CryptoAccountLinkFailed]: () => {
|
|
175
|
-
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
176
|
-
},
|
|
177
|
-
[IncomingMessageType.CryptoAccountLinkCompleted]: () => {
|
|
178
|
-
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK);
|
|
179
|
-
},
|
|
180
|
-
// Crypto Account Link Payouts message handlers
|
|
181
|
-
[IncomingMessageType.CryptoAccountLinkPayoutsAppLoaded]: () => {
|
|
182
|
-
appLoaded(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
183
|
-
},
|
|
184
|
-
[IncomingMessageType.CryptoAccountLinkPayoutsCloseButtonClicked]: () => {
|
|
185
|
-
closeModal(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
186
|
-
},
|
|
187
|
-
[IncomingMessageType.CryptoAccountLinkPayoutsFailed]: () => {
|
|
188
|
-
appFailed(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
189
|
-
},
|
|
190
|
-
[IncomingMessageType.CryptoAccountLinkPayoutsCompleted]: () => {
|
|
191
|
-
appCompleted(AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS);
|
|
192
|
-
},
|
|
193
|
-
// Payouts message handlers
|
|
194
|
-
[IncomingMessageType.PayoutsAppLoaded]: () => {
|
|
195
|
-
appLoaded(AppIdentifier.PAYOUTS);
|
|
196
|
-
},
|
|
197
|
-
[IncomingMessageType.PayoutsCloseButtonClicked]: () => {
|
|
198
|
-
closeModal(AppIdentifier.PAYOUTS);
|
|
199
|
-
},
|
|
200
|
-
[IncomingMessageType.PayoutsCompleted]: () => {
|
|
201
|
-
appCompleted(AppIdentifier.PAYOUTS);
|
|
202
|
-
},
|
|
203
|
-
[IncomingMessageType.PayoutsFailed]: () => {
|
|
204
|
-
appFailed(AppIdentifier.PAYOUTS);
|
|
205
|
-
},
|
|
206
|
-
// Pay message handlers
|
|
207
|
-
[IncomingMessageType.PayAppLoaded]: () => {
|
|
208
|
-
appLoaded(AppIdentifier.PAY);
|
|
209
|
-
},
|
|
210
|
-
[IncomingMessageType.PayCloseButtonClicked]: () => {
|
|
211
|
-
closeModal(AppIdentifier.PAY);
|
|
212
|
-
},
|
|
213
|
-
[IncomingMessageType.PayCompleted]: () => {
|
|
214
|
-
appCompleted(AppIdentifier.PAY);
|
|
215
|
-
},
|
|
216
|
-
[IncomingMessageType.PayFailed]: () => {
|
|
217
|
-
appFailed(AppIdentifier.PAY);
|
|
218
|
-
},
|
|
219
|
-
// Fiat Account Link message handlers
|
|
220
|
-
[IncomingMessageType.FiatAccountLinkAppLoaded]: () => {
|
|
221
|
-
appLoaded(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
222
|
-
},
|
|
223
|
-
[IncomingMessageType.FiatAccountLinkCloseButtonClicked]: () => {
|
|
224
|
-
closeModal(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
225
|
-
},
|
|
226
|
-
[IncomingMessageType.FiatAccountLinkCompleted]: () => {
|
|
227
|
-
appCompleted(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
228
|
-
},
|
|
229
|
-
[IncomingMessageType.FiatAccountLinkFailed]: () => {
|
|
230
|
-
appFailed(AppIdentifier.FIAT_ACCOUNT_LINK);
|
|
231
|
-
},
|
|
232
|
-
// StyleConfig is handled by the AppContainer component via postMessage
|
|
233
|
-
[IncomingMessageType.StyleConfig]: () => {
|
|
234
|
-
// No action needed - styles are applied directly in AppContainer
|
|
235
|
-
},
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* messageRouter routes the message to the appropriate message handler based on the host
|
|
240
|
-
* @private - not meant to be invoked publicly
|
|
241
|
-
*/
|
|
242
|
-
const messageRouter = (event: MessageEvent): void => {
|
|
243
|
-
const isSameOrigin = window.location.origin === event.origin;
|
|
244
|
-
const isZeroHashOrigin = event.origin === _zeroHashAppsOrigin;
|
|
245
|
-
|
|
246
|
-
// Check if Fund is using Auth (for same-origin messages)
|
|
247
|
-
const useAuth = store.getState().fund?.useAuth || false;
|
|
248
|
-
|
|
249
|
-
// Accept messages from iframe (_zeroHashAppsOrigin) OR from Auth component (same origin + useAuth enabled)
|
|
250
|
-
if (isZeroHashOrigin || (isSameOrigin && useAuth)) {
|
|
251
|
-
const incomingMessage: IncomingMessage = event.data;
|
|
252
|
-
if (
|
|
253
|
-
incomingMessage &&
|
|
254
|
-
incomingMessage.type &&
|
|
255
|
-
appsMessageHandlers[incomingMessage.type]
|
|
256
|
-
) {
|
|
257
|
-
try {
|
|
258
|
-
appsMessageHandlers[incomingMessage.type](incomingMessage.payload);
|
|
259
|
-
} catch (e) {
|
|
260
|
-
console.error(e);
|
|
261
|
-
// TODO: emit event that informs the platform of failure event, to inform ZH of bug
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
export class ZeroHashSDK implements IZeroHashSDK {
|
|
268
|
-
private rootQuerySelector: string = "";
|
|
269
|
-
private onboardingInitialized: boolean = false;
|
|
270
|
-
/**
|
|
271
|
-
* initializedApps is a map that keeps track of which apps have been initialized.
|
|
272
|
-
* This might grow as we start supporting new apps.
|
|
273
|
-
*/
|
|
274
|
-
private initializedApps: Map<AppIdentifier, boolean> = new Map([
|
|
275
|
-
[AppIdentifier.CRYPTO_WITHDRAWALS, false],
|
|
276
|
-
[AppIdentifier.ONBOARDING, false],
|
|
277
|
-
[AppIdentifier.FIAT_DEPOSITS, false],
|
|
278
|
-
[AppIdentifier.FIAT_WITHDRAWALS, false],
|
|
279
|
-
[AppIdentifier.CRYPTO_BUY, false],
|
|
280
|
-
[AppIdentifier.CRYPTO_SELL, false],
|
|
281
|
-
[AppIdentifier.FUND, false],
|
|
282
|
-
[AppIdentifier.PROFILE, false],
|
|
283
|
-
[AppIdentifier.CRYPTO_ACCOUNT_LINK, false],
|
|
284
|
-
[AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, false],
|
|
285
|
-
[AppIdentifier.PAYOUTS, false],
|
|
286
|
-
[AppIdentifier.PAY, false],
|
|
287
|
-
[AppIdentifier.FIAT_ACCOUNT_LINK, false],
|
|
288
|
-
]);
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Sets up the ZeroHash SDK and appends the ZeroHash DOM elements onto the page.
|
|
292
|
-
*
|
|
293
|
-
* For more information, see {@code IInitializeParameters}
|
|
294
|
-
*/
|
|
295
|
-
constructor({
|
|
296
|
-
zeroHashOnboardingURL = DEFAULT_ZH_APPS_URL,
|
|
297
|
-
rootQuerySelector,
|
|
298
|
-
userOnboardingJWT,
|
|
299
|
-
cryptoWithdrawalsJWT,
|
|
300
|
-
fiatDepositsJWT,
|
|
301
|
-
fiatWithdrawalsJWT,
|
|
302
|
-
cryptoBuyJWT,
|
|
303
|
-
cryptoSellJWT,
|
|
304
|
-
fundJWT,
|
|
305
|
-
profileJWT,
|
|
306
|
-
cryptoAccountLinkJWT,
|
|
307
|
-
cryptoAccountLinkPayoutsJWT,
|
|
308
|
-
payoutsJWT,
|
|
309
|
-
payJWT,
|
|
310
|
-
fiatAccountLinkJWT,
|
|
311
|
-
zeroHashAppsURL,
|
|
312
|
-
}: IInitializeParameters) {
|
|
313
|
-
// The || is for backwards compatibility
|
|
314
|
-
_zeroHashAppsURL = zeroHashAppsURL || zeroHashOnboardingURL;
|
|
315
|
-
const onboardingURL = new URL(_zeroHashAppsURL);
|
|
316
|
-
_zeroHashAppsOrigin = onboardingURL.origin;
|
|
317
|
-
if (rootQuerySelector) {
|
|
318
|
-
this.rootQuerySelector = rootQuerySelector as string;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// register message handler
|
|
322
|
-
window.addEventListener("message", messageRouter, false);
|
|
323
|
-
|
|
324
|
-
if (userOnboardingJWT) {
|
|
325
|
-
this.setJWT({
|
|
326
|
-
jwt: userOnboardingJWT,
|
|
327
|
-
appIdentifier: AppIdentifier.ONBOARDING,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
if (cryptoWithdrawalsJWT) {
|
|
331
|
-
this.setJWT({
|
|
332
|
-
jwt: cryptoWithdrawalsJWT,
|
|
333
|
-
appIdentifier: AppIdentifier.CRYPTO_WITHDRAWALS,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
if (fiatDepositsJWT) {
|
|
337
|
-
this.setJWT({
|
|
338
|
-
jwt: fiatDepositsJWT,
|
|
339
|
-
appIdentifier: AppIdentifier.FIAT_DEPOSITS,
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
if (fiatWithdrawalsJWT) {
|
|
343
|
-
this.setJWT({
|
|
344
|
-
jwt: fiatWithdrawalsJWT,
|
|
345
|
-
appIdentifier: AppIdentifier.FIAT_WITHDRAWALS,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
if (cryptoBuyJWT) {
|
|
349
|
-
this.setJWT({
|
|
350
|
-
jwt: cryptoBuyJWT,
|
|
351
|
-
appIdentifier: AppIdentifier.CRYPTO_BUY,
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
if (cryptoSellJWT) {
|
|
355
|
-
this.setJWT({
|
|
356
|
-
jwt: cryptoSellJWT,
|
|
357
|
-
appIdentifier: AppIdentifier.CRYPTO_SELL,
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
if (fundJWT) {
|
|
361
|
-
this.setJWT({
|
|
362
|
-
jwt: fundJWT,
|
|
363
|
-
appIdentifier: AppIdentifier.FUND,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
if (profileJWT) {
|
|
367
|
-
this.setJWT({
|
|
368
|
-
jwt: profileJWT,
|
|
369
|
-
appIdentifier: AppIdentifier.PROFILE,
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
if (cryptoAccountLinkJWT) {
|
|
373
|
-
this.setJWT({
|
|
374
|
-
jwt: cryptoAccountLinkJWT,
|
|
375
|
-
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK,
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
if (cryptoAccountLinkPayoutsJWT) {
|
|
379
|
-
this.setJWT({
|
|
380
|
-
jwt: cryptoAccountLinkPayoutsJWT,
|
|
381
|
-
appIdentifier: AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
if (payoutsJWT) {
|
|
385
|
-
this.setJWT({
|
|
386
|
-
jwt: payoutsJWT,
|
|
387
|
-
appIdentifier: AppIdentifier.PAYOUTS,
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
if (payJWT) {
|
|
391
|
-
this.setJWT({
|
|
392
|
-
jwt: payJWT,
|
|
393
|
-
appIdentifier: AppIdentifier.PAY,
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
if (fiatAccountLinkJWT) {
|
|
397
|
-
this.setJWT({
|
|
398
|
-
jwt: fiatAccountLinkJWT,
|
|
399
|
-
appIdentifier: AppIdentifier.FIAT_ACCOUNT_LINK,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* setJWT sets the JWT for the appIdentifier provided.
|
|
406
|
-
* The JWT should be the JWT provided by ZeroHash via the platform
|
|
407
|
-
* API proxied through your servers. As ZeroHash cannot authenticate
|
|
408
|
-
* your users' requests, it is paramount that the user be authenticated
|
|
409
|
-
* and validated on your servers, and exchanged for the JWT using your
|
|
410
|
-
* API key. DO NOT have the JWT exchange logic be on your front-end.
|
|
411
|
-
*
|
|
412
|
-
* As a precaution, we may restrict traffic to the JWT exchange API to
|
|
413
|
-
* whitelisted IPs that come from your server.
|
|
414
|
-
*/
|
|
415
|
-
setJWT({ jwt, appIdentifier }: ISetJWTParameters): void {
|
|
416
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_JWT, { jwt });
|
|
417
|
-
}
|
|
418
|
-
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
419
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, {
|
|
420
|
-
filters,
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Sets the navigate field for the appIdentifier provided. Currently this is
|
|
425
|
-
* specific to Onboarding and is used to navigate to a specific page within the App.
|
|
426
|
-
*/
|
|
427
|
-
setNavigate({ appIdentifier, navigate }: ISetNavigateParameters): void {
|
|
428
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_NAVIGATE, {
|
|
429
|
-
navigate,
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
434
|
-
* The JWT should be the UserJWT provided by ZeroHash via the platform
|
|
435
|
-
* API proxied through your servers. As ZeroHash cannot authenticate
|
|
436
|
-
* your users' requests, it is paramount that the user be authenticated
|
|
437
|
-
* and validated on your servers, and exchanged for the JWT using your
|
|
438
|
-
* API key. DO NOT have the JWT exchange logic be on your front-end.
|
|
439
|
-
*
|
|
440
|
-
* As a precaution, we may restrict traffic to the JWT exchange API to
|
|
441
|
-
* whitelisted IPs that come from your server.
|
|
442
|
-
* @deprecated in favor of setJWT({jwt: <userOnboardingJWT>, appIdentifier: "onboarding"})
|
|
443
|
-
*/
|
|
444
|
-
setUserOnboardingJWT(params: ISetUserOnboardingJWTParameters): void {
|
|
445
|
-
this.setJWT({
|
|
446
|
-
jwt: params.userOnboardingJWT,
|
|
447
|
-
appIdentifier: AppIdentifier.ONBOARDING,
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* isOnboardingModalOpen returns true if the onboarding modal is open,
|
|
453
|
-
* false otherwise
|
|
454
|
-
* @deprecated in favor of isModalOpen("onboarding")
|
|
455
|
-
*/
|
|
456
|
-
isOnboardingModalOpen(): boolean {
|
|
457
|
-
return store.getState().onboarding.isAppActive;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* isModalOpen returns true if the modal is open,
|
|
462
|
-
* for the appIdentifier provided, false otherwise
|
|
463
|
-
*/
|
|
464
|
-
isModalOpen(appIdentifier: AppIdentifier): boolean {
|
|
465
|
-
return store.getState()[appIdentifier].isAppActive;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* closeModal hides the modal for the appIdentifier provided.
|
|
470
|
-
*/
|
|
471
|
-
closeModal(appIdentifier: AppIdentifier): void {
|
|
472
|
-
closeModal(appIdentifier);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* openModal opens the modal for the appIdentifier provided.
|
|
477
|
-
*/
|
|
478
|
-
openModal({
|
|
479
|
-
jwt,
|
|
480
|
-
appIdentifier,
|
|
481
|
-
filters,
|
|
482
|
-
navigate,
|
|
483
|
-
}: IOpenModalParameters): void {
|
|
484
|
-
if (filters) {
|
|
485
|
-
this.setFilters({ filters, appIdentifier });
|
|
486
|
-
}
|
|
487
|
-
if (navigate) {
|
|
488
|
-
this.setNavigate({ appIdentifier, navigate });
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Check if we should use Auth based on JWT issuer
|
|
492
|
-
let useAuth = false;
|
|
493
|
-
|
|
494
|
-
if (jwt) {
|
|
495
|
-
const payload = decodeJWT(jwt);
|
|
496
|
-
|
|
497
|
-
// If JWT has 'iss' field containing 'connect', use Auth instead of iframe
|
|
498
|
-
if (payload && payload.iss && typeof payload.iss === 'string' && payload.iss.includes('connect')) {
|
|
499
|
-
useAuth = true;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
if (jwt) {
|
|
504
|
-
this.setJWT({
|
|
505
|
-
jwt,
|
|
506
|
-
appIdentifier,
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
if (appIdentifier === AppIdentifier.FUND) {
|
|
510
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_USE_AUTH, { useAuth });
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
openModal(appIdentifier);
|
|
514
|
-
if (this.initializedApps.get(appIdentifier)) {
|
|
515
|
-
// if the App was previously initialized already,
|
|
516
|
-
// simply open the modal, do not re-inject.
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
let root: HTMLElement | null = null;
|
|
521
|
-
if (this.rootQuerySelector) {
|
|
522
|
-
root = document.querySelector(this.rootQuerySelector);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// Previously this was if (!root) {...}
|
|
526
|
-
if (!this.initializedApps.get(appIdentifier)) {
|
|
527
|
-
// Create the default ZeroHash div, e.g. <div id="zerohash-<APP_IDENTIFIER>-49vt8y"/>
|
|
528
|
-
root = document.createElement("div");
|
|
529
|
-
const rootID = generateRootID(appIdentifier);
|
|
530
|
-
root.id = rootID;
|
|
531
|
-
root.style.position = "absolute";
|
|
532
|
-
root.style.top = "0";
|
|
533
|
-
root.style.left = "0";
|
|
534
|
-
this.rootQuerySelector = `#${rootID}`;
|
|
535
|
-
|
|
536
|
-
// Append the ZeroHash div as a child of <body>
|
|
537
|
-
const destinationBox = document.querySelector("body") as HTMLBodyElement;
|
|
538
|
-
destinationBox.appendChild(root);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (root) {
|
|
542
|
-
// Create a shadow wrapper around ZeroHash app for encapsulation
|
|
543
|
-
const shadowRoot = root.attachShadow({ mode: "closed" });
|
|
544
|
-
|
|
545
|
-
// Render the React modal
|
|
546
|
-
const urlWithIdentifier = new URL(appIdentifier, _zeroHashAppsURL).href;
|
|
547
|
-
ReactDOM.createRoot(shadowRoot).render(
|
|
548
|
-
<Provider store={store}>
|
|
549
|
-
<AppContainer
|
|
550
|
-
appIdentifier={appIdentifier}
|
|
551
|
-
zeroHashAppURL={urlWithIdentifier}
|
|
552
|
-
useAuth={useAuth}
|
|
553
|
-
/>
|
|
554
|
-
</Provider>
|
|
555
|
-
);
|
|
556
|
-
|
|
557
|
-
// set as initialized
|
|
558
|
-
this.initializedApps.set(appIdentifier, true);
|
|
559
|
-
} else {
|
|
560
|
-
const errMsg =
|
|
561
|
-
"failed to append ZeroHash root to the page: root not found";
|
|
562
|
-
console.error(errMsg);
|
|
563
|
-
throw new Error(errMsg);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* openOnboardingModal opens the onboarding modal
|
|
569
|
-
* @deprecated in favor of openModal({appIdentifier: "onboarding", jwt: <userOnboardingJWT>})
|
|
570
|
-
*/
|
|
571
|
-
openOnboardingModal(params: IOpenOnboardingModalParameters): void {
|
|
572
|
-
if (params.userOnboardingJWT) {
|
|
573
|
-
this.setUserOnboardingJWT({
|
|
574
|
-
userOnboardingJWT: params.userOnboardingJWT,
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
openModal(AppIdentifier.ONBOARDING);
|
|
578
|
-
if (this.onboardingInitialized) {
|
|
579
|
-
// if it was previously initialized already,
|
|
580
|
-
// simply open the modal, do not re-inject.
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
let root: HTMLElement | null = null;
|
|
584
|
-
if (this.rootQuerySelector) {
|
|
585
|
-
root = document.querySelector(this.rootQuerySelector);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
if (!root) {
|
|
589
|
-
// Create the default ZeroHash div, e.g. <div id="zerohash-49vt8y"/>
|
|
590
|
-
root = document.createElement("div");
|
|
591
|
-
const rootID = generateRootID();
|
|
592
|
-
root.id = rootID;
|
|
593
|
-
root.style.position = "absolute";
|
|
594
|
-
root.style.top = "0";
|
|
595
|
-
root.style.left = "0";
|
|
596
|
-
this.rootQuerySelector = `#${rootID}`;
|
|
597
|
-
|
|
598
|
-
// Append the ZeroHash div as a child of <body>
|
|
599
|
-
const destinationBox = document.querySelector("body") as HTMLBodyElement;
|
|
600
|
-
destinationBox.appendChild(root);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
if (root) {
|
|
604
|
-
// Create a shadow wrapper around ZeroHash app for encapsulation
|
|
605
|
-
const shadowRoot = root.attachShadow({ mode: "closed" });
|
|
606
|
-
|
|
607
|
-
// Render the React modal
|
|
608
|
-
ReactDOM.createRoot(shadowRoot).render(
|
|
609
|
-
<Provider store={store}>
|
|
610
|
-
<AppContainer
|
|
611
|
-
appIdentifier={AppIdentifier.ONBOARDING}
|
|
612
|
-
zeroHashAppURL={_zeroHashAppsURL}
|
|
613
|
-
/>
|
|
614
|
-
</Provider>
|
|
615
|
-
);
|
|
616
|
-
|
|
617
|
-
// set as initialized
|
|
618
|
-
this.onboardingInitialized = true;
|
|
619
|
-
} else {
|
|
620
|
-
const errMsg =
|
|
621
|
-
"failed to append ZeroHash root to the page: root not found";
|
|
622
|
-
console.error(errMsg);
|
|
623
|
-
throw new Error(errMsg);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
/**
|
|
628
|
-
* closeOnboardingModalModal hides the onboarding modal
|
|
629
|
-
* @deprecated in favor of closeModal("onboarding")
|
|
630
|
-
*/
|
|
631
|
-
closeOnboardingModal(): void {
|
|
632
|
-
closeModal(AppIdentifier.ONBOARDING);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
if (window) {
|
|
637
|
-
// if the window object exists, the ZeroHash SDK
|
|
638
|
-
// constructor will be appended to it for easier
|
|
639
|
-
// access.
|
|
640
|
-
window.zerohash = ZeroHashSDK;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
export default ZeroHashSDK;
|
|
644
|
-
|
|
645
|
-
export * from "./types";
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ACTION_APP_LOADED, ACTION_COMPLETED, ACTION_FAILED, ACTION_PENDING_APPROVAL, ACTION_SET_MODAL_STATE } from "../reducers/constants";
|
|
2
|
-
import { AppIdentifier } from "../../types";
|
|
3
|
-
import { dispatchActionBasedOnAppIdentifier } from "../../utils";
|
|
4
|
-
|
|
5
|
-
export const openModal = (appIdentifier: AppIdentifier) => {
|
|
6
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_MODAL_STATE, { isAppActive: true })
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const closeModal = (appIdentifier: AppIdentifier) => {
|
|
10
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_MODAL_STATE, { isAppActive: false })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const appLoaded = (appIdentifier: AppIdentifier) => {
|
|
14
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_APP_LOADED, { isAppLoaded: true })
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const appPendingApproval = (appIdentifier: AppIdentifier) => {
|
|
18
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_PENDING_APPROVAL, {})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const appCompleted = (appIdentifier: AppIdentifier) => {
|
|
22
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_COMPLETED, {})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const appFailed = (appIdentifier: AppIdentifier) => {
|
|
26
|
-
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_FAILED, {})
|
|
27
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Generic action suffixes
|
|
2
|
-
export const ACTION_SET_MODAL_STATE = "SET_MODAL_STATE"
|
|
3
|
-
export const ACTION_SET_JWT = "SET_JWT"
|
|
4
|
-
export const ACTION_APP_LOADED = "APP_LOADED"
|
|
5
|
-
export const ACTION_PENDING_APPROVAL = "PENDING_APPROVAL"
|
|
6
|
-
export const ACTION_COMPLETED = "COMPLETED"
|
|
7
|
-
export const ACTION_FAILED = "FAILED"
|
|
8
|
-
export const ACTION_SET_FILTERS = "ACTION_SET_FILTERS"
|
|
9
|
-
export const ACTION_SET_NAVIGATE = "SET_NAVIGATE"
|
|
10
|
-
export const ACTION_SET_USE_AUTH = "SET_USE_AUTH"
|