zh-web-sdk 2.11.2 → 2.12.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.
@@ -13,5 +13,6 @@ declare const rootReducer: import("redux").Reducer<import("redux").CombinedState
13
13
  "crypto-account-link": import("./crypto-account-link").ICryptoAccountLinkState;
14
14
  "crypto-account-link-payouts": import("./crypto-account-link-payouts").ICryptoAccountLinkPayoutsState;
15
15
  payouts: import("./payouts").IPayoutsState;
16
+ pay: import("./pay").IPayState;
16
17
  }>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./onboarding").IOnboardingAction | import("./crypto-buy").ICryptoBuyAction>;
17
18
  export default rootReducer;
@@ -0,0 +1,13 @@
1
+ export interface IPayState {
2
+ jwt: string;
3
+ isAppLoaded: boolean;
4
+ isAppActive: boolean;
5
+ }
6
+ export interface IPayAction {
7
+ type: string;
8
+ jwt?: string;
9
+ isAppActive?: boolean;
10
+ isAppLoaded?: boolean;
11
+ }
12
+ declare const PayReducer: (state: IPayState | undefined, action: IPayAction) => IPayState;
13
+ export default PayReducer;
@@ -15,6 +15,7 @@ declare const store: import("redux").Store<import("redux").EmptyObject & {
15
15
  "crypto-account-link": import("../reducers/crypto-account-link").ICryptoAccountLinkState;
16
16
  "crypto-account-link-payouts": import("../reducers/crypto-account-link-payouts").ICryptoAccountLinkPayoutsState;
17
17
  payouts: import("../reducers/payouts").IPayoutsState;
18
+ pay: import("../reducers/pay").IPayState;
18
19
  }, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/onboarding").IOnboardingAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
19
20
  export default store;
20
21
  export type RootState = ReturnType<typeof rootReducer>;
package/dist/styles.d.ts CHANGED
@@ -3,6 +3,10 @@ export declare const screenSizes: {
3
3
  id: string;
4
4
  size: number;
5
5
  }[];
6
+ /**
7
+ * When the width is smaller than
8
+ *
9
+ */
6
10
  export declare const minWidthMatcher: () => string;
7
11
  export declare const containerStyle: CSSProperties;
8
12
  export declare const containerMediaStyles: {
package/dist/types.d.ts CHANGED
@@ -103,6 +103,12 @@ export interface IInitializeParameters {
103
103
  * to perform payouts.
104
104
  */
105
105
  payoutsJWT?: string;
106
+ /**
107
+ * payJWT is the JWT that you received from
108
+ * the ZeroHash HTTP API and have specific permissions
109
+ * to perform pay.
110
+ */
111
+ payJWT?: string;
106
112
  /**
107
113
  * zeroHashAppsURL is the base URL for all our Apps.
108
114
  * It defaults to https://web-sdk.zerohash.com/ and will
@@ -352,7 +358,24 @@ export declare enum IncomingMessageType {
352
358
  /**
353
359
  * PayoutsFailed is received when the Payouts flow has failed.
354
360
  */
355
- PayoutsFailed = "PAYOUTS_FAILED"
361
+ PayoutsFailed = "PAYOUTS_FAILED",
362
+ /**
363
+ * PayAppLoaded is received when the Pay app has initialized.
364
+ */
365
+ PayAppLoaded = "PAY_APP_LOADED",
366
+ /**
367
+ * PayCloseButtonClicked is received when the close button
368
+ * has been clicked in the Pay app
369
+ */
370
+ PayCloseButtonClicked = "PAY_CLOSE_BUTTON_CLICKED",
371
+ /**
372
+ * PayCompleted is received when the Pay flow has completed successfully.
373
+ */
374
+ PayCompleted = "PAY_COMPLETED",
375
+ /**
376
+ * PayFailed is received when the Pay flow has failed.
377
+ */
378
+ PayFailed = "PAY_FAILED"
356
379
  }
357
380
  /**
358
381
  * IncomingMessage defines the structure of an incoming
@@ -398,7 +421,8 @@ export declare enum AppIdentifier {
398
421
  PROFILE = "profile",
399
422
  CRYPTO_ACCOUNT_LINK = "crypto-account-link",
400
423
  CRYPTO_ACCOUNT_LINK_PAYOUTS = "crypto-account-link-payouts",
401
- PAYOUTS = "payouts"
424
+ PAYOUTS = "payouts",
425
+ PAY = "pay"
402
426
  }
403
427
  /**
404
428
  * 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.11.2",
3
+ "version": "2.12.1",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",
@@ -123,6 +123,12 @@ interface AppContainerMappedProps {
123
123
  jwt: string;
124
124
  filters?: Filters;
125
125
  };
126
+ [AppIdentifier.PAY]: {
127
+ isAppActive: boolean;
128
+ isAppLoaded: boolean;
129
+ jwt: string;
130
+ filters?: Filters;
131
+ };
126
132
  }
127
133
 
128
134
  const appLoadTime = Date.now();
@@ -142,6 +148,7 @@ const mapAppToTitle = {
142
148
  [AppIdentifier.CRYPTO_ACCOUNT_LINK]: "Crypto Account Link",
143
149
  [AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS]: "Crypto Account Link Payouts",
144
150
  [AppIdentifier.PAYOUTS]: "Payouts",
151
+ [AppIdentifier.PAY]: "Pay",
145
152
  };
146
153
 
147
154
  const AppContainer = ({
@@ -18,6 +18,7 @@ describe('AppContainer', () => {
18
18
  [AppIdentifier.CRYPTO_ACCOUNT_LINK, "Crypto Account Link"],
19
19
  [AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, "Crypto Account Link Payouts"],
20
20
  [AppIdentifier.PAYOUTS, "Payouts"],
21
+ [AppIdentifier.PAY, "Pay"],
21
22
  ])("should render AppContainer correctly for %s", async (appIdentifier, title) => {
22
23
  renderWithProviders(
23
24
  <AppContainer
package/src/index.tsx CHANGED
@@ -176,6 +176,19 @@ const appsMessageHandlers: {
176
176
  [IncomingMessageType.PayoutsFailed]: () => {
177
177
  appFailed(AppIdentifier.PAYOUTS);
178
178
  },
179
+ // Pay message handlers
180
+ [IncomingMessageType.PayAppLoaded]: () => {
181
+ appLoaded(AppIdentifier.PAY);
182
+ },
183
+ [IncomingMessageType.PayCloseButtonClicked]: () => {
184
+ closeModal(AppIdentifier.PAY);
185
+ },
186
+ [IncomingMessageType.PayCompleted]: () => {
187
+ appCompleted(AppIdentifier.PAY);
188
+ },
189
+ [IncomingMessageType.PayFailed]: () => {
190
+ appFailed(AppIdentifier.PAY);
191
+ },
179
192
  };
180
193
 
181
194
  /**
@@ -219,6 +232,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
219
232
  [AppIdentifier.CRYPTO_ACCOUNT_LINK, false],
220
233
  [AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, false],
221
234
  [AppIdentifier.PAYOUTS, false],
235
+ [AppIdentifier.PAY, false],
222
236
  ]);
223
237
 
224
238
  /**
@@ -240,6 +254,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
240
254
  cryptoAccountLinkJWT,
241
255
  cryptoAccountLinkPayoutsJWT,
242
256
  payoutsJWT,
257
+ payJWT,
243
258
  zeroHashAppsURL,
244
259
  }: IInitializeParameters) {
245
260
  // The || is for backwards compatibility
@@ -319,6 +334,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
319
334
  appIdentifier: AppIdentifier.PAYOUTS,
320
335
  });
321
336
  }
337
+ if (payJWT) {
338
+ this.setJWT({
339
+ jwt: payJWT,
340
+ appIdentifier: AppIdentifier.PAY,
341
+ });
342
+ }
322
343
  }
323
344
 
324
345
  /**
@@ -10,6 +10,7 @@ import profileReducer from "./profile";
10
10
  import cryptoAccountLinkReducer from "./crypto-account-link";
11
11
  import cryptoAccountLinkPayoutsReducer from "./crypto-account-link-payouts";
12
12
  import payoutsReducer from "./payouts";
13
+ import payReducer from "./pay";
13
14
 
14
15
  const rootReducer = combineReducers({
15
16
  ["crypto-withdrawals"]: cryptoWithdrawalsReducer,
@@ -26,6 +27,7 @@ const rootReducer = combineReducers({
26
27
  ["crypto-account-link"]: cryptoAccountLinkReducer,
27
28
  ["crypto-account-link-payouts"]: cryptoAccountLinkPayoutsReducer,
28
29
  ["payouts"]: payoutsReducer,
30
+ ["pay"]: payReducer,
29
31
  });
30
32
 
31
33
  export default rootReducer;
@@ -0,0 +1,64 @@
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 IPayState {
10
+ jwt: string;
11
+ isAppLoaded: boolean;
12
+ isAppActive: boolean;
13
+ }
14
+
15
+ export interface IPayAction {
16
+ type: string;
17
+ jwt?: string;
18
+ isAppActive?: boolean;
19
+ isAppLoaded?: boolean;
20
+ }
21
+
22
+ const INITIAL_STATE: IPayState = {
23
+ jwt: "",
24
+ isAppActive: false,
25
+ isAppLoaded: false
26
+ }
27
+
28
+ const applySetIsAppActive = (state: IPayState, action: IPayAction) : IPayState => {
29
+ return {
30
+ ...state,
31
+ isAppActive: !!action.isAppActive,
32
+ }
33
+ }
34
+
35
+ const applySetSendJWTToApp = (state: IPayState, action: IPayAction) : IPayState => {
36
+ return {
37
+ ...state,
38
+ isAppLoaded: !!action.isAppLoaded,
39
+ }
40
+ }
41
+
42
+ const applySetJWT = (state: IPayState, action: IPayAction) : IPayState => {
43
+ return {
44
+ ...state,
45
+ jwt: action.jwt as string,
46
+ }
47
+ }
48
+
49
+ const reducerMap: { [actionType: string]: (state: IPayState, action: IPayAction) => IPayState } = {
50
+ // Pay reducer
51
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PAY)}${ACTION_SET_JWT}`]: applySetJWT,
52
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PAY)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
53
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PAY)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
54
+ };
55
+
56
+ const PayReducer = (state = INITIAL_STATE, action: IPayAction) => {
57
+ if (!!action.type && !!reducerMap[action.type]) {
58
+ return reducerMap[action.type](state, action);
59
+ } else {
60
+ return state;
61
+ }
62
+ }
63
+
64
+ export default PayReducer;
package/src/styles.ts CHANGED
@@ -1,14 +1,24 @@
1
1
  import { CSSProperties } from "react";
2
2
 
3
- const MTE_SM = 540;
3
+ const MTE_SM = 480;
4
+ const MTE_MD = 720;
5
+ const modalBorderRadius = 24
4
6
 
5
7
  export const screenSizes: { id: string, size: number }[] = [
6
8
  {
7
9
  id: "MTE_SM",
8
10
  size: MTE_SM,
9
- }
11
+ },
12
+ {
13
+ id: "MTE_MD",
14
+ size: MTE_MD,
15
+ },
10
16
  ]
11
17
 
18
+ /**
19
+ * When the width is smaller than
20
+ *
21
+ */
12
22
  export const minWidthMatcher = (): string => {
13
23
  for (let i = 0; i < screenSizes.length; i++) {
14
24
  const { id, size } = screenSizes[i];
@@ -24,18 +34,20 @@ export const containerStyle: CSSProperties = {
24
34
  paddingLeft: 0,
25
35
  marginRight: "auto",
26
36
  marginLeft: "auto",
27
- maxHeight: 882,
37
+ maxHeight: 812
28
38
  }
29
39
 
30
40
  export const containerMediaStyles: { [id: string]: CSSProperties } = {
31
41
  MTE_SM: {
32
- width: 540
42
+ width: 480
43
+ },
44
+ MTE_MD: {
45
+ width: 720
33
46
  },
34
47
  ANY: {
35
48
  width: "100%",
36
49
  height: "100%",
37
50
  maxWidth: "100%",
38
- borderRadius: 0,
39
51
  maxHeight: "100%"
40
52
  },
41
53
  }
@@ -51,15 +63,15 @@ export const appWrapperStyle: CSSProperties = {
51
63
  height: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
52
64
  maxHeight: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
53
65
  background: "rgba(0,0,0,0.5)",
54
- cursor: "pointer",
66
+ cursor: "pointer"
55
67
  }
56
68
 
57
69
  export const modalStyle: CSSProperties = {
58
70
  padding: 0,
59
- borderRadius: 5,
60
71
  backgroundColor: "#FFF",
61
72
  height: "calc(100% - 100px)",
62
73
  maxWidth: "calc(100% - 30px)",
74
+ borderRadius: modalBorderRadius
63
75
  }
64
76
 
65
77
  export const iframeWrapperStyle: CSSProperties = {
@@ -76,5 +88,5 @@ export const iframeStyle: CSSProperties = {
76
88
  margin: 0,
77
89
  padding: 0,
78
90
  overflow: "hidden",
79
- borderRadius: "0 0 15px 15px"
91
+ borderRadius: modalBorderRadius
80
92
  };
package/src/types.ts CHANGED
@@ -106,6 +106,12 @@ export interface IInitializeParameters {
106
106
  * to perform payouts.
107
107
  */
108
108
  payoutsJWT?: string
109
+ /**
110
+ * payJWT is the JWT that you received from
111
+ * the ZeroHash HTTP API and have specific permissions
112
+ * to perform pay.
113
+ */
114
+ payJWT?: string
109
115
  /**
110
116
  * zeroHashAppsURL is the base URL for all our Apps.
111
117
  * It defaults to https://web-sdk.zerohash.com/ and will
@@ -359,6 +365,23 @@ export enum IncomingMessageType {
359
365
  * PayoutsFailed is received when the Payouts flow has failed.
360
366
  */
361
367
  PayoutsFailed = "PAYOUTS_FAILED",
368
+ /**
369
+ * PayAppLoaded is received when the Pay app has initialized.
370
+ */
371
+ PayAppLoaded = "PAY_APP_LOADED",
372
+ /**
373
+ * PayCloseButtonClicked is received when the close button
374
+ * has been clicked in the Pay app
375
+ */
376
+ PayCloseButtonClicked = "PAY_CLOSE_BUTTON_CLICKED",
377
+ /**
378
+ * PayCompleted is received when the Pay flow has completed successfully.
379
+ */
380
+ PayCompleted = "PAY_COMPLETED",
381
+ /**
382
+ * PayFailed is received when the Pay flow has failed.
383
+ */
384
+ PayFailed = "PAY_FAILED",
362
385
  }
363
386
 
364
387
  /**
@@ -408,7 +431,8 @@ export enum AppIdentifier {
408
431
  PROFILE = "profile",
409
432
  CRYPTO_ACCOUNT_LINK = "crypto-account-link",
410
433
  CRYPTO_ACCOUNT_LINK_PAYOUTS = "crypto-account-link-payouts",
411
- PAYOUTS = "payouts"
434
+ PAYOUTS = "payouts",
435
+ PAY = "pay"
412
436
  }
413
437
 
414
438
  /**
@@ -430,7 +454,8 @@ export const appIdentifierToActionPrefixMap = new Map(
430
454
  [AppIdentifier.PROFILE, "PROFILE_"],
431
455
  [AppIdentifier.CRYPTO_ACCOUNT_LINK, "CRYPTO_ACCOUNT_LINK_"],
432
456
  [AppIdentifier.CRYPTO_ACCOUNT_LINK_PAYOUTS, "CRYPTO_ACCOUNT_LINK_PAYOUTS_"],
433
- [AppIdentifier.PAYOUTS, "PAYOUTS_"]
457
+ [AppIdentifier.PAYOUTS, "PAYOUTS_"],
458
+ [AppIdentifier.PAY, "PAY_"]
434
459
  ])
435
460
 
436
461
  export interface ISetJWTParameters {