zh-web-sdk 2.1.5 → 2.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zh-web-sdk",
3
- "version": "2.1.5",
3
+ "version": "2.2.0",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef, useState } from "react";
2
- import { connect } from "react-redux";
2
+ import { connect, useSelector } from "react-redux";
3
3
 
4
4
  import {
5
5
  appWrapperStyle,
@@ -12,13 +12,8 @@ import {
12
12
  screenSizes,
13
13
  appWrapperHiddenStyle,
14
14
  } from "../styles";
15
- import {
16
- MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS,
17
- MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
18
- MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS,
19
- } from "./constants";
20
15
  import { closeModal } from "../redux/actions";
21
- import { AppIdentifier } from "../types";
16
+ import { AppIdentifier, appIdentifierToActionPrefixMap } from "../types";
22
17
 
23
18
  interface AppContainerProps {
24
19
  isAppActive?: boolean;
@@ -59,12 +54,14 @@ const AppContainer = ({
59
54
  isAppLoaded,
60
55
  jwt,
61
56
  zeroHashAppURL,
62
- appIdentifier,
57
+ appIdentifier
63
58
  }: AppContainerProps) => {
64
59
  const title = mapAppToTitle[appIdentifier];
65
60
  const hasJwt = !!jwt;
66
61
  const [container, setContainerStyle] = useState(containerStyle);
67
62
 
63
+ const allAppsState = useSelector(state => state as AppContainerMappedProps);
64
+
68
65
  /**
69
66
  * setContainer sets the CSS styles based on the current matching media queries
70
67
  */
@@ -87,39 +84,21 @@ const AppContainer = ({
87
84
  hasJwt &&
88
85
  iRef.current?.contentWindow
89
86
  ) {
90
- switch (appIdentifier) {
91
- case AppIdentifier.CRYPTO_WITHDRAWALS:
92
- iRef.current.contentWindow.postMessage(
93
- {
94
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS,
95
- cryptoWithdrawalsJWT: jwt,
96
- },
97
- zeroHashAppURL
98
- );
99
- break;
100
- case AppIdentifier.ONBOARDING:
101
- iRef.current.contentWindow.postMessage(
102
- {
103
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
104
- userOnboardingJWT: jwt,
105
- },
106
- zeroHashAppURL
107
- );
108
- break;
109
- case AppIdentifier.ACH_DEPOSITS:
110
- iRef.current.contentWindow.postMessage(
111
- {
112
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS,
113
- achDepositsJWT: jwt,
114
- },
115
- zeroHashAppURL
116
- );
117
- break;
118
- default:
119
- break;
120
- }
87
+
88
+ // This loops all registered apps and sends their JWT tokens.
89
+ Object.keys(allAppsState).forEach((key: string) => {
90
+ if (!allAppsState[key as AppIdentifier].jwt) return;
91
+
92
+ iRef.current?.contentWindow?.postMessage(
93
+ {
94
+ type: `${appIdentifierToActionPrefixMap.get(key as AppIdentifier)}SEND_JWT_TOKEN`,
95
+ jwt: allAppsState[key as AppIdentifier].jwt,
96
+ },
97
+ zeroHashAppURL
98
+ );
99
+ })
121
100
  }
122
- }, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL]);
101
+ }, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL, allAppsState]);
123
102
 
124
103
  useEffect(() => {
125
104
  // set the styles when the screen size changes
@@ -1,3 +0,0 @@
1
- export declare const MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING: string;
2
- export declare const MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS: string;
3
- export declare const MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS: string;
@@ -1,13 +0,0 @@
1
- import { AppIdentifier } from "../types"
2
- import { appIdentifierToActionPrefixMap } from "../types"
3
-
4
- const ONBOARDING_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)
5
- const CRYPTO_WITHDRAWALS_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_WITHDRAWALS)
6
- const ACH_DEPOSITS_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.ACH_DEPOSITS)
7
-
8
- const SEND_JWT_TOKEN = "SEND_JWT_TOKEN"
9
-
10
-
11
- export const MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING = ONBOARDING_MESSAGE_TYPE_PREFIX + SEND_JWT_TOKEN
12
- export const MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS = CRYPTO_WITHDRAWALS_MESSAGE_TYPE_PREFIX + SEND_JWT_TOKEN
13
- export const MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS = ACH_DEPOSITS_MESSAGE_TYPE_PREFIX + SEND_JWT_TOKEN