zh-web-sdk 2.6.0 → 2.7.1
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 +3 -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/crypto-buy.d.ts +3 -0
- package/dist/redux/reducers/index.d.ts +1 -1
- package/dist/redux/store/index.d.ts +1 -1
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +42 -11
- package/src/index.tsx +9 -2
- package/src/redux/reducers/constants.ts +2 -1
- package/src/redux/reducers/crypto-buy.ts +13 -2
- package/src/types.ts +17 -0
|
@@ -4,3 +4,4 @@ export declare const ACTION_APP_LOADED = "APP_LOADED";
|
|
|
4
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
|
+
export declare const ACTION_SET_FILTERS = "ACTION_SET_FILTERS";
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { Filters } from "../../types";
|
|
1
2
|
export interface ICryptoBuyState {
|
|
2
3
|
jwt: string;
|
|
3
4
|
isAppLoaded: boolean;
|
|
4
5
|
isAppActive: boolean;
|
|
6
|
+
filters?: Filters;
|
|
5
7
|
}
|
|
6
8
|
export interface ICryptoBuyAction {
|
|
7
9
|
type: string;
|
|
8
10
|
jwt?: string;
|
|
9
11
|
isAppActive?: boolean;
|
|
10
12
|
isAppLoaded?: boolean;
|
|
13
|
+
filters?: Filters;
|
|
11
14
|
}
|
|
12
15
|
declare const cryptoBuyReducer: (state: ICryptoBuyState | undefined, action: ICryptoBuyAction) => ICryptoBuyState;
|
|
13
16
|
export default cryptoBuyReducer;
|
|
@@ -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-with-crypto": import("./fund-with-crypto").IFundWithCryptoState;
|
|
12
|
-
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
12
|
+
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
13
13
|
export default rootReducer;
|
|
@@ -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-with-crypto": import("../reducers/fund-with-crypto").IFundWithCryptoState;
|
|
12
|
-
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
12
|
+
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
13
13
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -301,7 +301,22 @@ export interface ISetJWTParameters {
|
|
|
301
301
|
jwt: string;
|
|
302
302
|
appIdentifier: AppIdentifier;
|
|
303
303
|
}
|
|
304
|
+
export interface Filters {
|
|
305
|
+
getAssets: {
|
|
306
|
+
deposit_address_creation: string;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
304
309
|
export interface IOpenModalParameters {
|
|
305
310
|
jwt?: string;
|
|
306
311
|
appIdentifier: AppIdentifier;
|
|
312
|
+
filters?: Filters;
|
|
313
|
+
}
|
|
314
|
+
export interface ISetFiltersParameters {
|
|
315
|
+
appIdentifier: AppIdentifier;
|
|
316
|
+
filters: {
|
|
317
|
+
getAssets: {
|
|
318
|
+
deposit_address_creation?: string;
|
|
319
|
+
stablecoin?: boolean;
|
|
320
|
+
};
|
|
321
|
+
};
|
|
307
322
|
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
appWrapperHiddenStyle,
|
|
14
14
|
} from "../styles";
|
|
15
15
|
import { closeModal } from "../redux/actions";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
AppIdentifier,
|
|
18
|
+
Filters,
|
|
19
|
+
appIdentifierToActionPrefixMap,
|
|
20
|
+
} from "../types";
|
|
17
21
|
|
|
18
22
|
interface AppContainerProps {
|
|
19
23
|
isAppActive?: boolean;
|
|
@@ -21,6 +25,7 @@ interface AppContainerProps {
|
|
|
21
25
|
jwt?: string;
|
|
22
26
|
zeroHashAppURL: string;
|
|
23
27
|
appIdentifier: AppIdentifier;
|
|
28
|
+
filters?: Filters;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
interface AppContainerMappedProps {
|
|
@@ -28,51 +33,61 @@ interface AppContainerMappedProps {
|
|
|
28
33
|
isAppActive: boolean;
|
|
29
34
|
isAppLoaded: boolean;
|
|
30
35
|
jwt: string;
|
|
36
|
+
filters?: Filters;
|
|
31
37
|
};
|
|
32
38
|
[AppIdentifier.ONBOARDING]: {
|
|
33
39
|
isAppActive: boolean;
|
|
34
40
|
isAppLoaded: boolean;
|
|
35
41
|
jwt: string;
|
|
42
|
+
filters?: Filters;
|
|
36
43
|
};
|
|
37
44
|
[AppIdentifier.FIAT_DEPOSITS]: {
|
|
38
45
|
isAppActive: boolean;
|
|
39
46
|
isAppLoaded: boolean;
|
|
40
47
|
jwt: string;
|
|
48
|
+
filters?: Filters;
|
|
41
49
|
};
|
|
42
50
|
[AppIdentifier.FIAT_WITHDRAWALS]: {
|
|
43
51
|
isAppActive: boolean;
|
|
44
52
|
isAppLoaded: boolean;
|
|
45
53
|
jwt: string;
|
|
54
|
+
filters?: Filters;
|
|
46
55
|
};
|
|
47
56
|
[AppIdentifier.CRYPTO_BUY]: {
|
|
48
57
|
isAppActive: boolean;
|
|
49
58
|
isAppLoaded: boolean;
|
|
50
59
|
jwt: string;
|
|
60
|
+
filters?: Filters;
|
|
51
61
|
};
|
|
52
62
|
[AppIdentifier.CRYPTO_SELL]: {
|
|
53
63
|
isAppActive: boolean;
|
|
54
64
|
isAppLoaded: boolean;
|
|
55
65
|
jwt: string;
|
|
66
|
+
filters?: Filters;
|
|
56
67
|
};
|
|
57
68
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: {
|
|
58
69
|
isAppActive: boolean;
|
|
59
70
|
isAppLoaded: boolean;
|
|
60
71
|
jwt: string;
|
|
72
|
+
filters?: Filters;
|
|
61
73
|
};
|
|
62
74
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS]: {
|
|
63
75
|
isAppActive: boolean;
|
|
64
76
|
isAppLoaded: boolean;
|
|
65
77
|
jwt: string;
|
|
78
|
+
filters?: Filters;
|
|
66
79
|
};
|
|
67
80
|
[AppIdentifier.CSP_CRYPTO_SELL]: {
|
|
68
81
|
isAppActive: boolean;
|
|
69
82
|
isAppLoaded: boolean;
|
|
70
83
|
jwt: string;
|
|
84
|
+
filters?: Filters;
|
|
71
85
|
};
|
|
72
86
|
[AppIdentifier.FUND_WITH_CRYPTO]: {
|
|
73
87
|
isAppActive: boolean;
|
|
74
88
|
isAppLoaded: boolean;
|
|
75
89
|
jwt: string;
|
|
90
|
+
filters?: Filters;
|
|
76
91
|
};
|
|
77
92
|
}
|
|
78
93
|
|
|
@@ -88,7 +103,7 @@ const mapAppToTitle = {
|
|
|
88
103
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
|
|
89
104
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
|
|
90
105
|
[AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
|
|
91
|
-
[AppIdentifier.FUND_WITH_CRYPTO]: "Fund With Crypto"
|
|
106
|
+
[AppIdentifier.FUND_WITH_CRYPTO]: "Fund With Crypto",
|
|
92
107
|
};
|
|
93
108
|
|
|
94
109
|
const AppContainer = ({
|
|
@@ -96,13 +111,12 @@ const AppContainer = ({
|
|
|
96
111
|
isAppLoaded,
|
|
97
112
|
jwt,
|
|
98
113
|
zeroHashAppURL,
|
|
99
|
-
appIdentifier
|
|
114
|
+
appIdentifier,
|
|
100
115
|
}: AppContainerProps) => {
|
|
101
116
|
const title = mapAppToTitle[appIdentifier];
|
|
102
117
|
const hasJwt = !!jwt;
|
|
103
118
|
const [container, setContainerStyle] = useState(containerStyle);
|
|
104
|
-
|
|
105
|
-
const allAppsState = useSelector(state => state as AppContainerMappedProps);
|
|
119
|
+
const allAppsState = useSelector((state) => state as AppContainerMappedProps);
|
|
106
120
|
|
|
107
121
|
/**
|
|
108
122
|
* setContainer sets the CSS styles based on the current matching media queries
|
|
@@ -126,19 +140,31 @@ const AppContainer = ({
|
|
|
126
140
|
hasJwt &&
|
|
127
141
|
iRef.current?.contentWindow
|
|
128
142
|
) {
|
|
129
|
-
|
|
130
143
|
// This loops all registered apps and sends their JWT tokens.
|
|
131
144
|
Object.keys(allAppsState).forEach((key: string) => {
|
|
132
145
|
if (!allAppsState[key as AppIdentifier].jwt) return;
|
|
133
146
|
|
|
134
147
|
iRef.current?.contentWindow?.postMessage(
|
|
135
148
|
{
|
|
136
|
-
type: `${appIdentifierToActionPrefixMap.get(
|
|
149
|
+
type: `${appIdentifierToActionPrefixMap.get(
|
|
150
|
+
key as AppIdentifier
|
|
151
|
+
)}SEND_JWT_TOKEN`,
|
|
137
152
|
jwt: allAppsState[key as AppIdentifier].jwt,
|
|
138
153
|
},
|
|
139
154
|
zeroHashAppURL
|
|
140
155
|
);
|
|
141
|
-
|
|
156
|
+
if (allAppsState[key as AppIdentifier].filters) {
|
|
157
|
+
iRef.current?.contentWindow?.postMessage(
|
|
158
|
+
{
|
|
159
|
+
type: `${appIdentifierToActionPrefixMap.get(
|
|
160
|
+
key as AppIdentifier
|
|
161
|
+
)}SEND_FILTERS`,
|
|
162
|
+
filters: allAppsState[key as AppIdentifier].filters,
|
|
163
|
+
},
|
|
164
|
+
zeroHashAppURL
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
142
168
|
}
|
|
143
169
|
}, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL, allAppsState]);
|
|
144
170
|
|
|
@@ -167,9 +193,13 @@ const AppContainer = ({
|
|
|
167
193
|
}
|
|
168
194
|
return (
|
|
169
195
|
<div
|
|
170
|
-
style={
|
|
171
|
-
|
|
172
|
-
|
|
196
|
+
style={
|
|
197
|
+
isAppActive
|
|
198
|
+
? {
|
|
199
|
+
...appWrapperStyle,
|
|
200
|
+
}
|
|
201
|
+
: appWrapperHiddenStyle
|
|
202
|
+
}
|
|
173
203
|
onClick={() => closeModal(appIdentifier)}
|
|
174
204
|
>
|
|
175
205
|
<div
|
|
@@ -205,6 +235,7 @@ const mapStateToProps = (
|
|
|
205
235
|
isAppActive: state[ownProps.appIdentifier].isAppActive,
|
|
206
236
|
isAppLoaded: state[ownProps.appIdentifier].isAppLoaded,
|
|
207
237
|
jwt: state[ownProps.appIdentifier].jwt,
|
|
238
|
+
filters: state[ownProps.appIdentifier].filters,
|
|
208
239
|
};
|
|
209
240
|
};
|
|
210
241
|
|
package/src/index.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
IncomingMessageType,
|
|
9
9
|
IOpenModalParameters,
|
|
10
10
|
IOpenOnboardingModalParameters,
|
|
11
|
+
ISetFiltersParameters,
|
|
11
12
|
ISetJWTParameters,
|
|
12
13
|
ISetUserOnboardingJWTParameters,
|
|
13
14
|
IZeroHashSDK,
|
|
@@ -17,7 +18,7 @@ import { DEFAULT_ZH_APPS_URL } from "./constants";
|
|
|
17
18
|
import AppContainer from "./iframe-container/AppContainer";
|
|
18
19
|
import { Provider } from "react-redux";
|
|
19
20
|
import store from "./redux/store";
|
|
20
|
-
import { ACTION_SET_JWT } from "./redux/reducers/constants";
|
|
21
|
+
import { ACTION_SET_FILTERS, ACTION_SET_JWT } from "./redux/reducers/constants";
|
|
21
22
|
import { appCompleted, appFailed, appLoaded, appPendingApproval, closeModal, openModal } from "./redux/actions";
|
|
22
23
|
|
|
23
24
|
let _zeroHashAppsURL: string = DEFAULT_ZH_APPS_URL;
|
|
@@ -252,6 +253,9 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
252
253
|
setJWT({ jwt, appIdentifier }: ISetJWTParameters): void {
|
|
253
254
|
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_JWT, { jwt });
|
|
254
255
|
}
|
|
256
|
+
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
257
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, { filters });
|
|
258
|
+
}
|
|
255
259
|
|
|
256
260
|
/**
|
|
257
261
|
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
@@ -299,7 +303,10 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
299
303
|
/**
|
|
300
304
|
* openModal opens the modal for the appIdentifier provided.
|
|
301
305
|
*/
|
|
302
|
-
openModal({ jwt, appIdentifier }: IOpenModalParameters): void {
|
|
306
|
+
openModal({ jwt, appIdentifier, filters }: IOpenModalParameters): void {
|
|
307
|
+
if (filters) {
|
|
308
|
+
this.setFilters({filters, appIdentifier})
|
|
309
|
+
}
|
|
303
310
|
if (jwt) {
|
|
304
311
|
this.setJWT({
|
|
305
312
|
jwt,
|
|
@@ -4,4 +4,5 @@ export const ACTION_SET_JWT = "SET_JWT"
|
|
|
4
4
|
export const ACTION_APP_LOADED = "APP_LOADED"
|
|
5
5
|
export const ACTION_PENDING_APPROVAL = "PENDING_APPROVAL"
|
|
6
6
|
export const ACTION_COMPLETED = "COMPLETED"
|
|
7
|
-
export const ACTION_FAILED = "FAILED"
|
|
7
|
+
export const ACTION_FAILED = "FAILED"
|
|
8
|
+
export const ACTION_SET_FILTERS = "ACTION_SET_FILTERS"
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { AppIdentifier } from "../../types";
|
|
1
|
+
import { AppIdentifier, Filters } 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_FILTERS
|
|
7
8
|
} from "./constants";
|
|
8
9
|
|
|
9
10
|
export interface ICryptoBuyState {
|
|
10
11
|
jwt: string;
|
|
11
12
|
isAppLoaded: boolean;
|
|
12
13
|
isAppActive: boolean;
|
|
14
|
+
filters?: Filters
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export interface ICryptoBuyAction {
|
|
@@ -17,6 +19,7 @@ export interface ICryptoBuyAction {
|
|
|
17
19
|
jwt?: string;
|
|
18
20
|
isAppActive?: boolean;
|
|
19
21
|
isAppLoaded?: boolean;
|
|
22
|
+
filters?: Filters;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const INITIAL_STATE: ICryptoBuyState = {
|
|
@@ -46,11 +49,19 @@ const applySetJWT = (state: ICryptoBuyState, action: ICryptoBuyAction) : ICrypto
|
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
const applySetFilters = (state: ICryptoBuyState, action: ICryptoBuyAction) : ICryptoBuyState => {
|
|
53
|
+
return {
|
|
54
|
+
...state,
|
|
55
|
+
filters: action.filters,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
const reducerMap: { [actionType: string]: (state: ICryptoBuyState, action: ICryptoBuyAction) => ICryptoBuyState } = {
|
|
50
60
|
// Crypto buy reducer
|
|
51
61
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
62
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
63
|
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
64
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_SET_FILTERS}`]: applySetFilters,
|
|
54
65
|
};
|
|
55
66
|
|
|
56
67
|
const cryptoBuyReducer = (state = INITIAL_STATE, action: ICryptoBuyAction) => {
|
package/src/types.ts
CHANGED
|
@@ -326,7 +326,24 @@ export interface ISetJWTParameters {
|
|
|
326
326
|
appIdentifier: AppIdentifier;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
export interface Filters {
|
|
330
|
+
getAssets: {
|
|
331
|
+
deposit_address_creation: string
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
329
335
|
export interface IOpenModalParameters {
|
|
330
336
|
jwt?: string;
|
|
331
337
|
appIdentifier: AppIdentifier;
|
|
338
|
+
filters?: Filters;
|
|
332
339
|
}
|
|
340
|
+
|
|
341
|
+
export interface ISetFiltersParameters {
|
|
342
|
+
appIdentifier: AppIdentifier;
|
|
343
|
+
filters: {
|
|
344
|
+
getAssets: {
|
|
345
|
+
deposit_address_creation?: string;
|
|
346
|
+
stablecoin?: boolean;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|