zh-web-sdk 2.1.4 → 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/dist/styles.d.ts CHANGED
@@ -9,7 +9,6 @@ export declare const containerMediaStyles: {
9
9
  [id: string]: CSSProperties;
10
10
  };
11
11
  export declare const appWrapperStyle: CSSProperties;
12
- export declare const height: CSSProperties;
13
12
  export declare const appWrapperHiddenStyle: CSSProperties;
14
13
  export declare const modalStyle: CSSProperties;
15
14
  export declare const iframeWrapperStyle: CSSProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zh-web-sdk",
3
- "version": "2.1.4",
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,
@@ -11,15 +11,9 @@ import {
11
11
  modalStyle,
12
12
  screenSizes,
13
13
  appWrapperHiddenStyle,
14
- height
15
14
  } from "../styles";
16
- import {
17
- MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS,
18
- MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
19
- MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS,
20
- } from "./constants";
21
15
  import { closeModal } from "../redux/actions";
22
- import { AppIdentifier } from "../types";
16
+ import { AppIdentifier, appIdentifierToActionPrefixMap } from "../types";
23
17
 
24
18
  interface AppContainerProps {
25
19
  isAppActive?: boolean;
@@ -60,12 +54,14 @@ const AppContainer = ({
60
54
  isAppLoaded,
61
55
  jwt,
62
56
  zeroHashAppURL,
63
- appIdentifier,
57
+ appIdentifier
64
58
  }: AppContainerProps) => {
65
59
  const title = mapAppToTitle[appIdentifier];
66
60
  const hasJwt = !!jwt;
67
61
  const [container, setContainerStyle] = useState(containerStyle);
68
62
 
63
+ const allAppsState = useSelector(state => state as AppContainerMappedProps);
64
+
69
65
  /**
70
66
  * setContainer sets the CSS styles based on the current matching media queries
71
67
  */
@@ -88,39 +84,21 @@ const AppContainer = ({
88
84
  hasJwt &&
89
85
  iRef.current?.contentWindow
90
86
  ) {
91
- switch (appIdentifier) {
92
- case AppIdentifier.CRYPTO_WITHDRAWALS:
93
- iRef.current.contentWindow.postMessage(
94
- {
95
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS,
96
- cryptoWithdrawalsJWT: jwt,
97
- },
98
- zeroHashAppURL
99
- );
100
- break;
101
- case AppIdentifier.ONBOARDING:
102
- iRef.current.contentWindow.postMessage(
103
- {
104
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
105
- userOnboardingJWT: jwt,
106
- },
107
- zeroHashAppURL
108
- );
109
- break;
110
- case AppIdentifier.ACH_DEPOSITS:
111
- iRef.current.contentWindow.postMessage(
112
- {
113
- type: MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS,
114
- achDepositsJWT: jwt,
115
- },
116
- zeroHashAppURL
117
- );
118
- break;
119
- default:
120
- break;
121
- }
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
+ })
122
100
  }
123
- }, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL]);
101
+ }, [appIdentifier, hasJwt, isAppLoaded, jwt, zeroHashAppURL, allAppsState]);
124
102
 
125
103
  useEffect(() => {
126
104
  // set the styles when the screen size changes
@@ -149,7 +127,6 @@ const AppContainer = ({
149
127
  <div
150
128
  style={isAppActive ? {
151
129
  ...appWrapperStyle,
152
- ...height
153
130
  } : appWrapperHiddenStyle}
154
131
  onClick={() => closeModal(appIdentifier)}
155
132
  >
package/src/styles.ts CHANGED
@@ -48,15 +48,12 @@ export const appWrapperStyle: CSSProperties = {
48
48
  alignItems: "center",
49
49
  flexDirection: "column",
50
50
  width: "100vw",
51
- height: "100vh",
51
+ height: CSS.supports("height: 100dvh") ? "100dvh" : window.innerHeight + "px",
52
+ maxHeight: window.innerHeight + "px",
52
53
  background: "rgba(0,0,0,0.5)",
53
54
  cursor: "pointer",
54
55
  }
55
56
 
56
- export const height: CSSProperties = {
57
- height: "100dvh",
58
- }
59
-
60
57
  export const appWrapperHiddenStyle: CSSProperties = {
61
58
  display: "none",
62
59
  width: 0,
@@ -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