zh-web-sdk 2.7.3 → 2.8.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/dist/iframe-container/AppContainer.d.ts +4 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +7 -7
- package/dist/index.js.map +3 -3
- package/dist/redux/reducers/constants.d.ts +1 -0
- package/dist/redux/reducers/index.d.ts +1 -1
- package/dist/redux/reducers/onboarding.d.ts +3 -0
- package/dist/redux/store/index.d.ts +1 -1
- package/dist/types.d.ts +17 -0
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +34 -3
- package/src/index.tsx +13 -3
- package/src/redux/reducers/constants.ts +2 -1
- package/src/redux/reducers/onboarding.ts +12 -2
- package/src/types.ts +297 -279
|
@@ -5,3 +5,4 @@ export declare const ACTION_PENDING_APPROVAL = "PENDING_APPROVAL";
|
|
|
5
5
|
export declare const ACTION_COMPLETED = "COMPLETED";
|
|
6
6
|
export declare const ACTION_FAILED = "FAILED";
|
|
7
7
|
export declare const ACTION_SET_FILTERS = "ACTION_SET_FILTERS";
|
|
8
|
+
export declare const ACTION_SET_NAVIGATE = "SET_NAVIGATE";
|
|
@@ -9,5 +9,5 @@ declare const rootReducer: import("redux").Reducer<import("redux").CombinedState
|
|
|
9
9
|
"csp-fiat-withdrawals": import("./fiat-withdrawals").IFiatWithdrawalsState;
|
|
10
10
|
"csp-crypto-sell": import("./crypto-sell").ICryptoSellState;
|
|
11
11
|
fund: import("./fund").IFundState;
|
|
12
|
-
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
12
|
+
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./onboarding").IOnboardingAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
13
13
|
export default rootReducer;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { OnboardingPage } from "../../types";
|
|
1
2
|
export interface IOnboardingState {
|
|
2
3
|
jwt: string;
|
|
3
4
|
isAppLoaded: boolean;
|
|
4
5
|
isAppActive: boolean;
|
|
6
|
+
navigate?: OnboardingPage;
|
|
5
7
|
}
|
|
6
8
|
export interface IOnboardingAction {
|
|
7
9
|
type: string;
|
|
8
10
|
jwt?: string;
|
|
9
11
|
isAppActive?: boolean;
|
|
10
12
|
isAppLoaded?: boolean;
|
|
13
|
+
navigate?: OnboardingPage;
|
|
11
14
|
}
|
|
12
15
|
declare const onboardingReducer: (state: IOnboardingState | undefined, action: IOnboardingAction) => IOnboardingState;
|
|
13
16
|
export default onboardingReducer;
|
|
@@ -9,5 +9,5 @@ declare const store: import("redux").Store<import("redux").EmptyObject & {
|
|
|
9
9
|
"csp-fiat-withdrawals": import("../reducers/fiat-withdrawals").IFiatWithdrawalsState;
|
|
10
10
|
"csp-crypto-sell": import("../reducers/crypto-sell").ICryptoSellState;
|
|
11
11
|
fund: import("../reducers/fund").IFundState;
|
|
12
|
-
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
12
|
+
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/onboarding").IOnboardingAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
13
13
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -311,8 +311,25 @@ export interface IOpenModalParameters {
|
|
|
311
311
|
jwt?: string;
|
|
312
312
|
appIdentifier: AppIdentifier;
|
|
313
313
|
filters?: Filters;
|
|
314
|
+
navigate?: Page;
|
|
314
315
|
}
|
|
315
316
|
export interface ISetFiltersParameters {
|
|
316
317
|
appIdentifier: AppIdentifier;
|
|
317
318
|
filters?: Filters;
|
|
318
319
|
}
|
|
320
|
+
export interface EditAddress {
|
|
321
|
+
to: "edit-address";
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Since we may extend this in the future, we use a union type to make it easy
|
|
325
|
+
* to allow for example a new CryptoBuyPage type to be added in the future or
|
|
326
|
+
* new pages for the Onboarding App with specialized props.
|
|
327
|
+
* Page is expected to be a union of "AppPage" and each App shall have it's own
|
|
328
|
+
* union of pages, such as EditAddress.
|
|
329
|
+
*/
|
|
330
|
+
export type OnboardingPage = EditAddress;
|
|
331
|
+
export type Page = OnboardingPage;
|
|
332
|
+
export interface ISetNavigateParameters {
|
|
333
|
+
appIdentifier: AppIdentifier;
|
|
334
|
+
navigate: Page;
|
|
335
|
+
}
|
package/package.json
CHANGED
|
@@ -16,6 +16,8 @@ import { closeModal } from "../redux/actions";
|
|
|
16
16
|
import {
|
|
17
17
|
AppIdentifier,
|
|
18
18
|
Filters,
|
|
19
|
+
OnboardingPage,
|
|
20
|
+
Page,
|
|
19
21
|
appIdentifierToActionPrefixMap,
|
|
20
22
|
} from "../types";
|
|
21
23
|
|
|
@@ -26,6 +28,7 @@ interface AppContainerProps {
|
|
|
26
28
|
zeroHashAppURL: string;
|
|
27
29
|
appIdentifier: AppIdentifier;
|
|
28
30
|
filters?: Filters;
|
|
31
|
+
navigate?: Page;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
interface AppContainerMappedProps {
|
|
@@ -40,6 +43,7 @@ interface AppContainerMappedProps {
|
|
|
40
43
|
isAppLoaded: boolean;
|
|
41
44
|
jwt: string;
|
|
42
45
|
filters?: Filters;
|
|
46
|
+
navigate?: OnboardingPage;
|
|
43
47
|
};
|
|
44
48
|
[AppIdentifier.FIAT_DEPOSITS]: {
|
|
45
49
|
isAppActive: boolean;
|
|
@@ -112,6 +116,7 @@ const AppContainer = ({
|
|
|
112
116
|
jwt,
|
|
113
117
|
zeroHashAppURL,
|
|
114
118
|
appIdentifier,
|
|
119
|
+
navigate,
|
|
115
120
|
}: AppContainerProps) => {
|
|
116
121
|
const title = mapAppToTitle[appIdentifier];
|
|
117
122
|
const hasJwt = !!jwt;
|
|
@@ -133,17 +138,18 @@ const AppContainer = ({
|
|
|
133
138
|
const iRef: React.MutableRefObject<HTMLIFrameElement | null> =
|
|
134
139
|
useRef<HTMLIFrameElement | null>(null);
|
|
135
140
|
useEffect(() => {
|
|
136
|
-
// Send
|
|
141
|
+
// Send events to the iframe when Apps are ready
|
|
137
142
|
if (
|
|
138
143
|
zeroHashAppURL &&
|
|
139
144
|
isAppLoaded &&
|
|
140
145
|
hasJwt &&
|
|
141
146
|
iRef.current?.contentWindow
|
|
142
147
|
) {
|
|
143
|
-
// This loops all registered apps and
|
|
148
|
+
// This loops all registered apps and send events listed below.
|
|
144
149
|
Object.keys(allAppsState).forEach((key: string) => {
|
|
145
150
|
if (!allAppsState[key as AppIdentifier].jwt) return;
|
|
146
151
|
|
|
152
|
+
// Send JWT token
|
|
147
153
|
iRef.current?.contentWindow?.postMessage(
|
|
148
154
|
{
|
|
149
155
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
@@ -153,6 +159,7 @@ const AppContainer = ({
|
|
|
153
159
|
},
|
|
154
160
|
zeroHashAppURL
|
|
155
161
|
);
|
|
162
|
+
// Send filters
|
|
156
163
|
if (allAppsState[key as AppIdentifier].filters) {
|
|
157
164
|
iRef.current?.contentWindow?.postMessage(
|
|
158
165
|
{
|
|
@@ -164,9 +171,29 @@ const AppContainer = ({
|
|
|
164
171
|
zeroHashAppURL
|
|
165
172
|
);
|
|
166
173
|
}
|
|
174
|
+
// Send navigate to Onboarding App
|
|
175
|
+
if (appIdentifier === AppIdentifier.ONBOARDING && navigate) {
|
|
176
|
+
iRef.current?.contentWindow?.postMessage(
|
|
177
|
+
{
|
|
178
|
+
type: `${appIdentifierToActionPrefixMap.get(
|
|
179
|
+
AppIdentifier.ONBOARDING
|
|
180
|
+
)}NAVIGATE`,
|
|
181
|
+
navigate,
|
|
182
|
+
},
|
|
183
|
+
zeroHashAppURL
|
|
184
|
+
);
|
|
185
|
+
}
|
|
167
186
|
});
|
|
168
187
|
}
|
|
169
|
-
}, [
|
|
188
|
+
}, [
|
|
189
|
+
appIdentifier,
|
|
190
|
+
hasJwt,
|
|
191
|
+
isAppLoaded,
|
|
192
|
+
jwt,
|
|
193
|
+
zeroHashAppURL,
|
|
194
|
+
allAppsState,
|
|
195
|
+
navigate,
|
|
196
|
+
]);
|
|
170
197
|
|
|
171
198
|
useEffect(() => {
|
|
172
199
|
// set the styles when the screen size changes
|
|
@@ -236,6 +263,10 @@ const mapStateToProps = (
|
|
|
236
263
|
isAppLoaded: state[ownProps.appIdentifier].isAppLoaded,
|
|
237
264
|
jwt: state[ownProps.appIdentifier].jwt,
|
|
238
265
|
filters: state[ownProps.appIdentifier].filters,
|
|
266
|
+
navigate:
|
|
267
|
+
ownProps.appIdentifier === AppIdentifier.ONBOARDING
|
|
268
|
+
? state[ownProps.appIdentifier].navigate
|
|
269
|
+
: undefined,
|
|
239
270
|
};
|
|
240
271
|
};
|
|
241
272
|
|
package/src/index.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
IOpenOnboardingModalParameters,
|
|
11
11
|
ISetFiltersParameters,
|
|
12
12
|
ISetJWTParameters,
|
|
13
|
+
ISetNavigateParameters,
|
|
13
14
|
ISetUserOnboardingJWTParameters,
|
|
14
15
|
IZeroHashSDK,
|
|
15
16
|
} from "./types";
|
|
@@ -18,7 +19,7 @@ import { DEFAULT_ZH_APPS_URL } from "./constants";
|
|
|
18
19
|
import AppContainer from "./iframe-container/AppContainer";
|
|
19
20
|
import { Provider } from "react-redux";
|
|
20
21
|
import store from "./redux/store";
|
|
21
|
-
import { ACTION_SET_FILTERS, ACTION_SET_JWT } from "./redux/reducers/constants";
|
|
22
|
+
import { ACTION_SET_FILTERS, ACTION_SET_JWT, ACTION_SET_NAVIGATE } from "./redux/reducers/constants";
|
|
22
23
|
import { appCompleted, appFailed, appLoaded, appPendingApproval, closeModal, openModal } from "./redux/actions";
|
|
23
24
|
|
|
24
25
|
let _zeroHashAppsURL: string = DEFAULT_ZH_APPS_URL;
|
|
@@ -256,7 +257,13 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
256
257
|
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
257
258
|
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, { filters });
|
|
258
259
|
}
|
|
259
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Sets the navigate field for the appIdentifier provided. Currently this is
|
|
262
|
+
* specific to Onboarding and is used to navigate to a specific page within the App.
|
|
263
|
+
*/
|
|
264
|
+
setNavigate({ appIdentifier, navigate }: ISetNavigateParameters): void {
|
|
265
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_NAVIGATE, { navigate });
|
|
266
|
+
}
|
|
260
267
|
/**
|
|
261
268
|
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
262
269
|
* The JWT should be the UserJWT provided by ZeroHash via the platform
|
|
@@ -303,10 +310,13 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
303
310
|
/**
|
|
304
311
|
* openModal opens the modal for the appIdentifier provided.
|
|
305
312
|
*/
|
|
306
|
-
openModal({ jwt, appIdentifier, filters }: IOpenModalParameters): void {
|
|
313
|
+
openModal({ jwt, appIdentifier, filters, navigate }: IOpenModalParameters): void {
|
|
307
314
|
if (filters) {
|
|
308
315
|
this.setFilters({filters, appIdentifier})
|
|
309
316
|
}
|
|
317
|
+
if (navigate) {
|
|
318
|
+
this.setNavigate({ appIdentifier, navigate })
|
|
319
|
+
}
|
|
310
320
|
if (jwt) {
|
|
311
321
|
this.setJWT({
|
|
312
322
|
jwt,
|
|
@@ -5,4 +5,5 @@ export const ACTION_APP_LOADED = "APP_LOADED"
|
|
|
5
5
|
export const ACTION_PENDING_APPROVAL = "PENDING_APPROVAL"
|
|
6
6
|
export const ACTION_COMPLETED = "COMPLETED"
|
|
7
7
|
export const ACTION_FAILED = "FAILED"
|
|
8
|
-
export const ACTION_SET_FILTERS = "ACTION_SET_FILTERS"
|
|
8
|
+
export const ACTION_SET_FILTERS = "ACTION_SET_FILTERS"
|
|
9
|
+
export const ACTION_SET_NAVIGATE = "SET_NAVIGATE"
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { AppIdentifier } from "../../types";
|
|
1
|
+
import { AppIdentifier, OnboardingPage } from "../../types";
|
|
2
2
|
import { appIdentifierToActionPrefixMap } from "../../types";
|
|
3
3
|
import {
|
|
4
4
|
ACTION_SET_JWT,
|
|
5
5
|
ACTION_SET_MODAL_STATE,
|
|
6
|
-
ACTION_APP_LOADED
|
|
6
|
+
ACTION_APP_LOADED,
|
|
7
|
+
ACTION_SET_NAVIGATE
|
|
7
8
|
} from "./constants";
|
|
8
9
|
|
|
9
10
|
export interface IOnboardingState {
|
|
10
11
|
jwt: string;
|
|
11
12
|
isAppLoaded: boolean;
|
|
12
13
|
isAppActive: boolean;
|
|
14
|
+
navigate?: OnboardingPage;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export interface IOnboardingAction {
|
|
@@ -17,6 +19,7 @@ export interface IOnboardingAction {
|
|
|
17
19
|
jwt?: string;
|
|
18
20
|
isAppActive?: boolean;
|
|
19
21
|
isAppLoaded?: boolean;
|
|
22
|
+
navigate?: OnboardingPage;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const INITIAL_STATE: IOnboardingState = {
|
|
@@ -45,12 +48,19 @@ const applySetJWT = (state: IOnboardingState, action: IOnboardingAction) : IOnbo
|
|
|
45
48
|
jwt: action.jwt as string,
|
|
46
49
|
}
|
|
47
50
|
}
|
|
51
|
+
const applySetNavigate = (state: IOnboardingState, action: IOnboardingAction): IOnboardingState => {
|
|
52
|
+
return {
|
|
53
|
+
...state,
|
|
54
|
+
navigate: action.navigate,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
48
57
|
|
|
49
58
|
const reducerMap: { [actionType: string]: (state: IOnboardingState, action: IOnboardingAction) => IOnboardingState } = {
|
|
50
59
|
// Onboarding reducer
|
|
51
60
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
61
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
62
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
63
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)}${ACTION_SET_NAVIGATE}`]: applySetNavigate,
|
|
54
64
|
};
|
|
55
65
|
|
|
56
66
|
const onboardingReducer = (state = INITIAL_STATE, action: IOnboardingAction) => {
|