zh-web-sdk 2.0.1 → 2.1.2
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/README.md +13 -6
- package/dist/iframe-container/constants.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +4 -4
- package/dist/redux/reducers/ach-deposits.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +1 -0
- package/dist/redux/store/index.d.ts +1 -0
- package/dist/types.d.ts +19 -2
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +19 -2
- package/src/iframe-container/constants.ts +7 -2
- package/src/index.tsx +15 -0
- package/src/redux/reducers/ach-deposits.ts +64 -0
- package/src/redux/reducers/index.ts +2 -0
- package/src/types.ts +19 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IAchDepositsState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IAchDepositsAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const achDepositsReducer: (state: IAchDepositsState | undefined, action: IAchDepositsAction) => IAchDepositsState;
|
|
13
|
+
export default achDepositsReducer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const rootReducer: import("redux").Reducer<import("redux").CombinedState<{
|
|
2
2
|
"crypto-withdrawals": import("./crypto-withdrawals").ICryptoWithdrawalsState;
|
|
3
3
|
onboarding: import("./onboarding").IOnboardingState;
|
|
4
|
+
"ach-deposits": import("./ach-deposits").IAchDepositsState;
|
|
4
5
|
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
5
6
|
export default rootReducer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const store: import("redux").Store<import("redux").EmptyObject & {
|
|
2
2
|
"crypto-withdrawals": import("../reducers/crypto-withdrawals").ICryptoWithdrawalsState;
|
|
3
3
|
onboarding: import("../reducers/onboarding").IOnboardingState;
|
|
4
|
+
"ach-deposits": import("../reducers/ach-deposits").IAchDepositsState;
|
|
4
5
|
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
5
6
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export interface IInitializeParameters {
|
|
|
42
42
|
* perform crypto withdrawals.
|
|
43
43
|
*/
|
|
44
44
|
cryptoWithdrawalsJWT?: string;
|
|
45
|
+
/**
|
|
46
|
+
* achDepositsJWT is the JWT that you received from
|
|
47
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
48
|
+
* perform ACH Deposits.
|
|
49
|
+
*/
|
|
50
|
+
achDepositsJWT?: string;
|
|
45
51
|
/**
|
|
46
52
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
47
53
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -94,7 +100,17 @@ export declare enum IncomingMessageType {
|
|
|
94
100
|
* CryptoWithdrawalsCloseButtonClicked is received when the close button
|
|
95
101
|
* has been clicked in the Crypto Withdrawals app
|
|
96
102
|
*/
|
|
97
|
-
CryptoWithdrawalsCloseButtonClicked = "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED"
|
|
103
|
+
CryptoWithdrawalsCloseButtonClicked = "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
104
|
+
/**
|
|
105
|
+
* AchDepositsAppLoaded is received when the crypto
|
|
106
|
+
* withdrawals app has initialized.
|
|
107
|
+
*/
|
|
108
|
+
AchDepositsAppLoaded = "ACH_DEPOSITS_APP_LOADED",
|
|
109
|
+
/**
|
|
110
|
+
* AchDepositsCloseButtonClicked is received when the close button
|
|
111
|
+
* has been clicked in the ACH Deposits app
|
|
112
|
+
*/
|
|
113
|
+
AchDepositsCloseButtonClicked = "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED"
|
|
98
114
|
}
|
|
99
115
|
/**
|
|
100
116
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -128,7 +144,8 @@ export interface IZeroHashSDK {
|
|
|
128
144
|
*/
|
|
129
145
|
export declare enum AppIdentifier {
|
|
130
146
|
ONBOARDING = "onboarding",
|
|
131
|
-
CRYPTO_WITHDRAWALS = "crypto-withdrawals"
|
|
147
|
+
CRYPTO_WITHDRAWALS = "crypto-withdrawals",
|
|
148
|
+
ACH_DEPOSITS = "ach-deposits"
|
|
132
149
|
}
|
|
133
150
|
/**
|
|
134
151
|
* Map that maps the app AppIdentifier to the redux action prefix
|
package/package.json
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
appWrapperHiddenStyle,
|
|
14
14
|
} from "../styles";
|
|
15
15
|
import {
|
|
16
|
-
|
|
16
|
+
MESSAGE_TYPE_SEND_JWT_TOKEN_ACH_DEPOSITS,
|
|
17
|
+
MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
|
|
17
18
|
MESSAGE_TYPE_SEND_JWT_TOKEN_WITHDRAWALS,
|
|
18
19
|
} from "./constants";
|
|
19
20
|
import { closeModal } from "../redux/actions";
|
|
@@ -38,6 +39,11 @@ interface AppContainerMappedProps {
|
|
|
38
39
|
isAppLoaded: boolean;
|
|
39
40
|
jwt: string;
|
|
40
41
|
};
|
|
42
|
+
[AppIdentifier.ACH_DEPOSITS]: {
|
|
43
|
+
isAppActive: boolean;
|
|
44
|
+
isAppLoaded: boolean;
|
|
45
|
+
jwt: string;
|
|
46
|
+
};
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
const appLoadTime = Date.now();
|
|
@@ -45,6 +51,7 @@ const appLoadTime = Date.now();
|
|
|
45
51
|
const mapAppToTitle = {
|
|
46
52
|
[AppIdentifier.ONBOARDING]: "Onboarding",
|
|
47
53
|
[AppIdentifier.CRYPTO_WITHDRAWALS]: "Crypto Withdrawals",
|
|
54
|
+
[AppIdentifier.ACH_DEPOSITS]: "ACH Deposits",
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
const AppContainer = ({
|
|
@@ -93,12 +100,21 @@ const AppContainer = ({
|
|
|
93
100
|
case AppIdentifier.ONBOARDING:
|
|
94
101
|
iRef.current.contentWindow.postMessage(
|
|
95
102
|
{
|
|
96
|
-
type:
|
|
103
|
+
type: MESSAGE_TYPE_SEND_JWT_TOKEN_ONBOARDING,
|
|
97
104
|
userOnboardingJWT: jwt,
|
|
98
105
|
},
|
|
99
106
|
zeroHashAppURL
|
|
100
107
|
);
|
|
101
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;
|
|
102
118
|
default:
|
|
103
119
|
break;
|
|
104
120
|
}
|
|
@@ -149,6 +165,7 @@ const AppContainer = ({
|
|
|
149
165
|
title={title}
|
|
150
166
|
src={iframeURL.toString()}
|
|
151
167
|
allow="camera *; fullscreen *; accelerometer *; gyroscope *; magnetometer *;"
|
|
168
|
+
sandbox="allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation"
|
|
152
169
|
style={iframeStyle}
|
|
153
170
|
/>
|
|
154
171
|
</div>
|
|
@@ -3,6 +3,11 @@ import { appIdentifierToActionPrefixMap } from "../types"
|
|
|
3
3
|
|
|
4
4
|
const ONBOARDING_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.ONBOARDING)
|
|
5
5
|
const CRYPTO_WITHDRAWALS_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_WITHDRAWALS)
|
|
6
|
+
const ACH_DEPOSITS_MESSAGE_TYPE_PREFIX = appIdentifierToActionPrefixMap.get(AppIdentifier.ACH_DEPOSITS)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
package/src/index.tsx
CHANGED
|
@@ -45,6 +45,13 @@ const appsMessageHandlers: {
|
|
|
45
45
|
[IncomingMessageType.CryptoWithdrawalsAppLoaded]: () => {
|
|
46
46
|
appLoaded(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
47
47
|
},
|
|
48
|
+
// ACH Deposits message handlers
|
|
49
|
+
[IncomingMessageType.AchDepositsCloseButtonClicked]: () => {
|
|
50
|
+
closeModal(AppIdentifier.ACH_DEPOSITS);
|
|
51
|
+
},
|
|
52
|
+
[IncomingMessageType.AchDepositsAppLoaded]: () => {
|
|
53
|
+
appLoaded(AppIdentifier.ACH_DEPOSITS);
|
|
54
|
+
},
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -79,6 +86,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
79
86
|
private initializedApps: Map<AppIdentifier, boolean> = new Map([
|
|
80
87
|
[AppIdentifier.CRYPTO_WITHDRAWALS, false],
|
|
81
88
|
[AppIdentifier.ONBOARDING, false],
|
|
89
|
+
[AppIdentifier.ACH_DEPOSITS, false],
|
|
82
90
|
]);
|
|
83
91
|
|
|
84
92
|
/**
|
|
@@ -91,6 +99,7 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
91
99
|
rootQuerySelector,
|
|
92
100
|
userOnboardingJWT,
|
|
93
101
|
cryptoWithdrawalsJWT,
|
|
102
|
+
achDepositsJWT,
|
|
94
103
|
zeroHashAppsURL,
|
|
95
104
|
}: IInitializeParameters) {
|
|
96
105
|
// The || is for backwards compatibility
|
|
@@ -116,6 +125,12 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
116
125
|
appIdentifier: AppIdentifier.CRYPTO_WITHDRAWALS,
|
|
117
126
|
});
|
|
118
127
|
}
|
|
128
|
+
if (achDepositsJWT) {
|
|
129
|
+
this.setJWT({
|
|
130
|
+
jwt: achDepositsJWT,
|
|
131
|
+
appIdentifier: AppIdentifier.ACH_DEPOSITS,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
/**
|
|
@@ -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 IAchDepositsState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IAchDepositsAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: IAchDepositsState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: IAchDepositsState, action: IAchDepositsAction) : IAchDepositsState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: IAchDepositsState, action: IAchDepositsAction) : IAchDepositsState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: IAchDepositsState, action: IAchDepositsAction) : IAchDepositsState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: IAchDepositsState, action: IAchDepositsAction) => IAchDepositsState } = {
|
|
50
|
+
// ACH Deposits reducer
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ACH_DEPOSITS)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ACH_DEPOSITS)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.ACH_DEPOSITS)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const achDepositsReducer = (state = INITIAL_STATE, action: IAchDepositsAction) => {
|
|
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 achDepositsReducer;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {combineReducers} from "redux";
|
|
2
2
|
import cryptoWithdrawalsReducer from './crypto-withdrawals'
|
|
3
3
|
import onboardingReducer from "./onboarding";
|
|
4
|
+
import achDepositsReducer from "./ach-deposits";
|
|
4
5
|
|
|
5
6
|
const rootReducer = combineReducers({
|
|
6
7
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
7
8
|
["onboarding"]: onboardingReducer,
|
|
9
|
+
["ach-deposits"]: achDepositsReducer,
|
|
8
10
|
});
|
|
9
11
|
|
|
10
12
|
export default rootReducer;
|
package/src/types.ts
CHANGED
|
@@ -44,6 +44,12 @@ export interface IInitializeParameters {
|
|
|
44
44
|
* perform crypto withdrawals.
|
|
45
45
|
*/
|
|
46
46
|
cryptoWithdrawalsJWT?: string
|
|
47
|
+
/**
|
|
48
|
+
* achDepositsJWT is the JWT that you received from
|
|
49
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
50
|
+
* perform ACH Deposits.
|
|
51
|
+
*/
|
|
52
|
+
achDepositsJWT?: string
|
|
47
53
|
/**
|
|
48
54
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
49
55
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -100,6 +106,16 @@ export enum IncomingMessageType {
|
|
|
100
106
|
* has been clicked in the Crypto Withdrawals app
|
|
101
107
|
*/
|
|
102
108
|
CryptoWithdrawalsCloseButtonClicked = "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
109
|
+
/**
|
|
110
|
+
* AchDepositsAppLoaded is received when the crypto
|
|
111
|
+
* withdrawals app has initialized.
|
|
112
|
+
*/
|
|
113
|
+
AchDepositsAppLoaded = "ACH_DEPOSITS_APP_LOADED",
|
|
114
|
+
/**
|
|
115
|
+
* AchDepositsCloseButtonClicked is received when the close button
|
|
116
|
+
* has been clicked in the ACH Deposits app
|
|
117
|
+
*/
|
|
118
|
+
AchDepositsCloseButtonClicked = "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED",
|
|
103
119
|
}
|
|
104
120
|
|
|
105
121
|
/**
|
|
@@ -138,6 +154,7 @@ export interface IZeroHashSDK {
|
|
|
138
154
|
export enum AppIdentifier {
|
|
139
155
|
ONBOARDING = "onboarding",
|
|
140
156
|
CRYPTO_WITHDRAWALS = "crypto-withdrawals",
|
|
157
|
+
ACH_DEPOSITS = "ach-deposits",
|
|
141
158
|
}
|
|
142
159
|
|
|
143
160
|
/**
|
|
@@ -146,7 +163,8 @@ export enum AppIdentifier {
|
|
|
146
163
|
export const appIdentifierToActionPrefixMap = new Map(
|
|
147
164
|
[
|
|
148
165
|
[AppIdentifier.ONBOARDING, "ONBOARDING_"],
|
|
149
|
-
[AppIdentifier.CRYPTO_WITHDRAWALS, "CRYPTO_WITHDRAWALS_"]
|
|
166
|
+
[AppIdentifier.CRYPTO_WITHDRAWALS, "CRYPTO_WITHDRAWALS_"],
|
|
167
|
+
[AppIdentifier.ACH_DEPOSITS, "ACH_DEPOSITS_"],
|
|
150
168
|
])
|
|
151
169
|
|
|
152
170
|
export interface ISetJWTParameters {
|