zh-web-sdk 2.7.2 → 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 +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/fund.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +2 -2
- package/dist/redux/reducers/onboarding.d.ts +3 -0
- package/dist/redux/store/index.d.ts +2 -2
- package/dist/types.d.ts +32 -15
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +36 -5
- package/src/index.tsx +27 -17
- package/src/redux/reducers/constants.ts +2 -1
- package/src/redux/reducers/fund.ts +63 -0
- package/src/redux/reducers/index.ts +2 -2
- package/src/redux/reducers/onboarding.ts +12 -2
- package/src/types.ts +297 -279
- package/dist/redux/reducers/fund-with-crypto.d.ts +0 -13
- package/src/redux/reducers/fund-with-crypto.ts +0 -63
|
@@ -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";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IFundState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IFundAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const fundReducer: (state: IFundState | undefined, action: IFundAction) => IFundState;
|
|
13
|
+
export default fundReducer;
|
|
@@ -8,6 +8,6 @@ declare const rootReducer: import("redux").Reducer<import("redux").CombinedState
|
|
|
8
8
|
"csp-crypto-withdrawals": import("./crypto-withdrawals").ICryptoWithdrawalsState;
|
|
9
9
|
"csp-fiat-withdrawals": import("./fiat-withdrawals").IFiatWithdrawalsState;
|
|
10
10
|
"csp-crypto-sell": import("./crypto-sell").ICryptoSellState;
|
|
11
|
-
|
|
12
|
-
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
11
|
+
fund: import("./fund").IFundState;
|
|
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;
|
|
@@ -8,6 +8,6 @@ declare const store: import("redux").Store<import("redux").EmptyObject & {
|
|
|
8
8
|
"csp-crypto-withdrawals": import("../reducers/crypto-withdrawals").ICryptoWithdrawalsState;
|
|
9
9
|
"csp-fiat-withdrawals": import("../reducers/fiat-withdrawals").IFiatWithdrawalsState;
|
|
10
10
|
"csp-crypto-sell": import("../reducers/crypto-sell").ICryptoSellState;
|
|
11
|
-
|
|
12
|
-
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
11
|
+
fund: import("../reducers/fund").IFundState;
|
|
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
|
@@ -67,11 +67,11 @@ export interface IInitializeParameters {
|
|
|
67
67
|
*/
|
|
68
68
|
cryptoSellJWT?: string;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* fundJWT is the JWT that you received from
|
|
71
71
|
* the ZeroHash HTTP API and have specific permissions to
|
|
72
|
-
* perform Fund
|
|
72
|
+
* perform Fund operations.
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
fundJWT?: string;
|
|
75
75
|
/**
|
|
76
76
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
77
77
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -231,25 +231,25 @@ export declare enum IncomingMessageType {
|
|
|
231
231
|
*/
|
|
232
232
|
CryptoSellFailed = "CRYPTO_SELL_FAILED",
|
|
233
233
|
/**
|
|
234
|
-
*
|
|
234
|
+
* FundAppLoaded is received when the Fund
|
|
235
235
|
* app has initialized.
|
|
236
236
|
*/
|
|
237
|
-
|
|
237
|
+
FundAppLoaded = "FUND_APP_LOADED",
|
|
238
238
|
/**
|
|
239
|
-
*
|
|
240
|
-
* has been clicked in the Fund
|
|
239
|
+
* FundCloseButtonClicked is received when the close button
|
|
240
|
+
* has been clicked in the Fund app
|
|
241
241
|
*/
|
|
242
|
-
|
|
242
|
+
FundCloseButtonClicked = "FUND_CLOSE_BUTTON_CLICKED",
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
245
|
-
* Fund
|
|
244
|
+
* FundCompleted is received when the
|
|
245
|
+
* Fund flow has completed successfully.
|
|
246
246
|
*/
|
|
247
|
-
|
|
247
|
+
FundCompleted = "FUND_COMPLETED",
|
|
248
248
|
/**
|
|
249
|
-
*
|
|
250
|
-
* Fund
|
|
249
|
+
* FundFailed is received when the
|
|
250
|
+
* Fund flow has failed.
|
|
251
251
|
*/
|
|
252
|
-
|
|
252
|
+
FundFailed = "FUND_FAILED"
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
255
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -291,7 +291,7 @@ export declare enum AppIdentifier {
|
|
|
291
291
|
CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
|
|
292
292
|
CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
|
|
293
293
|
CSP_CRYPTO_SELL = "csp-crypto-sell",
|
|
294
|
-
|
|
294
|
+
FUND = "fund"
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
297
|
* Map that maps the app AppIdentifier to the redux action prefix
|
|
@@ -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;
|
|
@@ -83,7 +87,7 @@ interface AppContainerMappedProps {
|
|
|
83
87
|
jwt: string;
|
|
84
88
|
filters?: Filters;
|
|
85
89
|
};
|
|
86
|
-
[AppIdentifier.
|
|
90
|
+
[AppIdentifier.FUND]: {
|
|
87
91
|
isAppActive: boolean;
|
|
88
92
|
isAppLoaded: boolean;
|
|
89
93
|
jwt: string;
|
|
@@ -103,7 +107,7 @@ const mapAppToTitle = {
|
|
|
103
107
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
|
|
104
108
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
|
|
105
109
|
[AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
|
|
106
|
-
[AppIdentifier.
|
|
110
|
+
[AppIdentifier.FUND]: "Fund"
|
|
107
111
|
};
|
|
108
112
|
|
|
109
113
|
const AppContainer = ({
|
|
@@ -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;
|
|
@@ -113,18 +114,18 @@ const appsMessageHandlers: {
|
|
|
113
114
|
[IncomingMessageType.CryptoSellFailed]: () => {
|
|
114
115
|
appFailed(AppIdentifier.CRYPTO_SELL);
|
|
115
116
|
},
|
|
116
|
-
// Fund
|
|
117
|
-
[IncomingMessageType.
|
|
118
|
-
appLoaded(AppIdentifier.
|
|
117
|
+
// Fund message handlers
|
|
118
|
+
[IncomingMessageType.FundAppLoaded]: () => {
|
|
119
|
+
appLoaded(AppIdentifier.FUND);
|
|
119
120
|
},
|
|
120
|
-
[IncomingMessageType.
|
|
121
|
-
closeModal(AppIdentifier.
|
|
121
|
+
[IncomingMessageType.FundCloseButtonClicked]: () => {
|
|
122
|
+
closeModal(AppIdentifier.FUND);
|
|
122
123
|
},
|
|
123
|
-
[IncomingMessageType.
|
|
124
|
-
appCompleted(AppIdentifier.
|
|
124
|
+
[IncomingMessageType.FundCompleted]: () => {
|
|
125
|
+
appCompleted(AppIdentifier.FUND);
|
|
125
126
|
},
|
|
126
|
-
[IncomingMessageType.
|
|
127
|
-
appFailed(AppIdentifier.
|
|
127
|
+
[IncomingMessageType.FundFailed]: () => {
|
|
128
|
+
appFailed(AppIdentifier.FUND);
|
|
128
129
|
},
|
|
129
130
|
};
|
|
130
131
|
|
|
@@ -164,7 +165,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
164
165
|
[AppIdentifier.FIAT_WITHDRAWALS, false],
|
|
165
166
|
[AppIdentifier.CRYPTO_BUY, false],
|
|
166
167
|
[AppIdentifier.CRYPTO_SELL, false],
|
|
167
|
-
[AppIdentifier.
|
|
168
|
+
[AppIdentifier.FUND, false],
|
|
168
169
|
]);
|
|
169
170
|
|
|
170
171
|
/**
|
|
@@ -181,7 +182,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
181
182
|
fiatWithdrawalsJWT,
|
|
182
183
|
cryptoBuyJWT,
|
|
183
184
|
cryptoSellJWT,
|
|
184
|
-
|
|
185
|
+
fundJWT,
|
|
185
186
|
zeroHashAppsURL,
|
|
186
187
|
}: IInitializeParameters) {
|
|
187
188
|
// The || is for backwards compatibility
|
|
@@ -231,10 +232,10 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
231
232
|
appIdentifier: AppIdentifier.CRYPTO_SELL,
|
|
232
233
|
});
|
|
233
234
|
}
|
|
234
|
-
if (
|
|
235
|
+
if (fundJWT) {
|
|
235
236
|
this.setJWT({
|
|
236
|
-
jwt:
|
|
237
|
-
appIdentifier: AppIdentifier.
|
|
237
|
+
jwt: fundJWT,
|
|
238
|
+
appIdentifier: AppIdentifier.FUND,
|
|
238
239
|
});
|
|
239
240
|
}
|
|
240
241
|
}
|
|
@@ -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"
|
|
@@ -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 IFundState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IFundAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: IFundState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: IFundState, action: IFundAction) : IFundState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: IFundState, action: IFundAction) : IFundState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: IFundState, action: IFundAction) : IFundState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: IFundState, action: IFundAction) => IFundState } = {
|
|
50
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const fundReducer = (state = INITIAL_STATE, action: IFundAction) => {
|
|
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 fundReducer;
|
|
@@ -5,7 +5,7 @@ import fiatDepositsReducer from "./fiat-deposits";
|
|
|
5
5
|
import fiatWithdrawalsReducer from "./fiat-withdrawals";
|
|
6
6
|
import cryptoBuyReducer from "./crypto-buy";
|
|
7
7
|
import cryptoSellReducer from "./crypto-sell";
|
|
8
|
-
import
|
|
8
|
+
import fundReducer from "./fund";
|
|
9
9
|
|
|
10
10
|
const rootReducer = combineReducers({
|
|
11
11
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
@@ -17,7 +17,7 @@ const rootReducer = combineReducers({
|
|
|
17
17
|
["csp-crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
18
18
|
["csp-fiat-withdrawals"]: fiatWithdrawalsReducer,
|
|
19
19
|
["csp-crypto-sell"]: cryptoSellReducer,
|
|
20
|
-
["fund
|
|
20
|
+
["fund"]: fundReducer,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
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) => {
|