zh-web-sdk 2.5.2 → 2.7.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 +4 -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/crypto-buy.d.ts +3 -0
- package/dist/redux/reducers/fund-with-crypto.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +2 -1
- package/dist/redux/store/index.d.ts +2 -1
- package/dist/types.d.ts +44 -2
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +48 -11
- package/src/index.tsx +30 -2
- package/src/redux/reducers/constants.ts +2 -1
- package/src/redux/reducers/crypto-buy.ts +13 -2
- package/src/redux/reducers/fund-with-crypto.ts +63 -0
- package/src/redux/reducers/index.ts +2 -0
- package/src/types.ts +47 -1
|
@@ -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;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IFundWithCryptoState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IFundWithCryptoAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const fundWithCryptoReducer: (state: IFundWithCryptoState | undefined, action: IFundWithCryptoAction) => IFundWithCryptoState;
|
|
13
|
+
export default fundWithCryptoReducer;
|
|
@@ -8,5 +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
|
-
|
|
11
|
+
"fund-with-crypto": import("./fund-with-crypto").IFundWithCryptoState;
|
|
12
|
+
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./crypto-buy").ICryptoBuyAction>;
|
|
12
13
|
export default rootReducer;
|
|
@@ -8,5 +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
|
-
|
|
11
|
+
"fund-with-crypto": import("../reducers/fund-with-crypto").IFundWithCryptoState;
|
|
12
|
+
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
|
|
12
13
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export interface IInitializeParameters {
|
|
|
66
66
|
* perform Crypto Sell.
|
|
67
67
|
*/
|
|
68
68
|
cryptoSellJWT?: string;
|
|
69
|
+
/**
|
|
70
|
+
* fundWithCryptoJWT is the JWT that you received from
|
|
71
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
72
|
+
* perform Fund With Crypto operations.
|
|
73
|
+
*/
|
|
74
|
+
fundWithCryptoJWT?: string;
|
|
69
75
|
/**
|
|
70
76
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
71
77
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -223,7 +229,27 @@ export declare enum IncomingMessageType {
|
|
|
223
229
|
* CryptoSellFailed is received when the Crypto
|
|
224
230
|
* sell flow has failed.
|
|
225
231
|
*/
|
|
226
|
-
CryptoSellFailed = "CRYPTO_SELL_FAILED"
|
|
232
|
+
CryptoSellFailed = "CRYPTO_SELL_FAILED",
|
|
233
|
+
/**
|
|
234
|
+
* FundWithCryptoAppLoaded is received when the Fund Witch Crypto
|
|
235
|
+
* app has initialized.
|
|
236
|
+
*/
|
|
237
|
+
FundWithCryptoAppLoaded = "FUND_WITH_CRYPTO_APP_LOADED",
|
|
238
|
+
/**
|
|
239
|
+
* FundWithCryptoCloseButtonClicked is received when the close button
|
|
240
|
+
* has been clicked in the Fund With Crypto app
|
|
241
|
+
*/
|
|
242
|
+
FundWithCryptoCloseButtonClicked = "FUND_WITH_CRYPTO_CLOSE_BUTTON_CLICKED",
|
|
243
|
+
/**
|
|
244
|
+
* FundWithCryptoCompleted is received when the
|
|
245
|
+
* Fund With Crypto flow has completed successfully.
|
|
246
|
+
*/
|
|
247
|
+
FundWithCryptoCompleted = "FUND_WITH_CRYPTO_COMPLETED",
|
|
248
|
+
/**
|
|
249
|
+
* FundWithCryptoFailed is received when the
|
|
250
|
+
* Fund With Crypto flow has failed.
|
|
251
|
+
*/
|
|
252
|
+
FundWithCryptoFailed = "FUND_WITH_CRYPTO_FAILED"
|
|
227
253
|
}
|
|
228
254
|
/**
|
|
229
255
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -264,7 +290,8 @@ export declare enum AppIdentifier {
|
|
|
264
290
|
CRYPTO_SELL = "crypto-sell",
|
|
265
291
|
CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
|
|
266
292
|
CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
|
|
267
|
-
CSP_CRYPTO_SELL = "csp-crypto-sell"
|
|
293
|
+
CSP_CRYPTO_SELL = "csp-crypto-sell",
|
|
294
|
+
FUND_WITH_CRYPTO = "fund-with-crypto"
|
|
268
295
|
}
|
|
269
296
|
/**
|
|
270
297
|
* Map that maps the app AppIdentifier to the redux action prefix
|
|
@@ -274,7 +301,22 @@ export interface ISetJWTParameters {
|
|
|
274
301
|
jwt: string;
|
|
275
302
|
appIdentifier: AppIdentifier;
|
|
276
303
|
}
|
|
304
|
+
export interface Filters {
|
|
305
|
+
getAssets: {
|
|
306
|
+
deposit_address_creation: string;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
277
309
|
export interface IOpenModalParameters {
|
|
278
310
|
jwt?: string;
|
|
279
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
|
+
};
|
|
280
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,46 +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;
|
|
85
|
+
};
|
|
86
|
+
[AppIdentifier.FUND_WITH_CRYPTO]: {
|
|
87
|
+
isAppActive: boolean;
|
|
88
|
+
isAppLoaded: boolean;
|
|
89
|
+
jwt: string;
|
|
90
|
+
filters?: Filters;
|
|
71
91
|
};
|
|
72
92
|
}
|
|
73
93
|
|
|
@@ -82,7 +102,8 @@ const mapAppToTitle = {
|
|
|
82
102
|
[AppIdentifier.CRYPTO_SELL]: "Crypto Sell",
|
|
83
103
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
|
|
84
104
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
|
|
85
|
-
[AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell"
|
|
105
|
+
[AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
|
|
106
|
+
[AppIdentifier.FUND_WITH_CRYPTO]: "Fund With Crypto",
|
|
86
107
|
};
|
|
87
108
|
|
|
88
109
|
const AppContainer = ({
|
|
@@ -90,13 +111,12 @@ const AppContainer = ({
|
|
|
90
111
|
isAppLoaded,
|
|
91
112
|
jwt,
|
|
92
113
|
zeroHashAppURL,
|
|
93
|
-
appIdentifier
|
|
114
|
+
appIdentifier,
|
|
94
115
|
}: AppContainerProps) => {
|
|
95
116
|
const title = mapAppToTitle[appIdentifier];
|
|
96
117
|
const hasJwt = !!jwt;
|
|
97
118
|
const [container, setContainerStyle] = useState(containerStyle);
|
|
98
|
-
|
|
99
|
-
const allAppsState = useSelector(state => state as AppContainerMappedProps);
|
|
119
|
+
const allAppsState = useSelector((state) => state as AppContainerMappedProps);
|
|
100
120
|
|
|
101
121
|
/**
|
|
102
122
|
* setContainer sets the CSS styles based on the current matching media queries
|
|
@@ -120,19 +140,31 @@ const AppContainer = ({
|
|
|
120
140
|
hasJwt &&
|
|
121
141
|
iRef.current?.contentWindow
|
|
122
142
|
) {
|
|
123
|
-
|
|
124
143
|
// This loops all registered apps and sends their JWT tokens.
|
|
125
144
|
Object.keys(allAppsState).forEach((key: string) => {
|
|
126
145
|
if (!allAppsState[key as AppIdentifier].jwt) return;
|
|
127
146
|
|
|
128
147
|
iRef.current?.contentWindow?.postMessage(
|
|
129
148
|
{
|
|
130
|
-
type: `${appIdentifierToActionPrefixMap.get(
|
|
149
|
+
type: `${appIdentifierToActionPrefixMap.get(
|
|
150
|
+
key as AppIdentifier
|
|
151
|
+
)}SEND_JWT_TOKEN`,
|
|
131
152
|
jwt: allAppsState[key as AppIdentifier].jwt,
|
|
132
153
|
},
|
|
133
154
|
zeroHashAppURL
|
|
134
155
|
);
|
|
135
|
-
|
|
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
|
+
});
|
|
136
168
|
}
|
|
137
169
|
}, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL, allAppsState]);
|
|
138
170
|
|
|
@@ -161,9 +193,13 @@ const AppContainer = ({
|
|
|
161
193
|
}
|
|
162
194
|
return (
|
|
163
195
|
<div
|
|
164
|
-
style={
|
|
165
|
-
|
|
166
|
-
|
|
196
|
+
style={
|
|
197
|
+
isAppActive
|
|
198
|
+
? {
|
|
199
|
+
...appWrapperStyle,
|
|
200
|
+
}
|
|
201
|
+
: appWrapperHiddenStyle
|
|
202
|
+
}
|
|
167
203
|
onClick={() => closeModal(appIdentifier)}
|
|
168
204
|
>
|
|
169
205
|
<div
|
|
@@ -199,6 +235,7 @@ const mapStateToProps = (
|
|
|
199
235
|
isAppActive: state[ownProps.appIdentifier].isAppActive,
|
|
200
236
|
isAppLoaded: state[ownProps.appIdentifier].isAppLoaded,
|
|
201
237
|
jwt: state[ownProps.appIdentifier].jwt,
|
|
238
|
+
filters: state[ownProps.appIdentifier].filters,
|
|
202
239
|
};
|
|
203
240
|
};
|
|
204
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;
|
|
@@ -112,6 +113,19 @@ const appsMessageHandlers: {
|
|
|
112
113
|
[IncomingMessageType.CryptoSellFailed]: () => {
|
|
113
114
|
appFailed(AppIdentifier.CRYPTO_SELL);
|
|
114
115
|
},
|
|
116
|
+
// Fund with crypto message handlers
|
|
117
|
+
[IncomingMessageType.FundWithCryptoAppLoaded]: () => {
|
|
118
|
+
appLoaded(AppIdentifier.FUND_WITH_CRYPTO);
|
|
119
|
+
},
|
|
120
|
+
[IncomingMessageType.FundWithCryptoCloseButtonClicked]: () => {
|
|
121
|
+
closeModal(AppIdentifier.FUND_WITH_CRYPTO);
|
|
122
|
+
},
|
|
123
|
+
[IncomingMessageType.FundWithCryptoCompleted]: () => {
|
|
124
|
+
appCompleted(AppIdentifier.FUND_WITH_CRYPTO);
|
|
125
|
+
},
|
|
126
|
+
[IncomingMessageType.FundWithCryptoFailed]: () => {
|
|
127
|
+
appFailed(AppIdentifier.FUND_WITH_CRYPTO);
|
|
128
|
+
},
|
|
115
129
|
};
|
|
116
130
|
|
|
117
131
|
/**
|
|
@@ -150,6 +164,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
150
164
|
[AppIdentifier.FIAT_WITHDRAWALS, false],
|
|
151
165
|
[AppIdentifier.CRYPTO_BUY, false],
|
|
152
166
|
[AppIdentifier.CRYPTO_SELL, false],
|
|
167
|
+
[AppIdentifier.FUND_WITH_CRYPTO, false],
|
|
153
168
|
]);
|
|
154
169
|
|
|
155
170
|
/**
|
|
@@ -166,6 +181,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
166
181
|
fiatWithdrawalsJWT,
|
|
167
182
|
cryptoBuyJWT,
|
|
168
183
|
cryptoSellJWT,
|
|
184
|
+
fundWithCryptoJWT,
|
|
169
185
|
zeroHashAppsURL,
|
|
170
186
|
}: IInitializeParameters) {
|
|
171
187
|
// The || is for backwards compatibility
|
|
@@ -215,6 +231,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
215
231
|
appIdentifier: AppIdentifier.CRYPTO_SELL,
|
|
216
232
|
});
|
|
217
233
|
}
|
|
234
|
+
if (fundWithCryptoJWT) {
|
|
235
|
+
this.setJWT({
|
|
236
|
+
jwt: fundWithCryptoJWT,
|
|
237
|
+
appIdentifier: AppIdentifier.FUND_WITH_CRYPTO,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
218
240
|
}
|
|
219
241
|
|
|
220
242
|
/**
|
|
@@ -231,6 +253,9 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
231
253
|
setJWT({ jwt, appIdentifier }: ISetJWTParameters): void {
|
|
232
254
|
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_JWT, { jwt });
|
|
233
255
|
}
|
|
256
|
+
setFilters({ filters, appIdentifier }: ISetFiltersParameters): void {
|
|
257
|
+
dispatchActionBasedOnAppIdentifier(appIdentifier, ACTION_SET_FILTERS, { filters });
|
|
258
|
+
}
|
|
234
259
|
|
|
235
260
|
/**
|
|
236
261
|
* setUserOnboardingJWT sets the JWT to be whatever value is provided.
|
|
@@ -278,7 +303,10 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
278
303
|
/**
|
|
279
304
|
* openModal opens the modal for the appIdentifier provided.
|
|
280
305
|
*/
|
|
281
|
-
openModal({ jwt, appIdentifier }: IOpenModalParameters): void {
|
|
306
|
+
openModal({ jwt, appIdentifier, filters }: IOpenModalParameters): void {
|
|
307
|
+
if (filters) {
|
|
308
|
+
this.setFilters({filters, appIdentifier})
|
|
309
|
+
}
|
|
282
310
|
if (jwt) {
|
|
283
311
|
this.setJWT({
|
|
284
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) => {
|
|
@@ -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 IFundWithCryptoState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IFundWithCryptoAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: IFundWithCryptoState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: IFundWithCryptoState, action: IFundWithCryptoAction) : IFundWithCryptoState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: IFundWithCryptoState, action: IFundWithCryptoAction) : IFundWithCryptoState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: IFundWithCryptoState, action: IFundWithCryptoAction) : IFundWithCryptoState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: IFundWithCryptoState, action: IFundWithCryptoAction) => IFundWithCryptoState } = {
|
|
50
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND_WITH_CRYPTO)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND_WITH_CRYPTO)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FUND_WITH_CRYPTO)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const fundWithCryptoReducer = (state = INITIAL_STATE, action: IFundWithCryptoAction) => {
|
|
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 fundWithCryptoReducer;
|
|
@@ -5,6 +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 fundWithCryptoReducer from "./fund-with-crypto";
|
|
8
9
|
|
|
9
10
|
const rootReducer = combineReducers({
|
|
10
11
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
@@ -16,6 +17,7 @@ const rootReducer = combineReducers({
|
|
|
16
17
|
["csp-crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
17
18
|
["csp-fiat-withdrawals"]: fiatWithdrawalsReducer,
|
|
18
19
|
["csp-crypto-sell"]: cryptoSellReducer,
|
|
20
|
+
["fund-with-crypto"]: fundWithCryptoReducer,
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
export default rootReducer;
|
package/src/types.ts
CHANGED
|
@@ -68,6 +68,12 @@ export interface IInitializeParameters {
|
|
|
68
68
|
* perform Crypto Sell.
|
|
69
69
|
*/
|
|
70
70
|
cryptoSellJWT?: string
|
|
71
|
+
/**
|
|
72
|
+
* fundWithCryptoJWT is the JWT that you received from
|
|
73
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
74
|
+
* perform Fund With Crypto operations.
|
|
75
|
+
*/
|
|
76
|
+
fundWithCryptoJWT?: string
|
|
71
77
|
/**
|
|
72
78
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
73
79
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -229,6 +235,26 @@ export enum IncomingMessageType {
|
|
|
229
235
|
* sell flow has failed.
|
|
230
236
|
*/
|
|
231
237
|
CryptoSellFailed = "CRYPTO_SELL_FAILED",
|
|
238
|
+
/**
|
|
239
|
+
* FundWithCryptoAppLoaded is received when the Fund Witch Crypto
|
|
240
|
+
* app has initialized.
|
|
241
|
+
*/
|
|
242
|
+
FundWithCryptoAppLoaded = "FUND_WITH_CRYPTO_APP_LOADED",
|
|
243
|
+
/**
|
|
244
|
+
* FundWithCryptoCloseButtonClicked is received when the close button
|
|
245
|
+
* has been clicked in the Fund With Crypto app
|
|
246
|
+
*/
|
|
247
|
+
FundWithCryptoCloseButtonClicked = "FUND_WITH_CRYPTO_CLOSE_BUTTON_CLICKED",
|
|
248
|
+
/**
|
|
249
|
+
* FundWithCryptoCompleted is received when the
|
|
250
|
+
* Fund With Crypto flow has completed successfully.
|
|
251
|
+
*/
|
|
252
|
+
FundWithCryptoCompleted = "FUND_WITH_CRYPTO_COMPLETED",
|
|
253
|
+
/**
|
|
254
|
+
* FundWithCryptoFailed is received when the
|
|
255
|
+
* Fund With Crypto flow has failed.
|
|
256
|
+
*/
|
|
257
|
+
FundWithCryptoFailed = "FUND_WITH_CRYPTO_FAILED",
|
|
232
258
|
}
|
|
233
259
|
|
|
234
260
|
/**
|
|
@@ -273,7 +299,8 @@ export enum AppIdentifier {
|
|
|
273
299
|
CRYPTO_SELL = "crypto-sell",
|
|
274
300
|
CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
|
|
275
301
|
CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
|
|
276
|
-
CSP_CRYPTO_SELL = "csp-crypto-sell"
|
|
302
|
+
CSP_CRYPTO_SELL = "csp-crypto-sell",
|
|
303
|
+
FUND_WITH_CRYPTO = "fund-with-crypto"
|
|
277
304
|
}
|
|
278
305
|
|
|
279
306
|
/**
|
|
@@ -290,6 +317,8 @@ export const appIdentifierToActionPrefixMap = new Map(
|
|
|
290
317
|
[AppIdentifier.CSP_CRYPTO_WITHDRAWALS, "CRYPTO_WITHDRAWALS_"], // CSP apps uses the same events as "regular" flow
|
|
291
318
|
[AppIdentifier.CSP_FIAT_WITHDRAWALS, "FIAT_WITHDRAWALS_"], // CSP apps uses the same events as "regular" flow
|
|
292
319
|
[AppIdentifier.CSP_CRYPTO_SELL, "CRYPTO_SELL_"],
|
|
320
|
+
[AppIdentifier.CSP_CRYPTO_SELL, "CRYPTO_SELL_"],
|
|
321
|
+
[AppIdentifier.FUND_WITH_CRYPTO, "FUND_WITH_CRYPTO_"],
|
|
293
322
|
])
|
|
294
323
|
|
|
295
324
|
export interface ISetJWTParameters {
|
|
@@ -297,7 +326,24 @@ export interface ISetJWTParameters {
|
|
|
297
326
|
appIdentifier: AppIdentifier;
|
|
298
327
|
}
|
|
299
328
|
|
|
329
|
+
export interface Filters {
|
|
330
|
+
getAssets: {
|
|
331
|
+
deposit_address_creation: string
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
300
335
|
export interface IOpenModalParameters {
|
|
301
336
|
jwt?: string;
|
|
302
337
|
appIdentifier: AppIdentifier;
|
|
338
|
+
filters: Filters;
|
|
303
339
|
}
|
|
340
|
+
|
|
341
|
+
export interface ISetFiltersParameters {
|
|
342
|
+
appIdentifier: AppIdentifier;
|
|
343
|
+
filters: {
|
|
344
|
+
getAssets: {
|
|
345
|
+
deposit_address_creation?: string;
|
|
346
|
+
stablecoin?: boolean;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|