zh-web-sdk 2.2.0 → 2.3.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/README.md +24 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +4 -4
- package/dist/redux/reducers/crypto-buy.d.ts +13 -0
- package/dist/redux/reducers/crypto-sell.d.ts +13 -0
- package/dist/redux/reducers/fiat-withdrawals.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +3 -0
- package/dist/redux/store/index.d.ts +3 -0
- package/dist/types.d.ts +55 -4
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +18 -0
- package/src/index.tsx +52 -7
- package/src/redux/reducers/crypto-buy.ts +64 -0
- package/src/redux/reducers/crypto-sell.ts +64 -0
- package/src/redux/reducers/fiat-withdrawals.ts +64 -0
- package/src/redux/reducers/index.ts +6 -0
- package/src/types.ts +56 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ICryptoBuyState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ICryptoBuyAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const cryptoBuyReducer: (state: ICryptoBuyState | undefined, action: ICryptoBuyAction) => ICryptoBuyState;
|
|
13
|
+
export default cryptoBuyReducer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ICryptoSellState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ICryptoSellAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const cryptoSellReducer: (state: ICryptoSellState | undefined, action: ICryptoSellAction) => ICryptoSellState;
|
|
13
|
+
export default cryptoSellReducer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IFiatWithdrawalsState {
|
|
2
|
+
jwt: string;
|
|
3
|
+
isAppLoaded: boolean;
|
|
4
|
+
isAppActive: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IFiatWithdrawalsAction {
|
|
7
|
+
type: string;
|
|
8
|
+
jwt?: string;
|
|
9
|
+
isAppActive?: boolean;
|
|
10
|
+
isAppLoaded?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const fiatWithdrawalsReducer: (state: IFiatWithdrawalsState | undefined, action: IFiatWithdrawalsAction) => IFiatWithdrawalsState;
|
|
13
|
+
export default fiatWithdrawalsReducer;
|
|
@@ -2,5 +2,8 @@ declare const rootReducer: import("redux").Reducer<import("redux").CombinedState
|
|
|
2
2
|
"crypto-withdrawals": import("./crypto-withdrawals").ICryptoWithdrawalsState;
|
|
3
3
|
onboarding: import("./onboarding").IOnboardingState;
|
|
4
4
|
"ach-deposits": import("./ach-deposits").IAchDepositsState;
|
|
5
|
+
"fiat-withdrawals": import("./fiat-withdrawals").IFiatWithdrawalsState;
|
|
6
|
+
"crypto-buy": import("./crypto-buy").ICryptoBuyState;
|
|
7
|
+
"crypto-sell": import("./crypto-sell").ICryptoSellState;
|
|
5
8
|
}>, import("./crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
6
9
|
export default rootReducer;
|
|
@@ -2,5 +2,8 @@ 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
4
|
"ach-deposits": import("../reducers/ach-deposits").IAchDepositsState;
|
|
5
|
+
"fiat-withdrawals": import("../reducers/fiat-withdrawals").IFiatWithdrawalsState;
|
|
6
|
+
"crypto-buy": import("../reducers/crypto-buy").ICryptoBuyState;
|
|
7
|
+
"crypto-sell": import("../reducers/crypto-sell").ICryptoSellState;
|
|
5
8
|
}, import("../reducers/crypto-withdrawals").ICryptoWithdrawalsAction>;
|
|
6
9
|
export default store;
|
package/dist/types.d.ts
CHANGED
|
@@ -48,6 +48,24 @@ export interface IInitializeParameters {
|
|
|
48
48
|
* perform ACH Deposits.
|
|
49
49
|
*/
|
|
50
50
|
achDepositsJWT?: string;
|
|
51
|
+
/**
|
|
52
|
+
* fiatWithdrawalsJWT is the JWT that you received from
|
|
53
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
54
|
+
* perform Fiat Withdrawals.
|
|
55
|
+
*/
|
|
56
|
+
fiatWithdrawalsJWT?: string;
|
|
57
|
+
/**
|
|
58
|
+
* cryptoBuyJWT is the JWT that you received from
|
|
59
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
60
|
+
* perform Crypto Buy.
|
|
61
|
+
*/
|
|
62
|
+
cryptoBuyJWT?: string;
|
|
63
|
+
/**
|
|
64
|
+
* cryptoSellJWT is the JWT that you received from
|
|
65
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
66
|
+
* perform Crypto Sell.
|
|
67
|
+
*/
|
|
68
|
+
cryptoSellJWT?: string;
|
|
51
69
|
/**
|
|
52
70
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
53
71
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -102,15 +120,45 @@ export declare enum IncomingMessageType {
|
|
|
102
120
|
*/
|
|
103
121
|
CryptoWithdrawalsCloseButtonClicked = "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
104
122
|
/**
|
|
105
|
-
* AchDepositsAppLoaded is received when the
|
|
106
|
-
*
|
|
123
|
+
* AchDepositsAppLoaded is received when the ACH
|
|
124
|
+
* deposits app has initialized.
|
|
107
125
|
*/
|
|
108
126
|
AchDepositsAppLoaded = "ACH_DEPOSITS_APP_LOADED",
|
|
109
127
|
/**
|
|
110
128
|
* AchDepositsCloseButtonClicked is received when the close button
|
|
111
129
|
* has been clicked in the ACH Deposits app
|
|
112
130
|
*/
|
|
113
|
-
AchDepositsCloseButtonClicked = "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED"
|
|
131
|
+
AchDepositsCloseButtonClicked = "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED",
|
|
132
|
+
/**
|
|
133
|
+
* FiatWithdrawalsAppLoaded is received when the Fiat
|
|
134
|
+
* withdrawals app has initialized.
|
|
135
|
+
*/
|
|
136
|
+
FiatWithdrawalsAppLoaded = "FIAT_WITHDRAWALS_APP_LOADED",
|
|
137
|
+
/**
|
|
138
|
+
* FiatWithdrawalsCloseButtonClicked is received when the close button
|
|
139
|
+
* has been clicked in the Fiat Withdrawals app
|
|
140
|
+
*/
|
|
141
|
+
FiatWithdrawalsCloseButtonClicked = "FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
142
|
+
/**
|
|
143
|
+
* CryptoBuyAppLoaded is received when the Crypto
|
|
144
|
+
* buy app has initialized.
|
|
145
|
+
*/
|
|
146
|
+
CryptoBuyAppLoaded = "CRYPTO_BUY_APP_LOADED",
|
|
147
|
+
/**
|
|
148
|
+
* CryptoBuyCloseButtonClicked is received when the close button
|
|
149
|
+
* has been clicked in the Crypto buy app
|
|
150
|
+
*/
|
|
151
|
+
CryptoBuyCloseButtonClicked = "CRYPTO_BUY_CLOSE_BUTTON_CLICKED",
|
|
152
|
+
/**
|
|
153
|
+
* CryptoSellAppLoaded is received when the Crypto
|
|
154
|
+
* sell app has initialized.
|
|
155
|
+
*/
|
|
156
|
+
CryptoSellAppLoaded = "CRYPTO_SELL_APP_LOADED",
|
|
157
|
+
/**
|
|
158
|
+
* CryptoSellCloseButtonClicked is received when the close button
|
|
159
|
+
* has been clicked in the Crypto sell app
|
|
160
|
+
*/
|
|
161
|
+
CryptoSellCloseButtonClicked = "CRYPTO_SELL_CLOSE_BUTTON_CLICKED"
|
|
114
162
|
}
|
|
115
163
|
/**
|
|
116
164
|
* IncomingMessage defines the structure of an incoming
|
|
@@ -145,7 +193,10 @@ export interface IZeroHashSDK {
|
|
|
145
193
|
export declare enum AppIdentifier {
|
|
146
194
|
ONBOARDING = "onboarding",
|
|
147
195
|
CRYPTO_WITHDRAWALS = "crypto-withdrawals",
|
|
148
|
-
ACH_DEPOSITS = "ach-deposits"
|
|
196
|
+
ACH_DEPOSITS = "ach-deposits",
|
|
197
|
+
FIAT_WITHDRAWALS = "fiat-withdrawals",
|
|
198
|
+
CRYPTO_BUY = "crypto-buy",
|
|
199
|
+
CRYPTO_SELL = "crypto-sell"
|
|
149
200
|
}
|
|
150
201
|
/**
|
|
151
202
|
* Map that maps the app AppIdentifier to the redux action prefix
|
package/package.json
CHANGED
|
@@ -39,6 +39,21 @@ interface AppContainerMappedProps {
|
|
|
39
39
|
isAppLoaded: boolean;
|
|
40
40
|
jwt: string;
|
|
41
41
|
};
|
|
42
|
+
[AppIdentifier.FIAT_WITHDRAWALS]: {
|
|
43
|
+
isAppActive: boolean;
|
|
44
|
+
isAppLoaded: boolean;
|
|
45
|
+
jwt: string;
|
|
46
|
+
};
|
|
47
|
+
[AppIdentifier.CRYPTO_BUY]: {
|
|
48
|
+
isAppActive: boolean;
|
|
49
|
+
isAppLoaded: boolean;
|
|
50
|
+
jwt: string;
|
|
51
|
+
};
|
|
52
|
+
[AppIdentifier.CRYPTO_SELL]: {
|
|
53
|
+
isAppActive: boolean;
|
|
54
|
+
isAppLoaded: boolean;
|
|
55
|
+
jwt: string;
|
|
56
|
+
};
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
const appLoadTime = Date.now();
|
|
@@ -47,6 +62,9 @@ const mapAppToTitle = {
|
|
|
47
62
|
[AppIdentifier.ONBOARDING]: "Onboarding",
|
|
48
63
|
[AppIdentifier.CRYPTO_WITHDRAWALS]: "Crypto Withdrawals",
|
|
49
64
|
[AppIdentifier.ACH_DEPOSITS]: "ACH Deposits",
|
|
65
|
+
[AppIdentifier.FIAT_WITHDRAWALS]: "Fiat Withdrawals",
|
|
66
|
+
[AppIdentifier.CRYPTO_BUY]: "Crypto Buy",
|
|
67
|
+
[AppIdentifier.CRYPTO_SELL]: "Crypto Sell",
|
|
50
68
|
};
|
|
51
69
|
|
|
52
70
|
const AppContainer = ({
|
package/src/index.tsx
CHANGED
|
@@ -45,13 +45,34 @@ const appsMessageHandlers: {
|
|
|
45
45
|
[IncomingMessageType.CryptoWithdrawalsAppLoaded]: () => {
|
|
46
46
|
appLoaded(AppIdentifier.CRYPTO_WITHDRAWALS);
|
|
47
47
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
// ACH Deposits message handlers
|
|
49
|
+
[IncomingMessageType.AchDepositsCloseButtonClicked]: () => {
|
|
50
|
+
closeModal(AppIdentifier.ACH_DEPOSITS);
|
|
51
|
+
},
|
|
52
|
+
[IncomingMessageType.AchDepositsAppLoaded]: () => {
|
|
53
|
+
appLoaded(AppIdentifier.ACH_DEPOSITS);
|
|
54
|
+
},
|
|
55
|
+
// Fiat Withdrawals message handlers
|
|
56
|
+
[IncomingMessageType.FiatWithdrawalsCloseButtonClicked]: () => {
|
|
57
|
+
closeModal(AppIdentifier.FIAT_WITHDRAWALS);
|
|
58
|
+
},
|
|
59
|
+
[IncomingMessageType.FiatWithdrawalsAppLoaded]: () => {
|
|
60
|
+
appLoaded(AppIdentifier.FIAT_WITHDRAWALS);
|
|
61
|
+
},
|
|
62
|
+
// Crypto buy message handlers
|
|
63
|
+
[IncomingMessageType.CryptoBuyCloseButtonClicked]: () => {
|
|
64
|
+
closeModal(AppIdentifier.CRYPTO_BUY);
|
|
65
|
+
},
|
|
66
|
+
[IncomingMessageType.CryptoBuyAppLoaded]: () => {
|
|
67
|
+
appLoaded(AppIdentifier.CRYPTO_BUY);
|
|
68
|
+
},
|
|
69
|
+
// Crypto sell message handlers
|
|
70
|
+
[IncomingMessageType.CryptoSellCloseButtonClicked]: () => {
|
|
71
|
+
closeModal(AppIdentifier.CRYPTO_SELL);
|
|
72
|
+
},
|
|
73
|
+
[IncomingMessageType.CryptoSellAppLoaded]: () => {
|
|
74
|
+
appLoaded(AppIdentifier.CRYPTO_SELL);
|
|
75
|
+
},
|
|
55
76
|
};
|
|
56
77
|
|
|
57
78
|
/**
|
|
@@ -87,6 +108,9 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
87
108
|
[AppIdentifier.CRYPTO_WITHDRAWALS, false],
|
|
88
109
|
[AppIdentifier.ONBOARDING, false],
|
|
89
110
|
[AppIdentifier.ACH_DEPOSITS, false],
|
|
111
|
+
[AppIdentifier.FIAT_WITHDRAWALS, false],
|
|
112
|
+
[AppIdentifier.CRYPTO_BUY, false],
|
|
113
|
+
[AppIdentifier.CRYPTO_SELL, false],
|
|
90
114
|
]);
|
|
91
115
|
|
|
92
116
|
/**
|
|
@@ -100,6 +124,9 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
100
124
|
userOnboardingJWT,
|
|
101
125
|
cryptoWithdrawalsJWT,
|
|
102
126
|
achDepositsJWT,
|
|
127
|
+
fiatWithdrawalsJWT,
|
|
128
|
+
cryptoBuyJWT,
|
|
129
|
+
cryptoSellJWT,
|
|
103
130
|
zeroHashAppsURL,
|
|
104
131
|
}: IInitializeParameters) {
|
|
105
132
|
// The || is for backwards compatibility
|
|
@@ -131,6 +158,24 @@ export class ZeroHashSDK implements IZeroHashSDK {
|
|
|
131
158
|
appIdentifier: AppIdentifier.ACH_DEPOSITS,
|
|
132
159
|
});
|
|
133
160
|
}
|
|
161
|
+
if (fiatWithdrawalsJWT) {
|
|
162
|
+
this.setJWT({
|
|
163
|
+
jwt: fiatWithdrawalsJWT,
|
|
164
|
+
appIdentifier: AppIdentifier.FIAT_WITHDRAWALS,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (cryptoBuyJWT) {
|
|
168
|
+
this.setJWT({
|
|
169
|
+
jwt: cryptoBuyJWT,
|
|
170
|
+
appIdentifier: AppIdentifier.CRYPTO_BUY,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (cryptoSellJWT) {
|
|
174
|
+
this.setJWT({
|
|
175
|
+
jwt: cryptoSellJWT,
|
|
176
|
+
appIdentifier: AppIdentifier.CRYPTO_SELL,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
134
179
|
}
|
|
135
180
|
|
|
136
181
|
/**
|
|
@@ -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 ICryptoBuyState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ICryptoBuyAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: ICryptoBuyState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: ICryptoBuyState, action: ICryptoBuyAction) : ICryptoBuyState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: ICryptoBuyState, action: ICryptoBuyAction) : ICryptoBuyState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: ICryptoBuyState, action: ICryptoBuyAction) : ICryptoBuyState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: ICryptoBuyState, action: ICryptoBuyAction) => ICryptoBuyState } = {
|
|
50
|
+
// Crypto buy reducer
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_BUY)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const cryptoBuyReducer = (state = INITIAL_STATE, action: ICryptoBuyAction) => {
|
|
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 cryptoBuyReducer;
|
|
@@ -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 ICryptoSellState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ICryptoSellAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: ICryptoSellState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: ICryptoSellState, action: ICryptoSellAction) : ICryptoSellState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: ICryptoSellState, action: ICryptoSellAction) : ICryptoSellState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: ICryptoSellState, action: ICryptoSellAction) : ICryptoSellState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: ICryptoSellState, action: ICryptoSellAction) => ICryptoSellState } = {
|
|
50
|
+
// Crypto sell reducer
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_SELL)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_SELL)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.CRYPTO_SELL)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const cryptoSellReducer = (state = INITIAL_STATE, action: ICryptoSellAction) => {
|
|
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 cryptoSellReducer;
|
|
@@ -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 IFiatWithdrawalsState {
|
|
10
|
+
jwt: string;
|
|
11
|
+
isAppLoaded: boolean;
|
|
12
|
+
isAppActive: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IFiatWithdrawalsAction {
|
|
16
|
+
type: string;
|
|
17
|
+
jwt?: string;
|
|
18
|
+
isAppActive?: boolean;
|
|
19
|
+
isAppLoaded?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INITIAL_STATE: IFiatWithdrawalsState = {
|
|
23
|
+
jwt: "",
|
|
24
|
+
isAppActive: false,
|
|
25
|
+
isAppLoaded: false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applySetIsAppActive = (state: IFiatWithdrawalsState, action: IFiatWithdrawalsAction) : IFiatWithdrawalsState => {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
isAppActive: !!action.isAppActive,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const applySetSendJWTToApp = (state: IFiatWithdrawalsState, action: IFiatWithdrawalsAction) : IFiatWithdrawalsState => {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isAppLoaded: !!action.isAppLoaded,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const applySetJWT = (state: IFiatWithdrawalsState, action: IFiatWithdrawalsAction) : IFiatWithdrawalsState => {
|
|
43
|
+
return {
|
|
44
|
+
...state,
|
|
45
|
+
jwt: action.jwt as string,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reducerMap: { [actionType: string]: (state: IFiatWithdrawalsState, action: IFiatWithdrawalsAction) => IFiatWithdrawalsState } = {
|
|
50
|
+
// Fiat Withdrawals reducer
|
|
51
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_WITHDRAWALS)}${ACTION_SET_JWT}`]: applySetJWT,
|
|
52
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_WITHDRAWALS)}${ACTION_SET_MODAL_STATE}`]: applySetIsAppActive,
|
|
53
|
+
[`${appIdentifierToActionPrefixMap.get(AppIdentifier.FIAT_WITHDRAWALS)}${ACTION_APP_LOADED}`]: applySetSendJWTToApp,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const fiatWithdrawalsReducer = (state = INITIAL_STATE, action: IFiatWithdrawalsAction) => {
|
|
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 fiatWithdrawalsReducer;
|
|
@@ -2,11 +2,17 @@ import {combineReducers} from "redux";
|
|
|
2
2
|
import cryptoWithdrawalsReducer from './crypto-withdrawals'
|
|
3
3
|
import onboardingReducer from "./onboarding";
|
|
4
4
|
import achDepositsReducer from "./ach-deposits";
|
|
5
|
+
import fiatWithdrawalsReducer from "./fiat-withdrawals";
|
|
6
|
+
import cryptoBuyReducer from "./crypto-buy";
|
|
7
|
+
import cryptoSellReducer from "./crypto-sell";
|
|
5
8
|
|
|
6
9
|
const rootReducer = combineReducers({
|
|
7
10
|
["crypto-withdrawals"]: cryptoWithdrawalsReducer,
|
|
8
11
|
["onboarding"]: onboardingReducer,
|
|
9
12
|
["ach-deposits"]: achDepositsReducer,
|
|
13
|
+
["fiat-withdrawals"]: fiatWithdrawalsReducer,
|
|
14
|
+
["crypto-buy"]: cryptoBuyReducer,
|
|
15
|
+
["crypto-sell"]: cryptoSellReducer,
|
|
10
16
|
});
|
|
11
17
|
|
|
12
18
|
export default rootReducer;
|
package/src/types.ts
CHANGED
|
@@ -50,6 +50,24 @@ export interface IInitializeParameters {
|
|
|
50
50
|
* perform ACH Deposits.
|
|
51
51
|
*/
|
|
52
52
|
achDepositsJWT?: string
|
|
53
|
+
/**
|
|
54
|
+
* fiatWithdrawalsJWT is the JWT that you received from
|
|
55
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
56
|
+
* perform Fiat Withdrawals.
|
|
57
|
+
*/
|
|
58
|
+
fiatWithdrawalsJWT?: string
|
|
59
|
+
/**
|
|
60
|
+
* cryptoBuyJWT is the JWT that you received from
|
|
61
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
62
|
+
* perform Crypto Buy.
|
|
63
|
+
*/
|
|
64
|
+
cryptoBuyJWT?: string
|
|
65
|
+
/**
|
|
66
|
+
* cryptoSellJWT is the JWT that you received from
|
|
67
|
+
* the ZeroHash HTTP API and have specific permissions to
|
|
68
|
+
* perform Crypto Sell.
|
|
69
|
+
*/
|
|
70
|
+
cryptoSellJWT?: string
|
|
53
71
|
/**
|
|
54
72
|
* zeroHashAppsURL is the base URL for all our Apps.
|
|
55
73
|
* It defaults to https://web-sdk.zerohash.com/ and will
|
|
@@ -107,8 +125,8 @@ export enum IncomingMessageType {
|
|
|
107
125
|
*/
|
|
108
126
|
CryptoWithdrawalsCloseButtonClicked = "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
109
127
|
/**
|
|
110
|
-
* AchDepositsAppLoaded is received when the
|
|
111
|
-
*
|
|
128
|
+
* AchDepositsAppLoaded is received when the ACH
|
|
129
|
+
* deposits app has initialized.
|
|
112
130
|
*/
|
|
113
131
|
AchDepositsAppLoaded = "ACH_DEPOSITS_APP_LOADED",
|
|
114
132
|
/**
|
|
@@ -116,6 +134,36 @@ export enum IncomingMessageType {
|
|
|
116
134
|
* has been clicked in the ACH Deposits app
|
|
117
135
|
*/
|
|
118
136
|
AchDepositsCloseButtonClicked = "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED",
|
|
137
|
+
/**
|
|
138
|
+
* FiatWithdrawalsAppLoaded is received when the Fiat
|
|
139
|
+
* withdrawals app has initialized.
|
|
140
|
+
*/
|
|
141
|
+
FiatWithdrawalsAppLoaded = "FIAT_WITHDRAWALS_APP_LOADED",
|
|
142
|
+
/**
|
|
143
|
+
* FiatWithdrawalsCloseButtonClicked is received when the close button
|
|
144
|
+
* has been clicked in the Fiat Withdrawals app
|
|
145
|
+
*/
|
|
146
|
+
FiatWithdrawalsCloseButtonClicked = "FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
147
|
+
/**
|
|
148
|
+
* CryptoBuyAppLoaded is received when the Crypto
|
|
149
|
+
* buy app has initialized.
|
|
150
|
+
*/
|
|
151
|
+
CryptoBuyAppLoaded = "CRYPTO_BUY_APP_LOADED",
|
|
152
|
+
/**
|
|
153
|
+
* CryptoBuyCloseButtonClicked is received when the close button
|
|
154
|
+
* has been clicked in the Crypto buy app
|
|
155
|
+
*/
|
|
156
|
+
CryptoBuyCloseButtonClicked = "CRYPTO_BUY_CLOSE_BUTTON_CLICKED",
|
|
157
|
+
/**
|
|
158
|
+
* CryptoSellAppLoaded is received when the Crypto
|
|
159
|
+
* sell app has initialized.
|
|
160
|
+
*/
|
|
161
|
+
CryptoSellAppLoaded = "CRYPTO_SELL_APP_LOADED",
|
|
162
|
+
/**
|
|
163
|
+
* CryptoSellCloseButtonClicked is received when the close button
|
|
164
|
+
* has been clicked in the Crypto sell app
|
|
165
|
+
*/
|
|
166
|
+
CryptoSellCloseButtonClicked = "CRYPTO_SELL_CLOSE_BUTTON_CLICKED",
|
|
119
167
|
}
|
|
120
168
|
|
|
121
169
|
/**
|
|
@@ -155,6 +203,9 @@ export enum AppIdentifier {
|
|
|
155
203
|
ONBOARDING = "onboarding",
|
|
156
204
|
CRYPTO_WITHDRAWALS = "crypto-withdrawals",
|
|
157
205
|
ACH_DEPOSITS = "ach-deposits",
|
|
206
|
+
FIAT_WITHDRAWALS = "fiat-withdrawals",
|
|
207
|
+
CRYPTO_BUY = "crypto-buy",
|
|
208
|
+
CRYPTO_SELL = "crypto-sell",
|
|
158
209
|
}
|
|
159
210
|
|
|
160
211
|
/**
|
|
@@ -165,6 +216,9 @@ export const appIdentifierToActionPrefixMap = new Map(
|
|
|
165
216
|
[AppIdentifier.ONBOARDING, "ONBOARDING_"],
|
|
166
217
|
[AppIdentifier.CRYPTO_WITHDRAWALS, "CRYPTO_WITHDRAWALS_"],
|
|
167
218
|
[AppIdentifier.ACH_DEPOSITS, "ACH_DEPOSITS_"],
|
|
219
|
+
[AppIdentifier.FIAT_WITHDRAWALS, "FIAT_WITHDRAWALS_"],
|
|
220
|
+
[AppIdentifier.CRYPTO_BUY, "CRYPTO_BUY_"],
|
|
221
|
+
[AppIdentifier.CRYPTO_SELL, "CRYPTO_SELL_"],
|
|
168
222
|
])
|
|
169
223
|
|
|
170
224
|
export interface ISetJWTParameters {
|