zh-web-sdk 2.5.1 → 2.6.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.
@@ -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
+ "fund-with-crypto": import("./fund-with-crypto").IFundWithCryptoState;
11
12
  }>, import("./crypto-withdrawals").ICryptoWithdrawalsAction>;
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
+ "fund-with-crypto": import("../reducers/fund-with-crypto").IFundWithCryptoState;
11
12
  }, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction>;
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zh-web-sdk",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",
@@ -69,6 +69,11 @@ interface AppContainerMappedProps {
69
69
  isAppLoaded: boolean;
70
70
  jwt: string;
71
71
  };
72
+ [AppIdentifier.FUND_WITH_CRYPTO]: {
73
+ isAppActive: boolean;
74
+ isAppLoaded: boolean;
75
+ jwt: string;
76
+ };
72
77
  }
73
78
 
74
79
  const appLoadTime = Date.now();
@@ -82,7 +87,8 @@ const mapAppToTitle = {
82
87
  [AppIdentifier.CRYPTO_SELL]: "Crypto Sell",
83
88
  [AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
84
89
  [AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
85
- [AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell"
90
+ [AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
91
+ [AppIdentifier.FUND_WITH_CRYPTO]: "Fund With Crypto"
86
92
  };
87
93
 
88
94
  const AppContainer = ({
package/src/index.tsx CHANGED
@@ -112,6 +112,19 @@ const appsMessageHandlers: {
112
112
  [IncomingMessageType.CryptoSellFailed]: () => {
113
113
  appFailed(AppIdentifier.CRYPTO_SELL);
114
114
  },
115
+ // Fund with crypto message handlers
116
+ [IncomingMessageType.FundWithCryptoAppLoaded]: () => {
117
+ appLoaded(AppIdentifier.FUND_WITH_CRYPTO);
118
+ },
119
+ [IncomingMessageType.FundWithCryptoCloseButtonClicked]: () => {
120
+ closeModal(AppIdentifier.FUND_WITH_CRYPTO);
121
+ },
122
+ [IncomingMessageType.FundWithCryptoCompleted]: () => {
123
+ appCompleted(AppIdentifier.FUND_WITH_CRYPTO);
124
+ },
125
+ [IncomingMessageType.FundWithCryptoFailed]: () => {
126
+ appFailed(AppIdentifier.FUND_WITH_CRYPTO);
127
+ },
115
128
  };
116
129
 
117
130
  /**
@@ -150,6 +163,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
150
163
  [AppIdentifier.FIAT_WITHDRAWALS, false],
151
164
  [AppIdentifier.CRYPTO_BUY, false],
152
165
  [AppIdentifier.CRYPTO_SELL, false],
166
+ [AppIdentifier.FUND_WITH_CRYPTO, false],
153
167
  ]);
154
168
 
155
169
  /**
@@ -166,6 +180,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
166
180
  fiatWithdrawalsJWT,
167
181
  cryptoBuyJWT,
168
182
  cryptoSellJWT,
183
+ fundWithCryptoJWT,
169
184
  zeroHashAppsURL,
170
185
  }: IInitializeParameters) {
171
186
  // The || is for backwards compatibility
@@ -215,6 +230,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
215
230
  appIdentifier: AppIdentifier.CRYPTO_SELL,
216
231
  });
217
232
  }
233
+ if (fundWithCryptoJWT) {
234
+ this.setJWT({
235
+ jwt: fundWithCryptoJWT,
236
+ appIdentifier: AppIdentifier.FUND_WITH_CRYPTO,
237
+ });
238
+ }
218
239
  }
219
240
 
220
241
  /**
@@ -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 {