zh-web-sdk 2.8.0 → 2.10.3

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.
@@ -9,5 +9,6 @@ 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: import("./fund").IFundState;
12
+ profile: import("./profile").ProfileState;
12
13
  }>, import("./crypto-withdrawals").ICryptoWithdrawalsAction | import("./onboarding").IOnboardingAction | import("./crypto-buy").ICryptoBuyAction>;
13
14
  export default rootReducer;
@@ -0,0 +1,13 @@
1
+ export interface ProfileState {
2
+ jwt: string;
3
+ isAppLoaded: boolean;
4
+ isAppActive: boolean;
5
+ }
6
+ export interface ProfileAction {
7
+ type: string;
8
+ jwt?: string;
9
+ isAppActive?: boolean;
10
+ isAppLoaded?: boolean;
11
+ }
12
+ declare const profileReducer: (state: ProfileState | undefined, action: ProfileAction) => ProfileState;
13
+ export default profileReducer;
@@ -9,5 +9,6 @@ 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: import("../reducers/fund").IFundState;
12
+ profile: import("../reducers/profile").ProfileState;
12
13
  }, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction | import("../reducers/onboarding").IOnboardingAction | import("../reducers/crypto-buy").ICryptoBuyAction>;
13
14
  export default store;
package/dist/types.d.ts CHANGED
@@ -72,6 +72,12 @@ export interface IInitializeParameters {
72
72
  * perform Fund operations.
73
73
  */
74
74
  fundJWT?: string;
75
+ /**
76
+ * profileJWT is the JWT that you received from
77
+ * the ZeroHash HTTP API and have specific permissions to
78
+ * perform Profile operations.
79
+ */
80
+ profileJWT?: string;
75
81
  /**
76
82
  * zeroHashAppsURL is the base URL for all our Apps.
77
83
  * It defaults to https://web-sdk.zerohash.com/ and will
@@ -249,7 +255,22 @@ export declare enum IncomingMessageType {
249
255
  * FundFailed is received when the
250
256
  * Fund flow has failed.
251
257
  */
252
- FundFailed = "FUND_FAILED"
258
+ FundFailed = "FUND_FAILED",
259
+ /**
260
+ * ProfileAppLoaded is received when the Profile
261
+ * app has initialized.
262
+ */
263
+ ProfileAppLoaded = "PROFILE_APP_LOADED",
264
+ /**
265
+ * ProfileCloseButtonClicked is received when the close button
266
+ * has been clicked in the Profile app
267
+ */
268
+ ProfileCloseButtonClicked = "PROFILE_CLOSE_BUTTON_CLICKED",
269
+ /**
270
+ * ProfileFailed is received when the
271
+ * Profile flow has failed.
272
+ */
273
+ ProfileFailed = "PROFILE_FAILED"
253
274
  }
254
275
  /**
255
276
  * IncomingMessage defines the structure of an incoming
@@ -291,7 +312,8 @@ export declare enum AppIdentifier {
291
312
  CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
292
313
  CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
293
314
  CSP_CRYPTO_SELL = "csp-crypto-sell",
294
- FUND = "fund"
315
+ FUND = "fund",
316
+ PROFILE = "profile"
295
317
  }
296
318
  /**
297
319
  * 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.8.0",
3
+ "version": "2.10.3",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",
@@ -93,6 +93,12 @@ interface AppContainerMappedProps {
93
93
  jwt: string;
94
94
  filters?: Filters;
95
95
  };
96
+ [AppIdentifier.PROFILE]: {
97
+ isAppActive: boolean;
98
+ isAppLoaded: boolean;
99
+ jwt: string;
100
+ filters?: Filters;
101
+ };
96
102
  }
97
103
 
98
104
  const appLoadTime = Date.now();
@@ -107,7 +113,8 @@ const mapAppToTitle = {
107
113
  [AppIdentifier.CSP_CRYPTO_WITHDRAWALS]: "CBP Crypto Withdrawals",
108
114
  [AppIdentifier.CSP_FIAT_WITHDRAWALS]: "CBP Fiat Withdrawals",
109
115
  [AppIdentifier.CSP_CRYPTO_SELL]: "Crypto Sell",
110
- [AppIdentifier.FUND]: "Fund"
116
+ [AppIdentifier.FUND]: "Fund",
117
+ [AppIdentifier.PROFILE]: "Profile",
111
118
  };
112
119
 
113
120
  const AppContainer = ({
package/src/index.tsx CHANGED
@@ -127,6 +127,16 @@ const appsMessageHandlers: {
127
127
  [IncomingMessageType.FundFailed]: () => {
128
128
  appFailed(AppIdentifier.FUND);
129
129
  },
130
+ // Profile message handlers
131
+ [IncomingMessageType.ProfileAppLoaded]: () => {
132
+ appLoaded(AppIdentifier.PROFILE);
133
+ },
134
+ [IncomingMessageType.ProfileCloseButtonClicked]: () => {
135
+ closeModal(AppIdentifier.PROFILE);
136
+ },
137
+ [IncomingMessageType.ProfileFailed]: () => {
138
+ appFailed(AppIdentifier.PROFILE);
139
+ },
130
140
  };
131
141
 
132
142
  /**
@@ -166,6 +176,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
166
176
  [AppIdentifier.CRYPTO_BUY, false],
167
177
  [AppIdentifier.CRYPTO_SELL, false],
168
178
  [AppIdentifier.FUND, false],
179
+ [AppIdentifier.PROFILE, false],
169
180
  ]);
170
181
 
171
182
  /**
@@ -183,6 +194,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
183
194
  cryptoBuyJWT,
184
195
  cryptoSellJWT,
185
196
  fundJWT,
197
+ profileJWT,
186
198
  zeroHashAppsURL,
187
199
  }: IInitializeParameters) {
188
200
  // The || is for backwards compatibility
@@ -238,6 +250,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
238
250
  appIdentifier: AppIdentifier.FUND,
239
251
  });
240
252
  }
253
+ if (profileJWT) {
254
+ this.setJWT({
255
+ jwt: profileJWT,
256
+ appIdentifier: AppIdentifier.PROFILE,
257
+ });
258
+ }
241
259
  }
242
260
 
243
261
  /**
@@ -6,6 +6,7 @@ import fiatWithdrawalsReducer from "./fiat-withdrawals";
6
6
  import cryptoBuyReducer from "./crypto-buy";
7
7
  import cryptoSellReducer from "./crypto-sell";
8
8
  import fundReducer from "./fund";
9
+ import profileReducer from "./profile";
9
10
 
10
11
  const rootReducer = combineReducers({
11
12
  ["crypto-withdrawals"]: cryptoWithdrawalsReducer,
@@ -18,6 +19,7 @@ const rootReducer = combineReducers({
18
19
  ["csp-fiat-withdrawals"]: fiatWithdrawalsReducer,
19
20
  ["csp-crypto-sell"]: cryptoSellReducer,
20
21
  ["fund"]: fundReducer,
22
+ ["profile"]: profileReducer,
21
23
  });
22
24
 
23
25
  export default rootReducer;
@@ -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 ProfileState {
10
+ jwt: string;
11
+ isAppLoaded: boolean;
12
+ isAppActive: boolean;
13
+ }
14
+
15
+ export interface ProfileAction {
16
+ type: string;
17
+ jwt?: string;
18
+ isAppActive?: boolean;
19
+ isAppLoaded?: boolean;
20
+ }
21
+
22
+ const INITIAL_STATE: ProfileState = {
23
+ jwt: "",
24
+ isAppActive: false,
25
+ isAppLoaded: false
26
+ }
27
+
28
+ const applySetIsAppActive = (state: ProfileState, action: ProfileAction) : ProfileState => {
29
+ return {
30
+ ...state,
31
+ isAppActive: !!action.isAppActive,
32
+ }
33
+ }
34
+
35
+ const applySetSendJWTToApp = (state: ProfileState, action: ProfileAction) : ProfileState => {
36
+ return {
37
+ ...state,
38
+ isAppLoaded: !!action.isAppLoaded,
39
+ }
40
+ }
41
+
42
+ const applySetJWT = (state: ProfileState, action: ProfileAction) : ProfileState => {
43
+ return {
44
+ ...state,
45
+ jwt: action.jwt as string,
46
+ }
47
+ }
48
+
49
+ const reducerMap: { [actionType: string]: (state: ProfileState, action: ProfileAction) => ProfileState } = {
50
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_SET_JWT}`]: applySetJWT,
51
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
52
+ [`${appIdentifierToActionPrefixMap.get(AppIdentifier.PROFILE)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
53
+ };
54
+
55
+ const profileReducer = (state = INITIAL_STATE, action: ProfileAction) => {
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 profileReducer;
package/src/types.ts CHANGED
@@ -74,6 +74,12 @@ export interface IInitializeParameters {
74
74
  * perform Fund operations.
75
75
  */
76
76
  fundJWT?: string
77
+ /**
78
+ * profileJWT is the JWT that you received from
79
+ * the ZeroHash HTTP API and have specific permissions to
80
+ * perform Profile operations.
81
+ */
82
+ profileJWT?: string
77
83
  /**
78
84
  * zeroHashAppsURL is the base URL for all our Apps.
79
85
  * It defaults to https://web-sdk.zerohash.com/ and will
@@ -255,6 +261,21 @@ export enum IncomingMessageType {
255
261
  * Fund flow has failed.
256
262
  */
257
263
  FundFailed = "FUND_FAILED",
264
+ /**
265
+ * ProfileAppLoaded is received when the Profile
266
+ * app has initialized.
267
+ */
268
+ ProfileAppLoaded = "PROFILE_APP_LOADED",
269
+ /**
270
+ * ProfileCloseButtonClicked is received when the close button
271
+ * has been clicked in the Profile app
272
+ */
273
+ ProfileCloseButtonClicked = "PROFILE_CLOSE_BUTTON_CLICKED",
274
+ /**
275
+ * ProfileFailed is received when the
276
+ * Profile flow has failed.
277
+ */
278
+ ProfileFailed = "PROFILE_FAILED",
258
279
  }
259
280
 
260
281
  /**
@@ -300,7 +321,8 @@ export enum AppIdentifier {
300
321
  CSP_CRYPTO_WITHDRAWALS = "csp-crypto-withdrawals",
301
322
  CSP_FIAT_WITHDRAWALS = "csp-fiat-withdrawals",
302
323
  CSP_CRYPTO_SELL = "csp-crypto-sell",
303
- FUND = "fund"
324
+ FUND = "fund",
325
+ PROFILE = "profile"
304
326
  }
305
327
 
306
328
  /**
@@ -319,6 +341,7 @@ export const appIdentifierToActionPrefixMap = new Map(
319
341
  [AppIdentifier.CSP_CRYPTO_SELL, "CRYPTO_SELL_"],
320
342
  [AppIdentifier.CSP_CRYPTO_SELL, "CRYPTO_SELL_"],
321
343
  [AppIdentifier.FUND, "FUND_"],
344
+ [AppIdentifier.PROFILE, "PROFILE_"],
322
345
  ])
323
346
 
324
347
  export interface ISetJWTParameters {
@@ -1,57 +0,0 @@
1
- name: "Release"
2
-
3
- on:
4
- push:
5
- tags:
6
- - "*"
7
-
8
- jobs:
9
- release:
10
- name: Release
11
- env:
12
- NODE_VERSION: '16.13.0'
13
- runs-on: ["builder","x64","linux","self-hosted"]
14
- steps:
15
- - uses: actions/checkout@v3
16
-
17
- - uses: actions/setup-node@v3
18
- with:
19
- node-version: ${{ env.NODE_VERSION }}
20
- cache: 'npm'
21
-
22
- - name: NPM CI
23
- run: npm ci
24
-
25
- - name: NPM Build
26
- run: echo "BUILD=$(npm run build:zip | grep Zipping | awk '{print $3}') " >> $GITHUB_OUTPUT
27
- id: build
28
-
29
- - name: Create a GitHub release
30
- uses: ncipollo/release-action@v1
31
- with:
32
- tag: ${{ github.ref_name }}
33
- name: Release ${{ github.ref_name }}
34
- body: |
35
- ${{ github.ref.outputs.changelog }}
36
- generateReleaseNotes: true
37
- token: ${{ secrets.GITHUB_TOKEN }}
38
- artifacts: |
39
- ${{ steps.build.outputs.BUILD }}
40
-
41
- publish:
42
- name: Publish
43
- env:
44
- NODE_VERSION: '16.13.0'
45
- runs-on: ["builder","x64","linux","self-hosted"]
46
- steps:
47
- - uses: actions/checkout@v3
48
- - uses: actions/setup-node@v3
49
- with:
50
- node-version: ${{ env.NODE_VERSION }}
51
- cache: 'npm'
52
- registry-url: 'https://registry.npmjs.org'
53
- - name: NPM CI
54
- run: npm ci
55
- - run: npm publish
56
- env:
57
- NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}