zh-web-sdk 2.7.3 → 2.9.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 +8 -3
- package/dist/index.js +7 -7
- package/dist/index.js.map +4 -4
- package/dist/redux/reducers/constants.d.ts +1 -0
- package/dist/redux/reducers/index.d.ts +2 -1
- package/dist/redux/reducers/onboarding.d.ts +3 -0
- package/dist/redux/reducers/profile.d.ts +13 -0
- package/dist/redux/store/index.d.ts +2 -1
- package/dist/types.d.ts +41 -2
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +42 -4
- package/src/index.tsx +31 -3
- package/src/redux/reducers/constants.ts +2 -1
- package/src/redux/reducers/index.ts +2 -0
- package/src/redux/reducers/onboarding.ts +12 -2
- package/src/redux/reducers/profile.ts +63 -0
- package/src/types.ts +317 -276
|
@@ -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,6 @@ 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
|
-
|
|
12
|
+
profile: import("./profile").ProfileState;
|
|
13
|
+
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./onboarding").IOnboardingAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
13
14
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ProfileState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ProfileAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const profileReducer: (state: ProfileState | undefined, action: ProfileAction) => ProfileState;
|
|
13
|
+
export default profileReducer;
|
|
@@ -9,5 +9,6 @@ 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
|
-
|
|
12
|
+
profile: import("../reducers/profile").ProfileState;
|
|
13
|
+
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/onboarding").IOnboardingAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
13
14
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -72,6 +72,12 @@ export interface IInitializeParameters {
|
|
|
72
72
|
* perform Fund operations.
|
|
73
73
|
*/
|
|
74
74
|
fundJWT?: string;
|
|
75
|
+
/**
|
|
76
|
+
* profileJWT is the JWT that you received from
|
|
77
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
78
|
+
* perform Profile operations.
|
|
79
|
+
*/
|
|
80
|
+
profileJWT?: string;
|
|
75
81
|
/**
|
|
76
82
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
77
83
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -249,7 +255,22 @@ export declare enum IncomingMessageType {
|
|
|
249
255
|
* FundFailed is received when the
|
|
250
256
|
* Fund flow has failed.
|
|
251
257
|
*/
|
|
252
|
-
FundFailed = "FUND_FAILED"
|
|
258
|
+
FundFailed = "FUND_FAILED",
|
|
259
|
+
/**
|
|
260
|
+
* ProfileAppLoaded is received when the Profile
|
|
261
|
+
* app has initialized.
|
|
262
|
+
*/
|
|
263
|
+
ProfileAppLoaded = "PROFILE_APP_LOADED",
|
|
264
|
+
/**
|
|
265
|
+
* ProfileCloseButtonClicked is received when the close button
|
|
266
|
+
* has been clicked in the Profile app
|
|
267
|
+
*/
|
|
268
|
+
ProfileCloseButtonClicked = "PROFILE_CLOSE_BUTTON_CLICKED",
|
|
269
|
+
/**
|
|
270
|
+
* ProfileFailed is received when the
|
|
271
|
+
* Profile flow has failed.
|
|
272
|
+
*/
|
|
273
|
+
ProfileFailed = "PROFILE_FAILED"
|
|
253
274
|
}
|
|
254
275
|
/**
|
|
255
276
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -291,7 +312,8 @@ export declare enum AppIdentifier {
|
|
|
291
312
|
CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
|
|
292
313
|
CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
|
|
293
314
|
CSP_CRYPTO_SELL = "csp-crypto-sell",
|
|
294
|
-
FUND = "fund"
|
|
315
|
+
FUND = "fund",
|
|
316
|
+
PROFILE = "profile"
|
|
295
317
|
}
|
|
296
318
|
/**
|
|
297
319
|
* Map that maps the app AppIdentifier to the redux action prefix
|
|
@@ -311,8 +333,25 @@ export interface IOpenModalParameters {
|
|
|
311
333
|
jwt?: string;
|
|
312
334
|
appIdentifier: AppIdentifier;
|
|
313
335
|
filters?: Filters;
|
|
336
|
+
navigate?: Page;
|
|
314
337
|
}
|
|
315
338
|
export interface ISetFiltersParameters {
|
|
316
339
|
appIdentifier: AppIdentifier;
|
|
317
340
|
filters?: Filters;
|
|
318
341
|
}
|
|
342
|
+
export interface EditAddress {
|
|
343
|
+
to: "edit-address";
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Since we may extend this in the future, we use a union type to make it easy
|
|
347
|
+
* to allow for example a new CryptoBuyPage type to be added in the future or
|
|
348
|
+
* new pages for the Onboarding App with specialized props.
|
|
349
|
+
* Page is expected to be a union of "AppPage" and each App shall have it's own
|
|
350
|
+
* union of pages, such as EditAddress.
|
|
351
|
+
*/
|
|
352
|
+
export type OnboardingPage = EditAddress;
|
|
353
|
+
export type Page = OnboardingPage;
|
|
354
|
+
export interface ISetNavigateParameters {
|
|
355
|
+
appIdentifier: AppIdentifier;
|
|
356
|
+
navigate: Page;
|
|
357
|
+
}
|
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;
|
|
@@ -89,6 +93,12 @@ interface AppContainerMappedProps {
|
|
|
89
93
|
jwt: string;
|
|
90
94
|
filters?: Filters;
|
|
91
95
|
};
|
|
96
|
+
[AppIdentifier.PROFILE]: {
|
|
97
|
+
isAppActive: boolean;
|
|
98
|
+
isAppLoaded: boolean;
|
|
99
|
+
jwt: string;
|
|
100
|
+
filters?: Filters;
|
|
101
|
+
};
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
const appLoadTime = Date.now();
|
|
@@ -103,7 +113,8 @@ const mapAppToTitle = {
|
|
|
103
113
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
|
|
104
114
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
|
|
105
115
|
[AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
|
|
106
|
-
[AppIdentifier.FUND]: "Fund"
|
|
116
|
+
[AppIdentifier.FUND]: "Fund",
|
|
117
|
+
[AppIdentifier.PROFILE]: "Profile",
|
|
107
118
|
};
|
|
108
119
|
|
|
109
120
|
const AppContainer = ({
|
|
@@ -112,6 +123,7 @@ const AppContainer = ({
|
|
|
112
123
|
jwt,
|
|
113
124
|
zeroHashAppURL,
|
|
114
125
|
appIdentifier,
|
|
126
|
+
navigate,
|
|
115
127
|
}: AppContainerProps) => {
|
|
116
128
|
const title = mapAppToTitle[appIdentifier];
|
|
117
129
|
const hasJwt = !!jwt;
|
|
@@ -133,17 +145,18 @@ const AppContainer = ({
|
|
|
133
145
|
const iRef: React.MutableRefObject<HTMLIFrameElement | null> =
|
|
134
146
|
useRef<HTMLIFrameElement | null>(null);
|
|
135
147
|
useEffect(() => {
|
|
136
|
-
// Send
|
|
148
|
+
// Send events to the iframe when Apps are ready
|
|
137
149
|
if (
|
|
138
150
|
zeroHashAppURL &&
|
|
139
151
|
isAppLoaded &&
|
|
140
152
|
hasJwt &&
|
|
141
153
|
iRef.current?.contentWindow
|
|
142
154
|
) {
|
|
143
|
-
// This loops all registered apps and
|
|
155
|
+
// This loops all registered apps and send events listed below.
|
|
144
156
|
Object.keys(allAppsState).forEach((key: string) => {
|
|
145
157
|
if (!allAppsState[key as AppIdentifier].jwt) return;
|
|
146
158
|
|
|
159
|
+
// Send JWT token
|
|
147
160
|
iRef.current?.contentWindow?.postMessage(
|
|
148
161
|
{
|
|
149
162
|
type: `${appIdentifierToActionPrefixMap.get(
|
|
@@ -153,6 +166,7 @@ const AppContainer = ({
|
|
|
153
166
|
},
|
|
154
167
|
zeroHashAppURL
|
|
155
168
|
);
|
|
169
|
+
// Send filters
|
|
156
170
|
if (allAppsState[key as AppIdentifier].filters) {
|
|
157
171
|
iRef.current?.contentWindow?.postMessage(
|
|
158
172
|
{
|
|
@@ -164,9 +178,29 @@ const AppContainer = ({
|
|
|
164
178
|
zeroHashAppURL
|
|
165
179
|
);
|
|
166
180
|
}
|
|
181
|
+
// Send navigate to Onboarding App
|
|
182
|
+
if (appIdentifier === AppIdentifier.ONBOARDING && navigate) {
|
|
183
|
+
iRef.current?.contentWindow?.postMessage(
|
|
184
|
+
{
|
|
185
|
+
type: `${appIdentifierToActionPrefixMap.get(
|
|
186
|
+
AppIdentifier.ONBOARDING
|
|
187
|
+
)}NAVIGATE`,
|
|
188
|
+
navigate,
|
|
189
|
+
},
|
|
190
|
+
zeroHashAppURL
|
|
191
|
+
);
|
|
192
|
+
}
|
|
167
193
|
});
|
|
168
194
|
}
|
|
169
|
-
}, [
|
|
195
|
+
}, [
|
|
196
|
+
appIdentifier,
|
|
197
|
+
hasJwt,
|
|
198
|
+
isAppLoaded,
|
|
199
|
+
jwt,
|
|
200
|
+
zeroHashAppURL,
|
|
201
|
+
allAppsState,
|
|
202
|
+
navigate,
|
|
203
|
+
]);
|
|
170
204
|
|
|
171
205
|
useEffect(() => {
|
|
172
206
|
// set the styles when the screen size changes
|
|
@@ -236,6 +270,10 @@ const mapStateToProps = (
|
|
|
236
270
|
isAppLoaded: state[ownProps.appIdentifier].isAppLoaded,
|
|
237
271
|
jwt: state[ownProps.appIdentifier].jwt,
|
|
238
272
|
filters: state[ownProps.appIdentifier].filters,
|
|
273
|
+
navigate:
|
|
274
|
+
ownProps.appIdentifier === AppIdentifier.ONBOARDING
|
|
275
|
+
? state[ownProps.appIdentifier].navigate
|
|
276
|
+
: undefined,
|
|
239
277
|
};
|
|
240
278
|
};
|
|
241
279
|
|
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;
|
|
@@ -126,6 +127,16 @@ const appsMessageHandlers: {
|
|
|
126
127
|
[IncomingMessageType.FundFailed]: () => {
|
|
127
128
|
appFailed(AppIdentifier.FUND);
|
|
128
129
|
},
|
|
130
|
+
// Profile message handlers
|
|
131
|
+
[IncomingMessageType.ProfileAppLoaded]: () => {
|
|
132
|
+
appLoaded(AppIdentifier.PROFILE);
|
|
133
|
+
},
|
|
134
|
+
[IncomingMessageType.ProfileCloseButtonClicked]: () => {
|
|
135
|
+
closeModal(AppIdentifier.PROFILE);
|
|
136
|
+
},
|
|
137
|
+
[IncomingMessageType.ProfileFailed]: () => {
|
|
138
|
+
appFailed(AppIdentifier.PROFILE);
|
|
139
|
+
},
|
|
129
140
|
};
|
|
130
141
|
|
|
131
142
|
/**
|
|
@@ -165,6 +176,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
165
176
|
[AppIdentifier.CRYPTO_BUY, false],
|
|
166
177
|
[AppIdentifier.CRYPTO_SELL, false],
|
|
167
178
|
[AppIdentifier.FUND, false],
|
|
179
|
+
[AppIdentifier.PROFILE, false],
|
|
168
180
|
]);
|
|
169
181
|
|
|
170
182
|
/**
|
|
@@ -182,6 +194,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
182
194
|
cryptoBuyJWT,
|
|
183
195
|
cryptoSellJWT,
|
|
184
196
|
fundJWT,
|
|
197
|
+
profileJWT,
|
|
185
198
|
zeroHashAppsURL,
|
|
186
199
|
}: IInitializeParameters) {
|
|
187
200
|
// The || is for backwards compatibility
|
|
@@ -237,6 +250,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
237
250
|
appIdentifier: AppIdentifier.FUND,
|
|
238
251
|
});
|
|
239
252
|
}
|
|
253
|
+
if (profileJWT) {
|
|
254
|
+
this.setJWT({
|
|
255
|
+
jwt: profileJWT,
|
|
256
|
+
appIdentifier: AppIdentifier.PROFILE,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
240
259
|
}
|
|
241
260
|
|
|
242
261
|
/**
|
|
@@ -256,7 +275,13 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
256
275
|
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
257
276
|
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, { filters });
|
|
258
277
|
}
|
|
259
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Sets the navigate field for the appIdentifier provided. Currently this is
|
|
280
|
+
* specific to Onboarding and is used to navigate to a specific page within the App.
|
|
281
|
+
*/
|
|
282
|
+
setNavigate({ appIdentifier, navigate }: ISetNavigateParameters): void {
|
|
283
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_NAVIGATE, { navigate });
|
|
284
|
+
}
|
|
260
285
|
/**
|
|
261
286
|
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
262
287
|
* The JWT should be the UserJWT provided by ZeroHash via the platform
|
|
@@ -303,10 +328,13 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
303
328
|
/**
|
|
304
329
|
* openModal opens the modal for the appIdentifier provided.
|
|
305
330
|
*/
|
|
306
|
-
openModal({ jwt, appIdentifier, filters }: IOpenModalParameters): void {
|
|
331
|
+
openModal({ jwt, appIdentifier, filters, navigate }: IOpenModalParameters): void {
|
|
307
332
|
if (filters) {
|
|
308
333
|
this.setFilters({filters, appIdentifier})
|
|
309
334
|
}
|
|
335
|
+
if (navigate) {
|
|
336
|
+
this.setNavigate({ appIdentifier, navigate })
|
|
337
|
+
}
|
|
310
338
|
if (jwt) {
|
|
311
339
|
this.setJWT({
|
|
312
340
|
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"
|
|
@@ -6,6 +6,7 @@ import fiatWithdrawalsReducer from "./fiat-withdrawals";
|
|
|
6
6
|
import cryptoBuyReducer from "./crypto-buy";
|
|
7
7
|
import cryptoSellReducer from "./crypto-sell";
|
|
8
8
|
import fundReducer from "./fund";
|
|
9
|
+
import profileReducer from "./profile";
|
|
9
10
|
|
|
10
11
|
const rootReducer = combineReducers({
|
|
11
12
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
@@ -18,6 +19,7 @@ const rootReducer = combineReducers({
|
|
|
18
19
|
["csp-fiat-withdrawals"]: fiatWithdrawalsReducer,
|
|
19
20
|
["csp-crypto-sell"]: cryptoSellReducer,
|
|
20
21
|
["fund"]: fundReducer,
|
|
22
|
+
["profile"]: profileReducer,
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
export default rootReducer;
|
|
@@ -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) => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AppIdentifier } from "../../types";
|
|
2
|
+
import { appIdentifierToActionPrefixMap } from "../../types";
|
|
3
|
+
import {
|
|
4
|
+
ACTION_SET_JWT,
|
|
5
|
+
ACTION_SET_MODAL_STATE,
|
|
6
|
+
ACTION_APP_LOADED
|
|
7
|
+
} from "./constants";
|
|
8
|
+
|
|
9
|
+
export interface ProfileState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ProfileAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: ProfileState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: ProfileState, action: ProfileAction) : ProfileState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: ProfileState, action: ProfileAction) : ProfileState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: ProfileState, action: ProfileAction) : ProfileState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: ProfileState, action: ProfileAction) => ProfileState } = {
|
|
50
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const profileReducer = (state = INITIAL_STATE, action: ProfileAction) => {
|
|
56
|
+
if (!!action.type && !!reducerMap[action.type]) {
|
|
57
|
+
return reducerMap[action.type](state, action);
|
|
58
|
+
} else {
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default profileReducer;
|