zh-web-sdk 2.3.2 → 2.3.4
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 +16 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +4 -4
- package/dist/redux/reducers/fiat-deposits.d.ts +13 -0
- package/dist/redux/reducers/index.d.ts +1 -1
- package/dist/redux/store/index.d.ts +1 -1
- package/dist/types.d.ts +9 -9
- package/package.json +1 -1
- package/src/iframe-container/AppContainer.tsx +2 -2
- package/src/index.tsx +10 -10
- package/src/redux/reducers/fiat-deposits.ts +64 -0
- package/src/redux/reducers/index.ts +3 -3
- package/src/types.ts +15 -15
- package/dist/redux/reducers/ach-deposits.d.ts +0 -13
- package/src/redux/reducers/ach-deposits.ts +0 -64
package/README.md
CHANGED
|
@@ -89,9 +89,9 @@ We forward events that come from the UI to the Native App using the `postMessage
|
|
|
89
89
|
- **Crypto Withdrawals:**
|
|
90
90
|
- `CRYPTO_WITHDRAWALS_APP_LOADED` Sent when the App is loaded in the first time
|
|
91
91
|
- `CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
|
|
92
|
-
- **
|
|
93
|
-
- `
|
|
94
|
-
- `
|
|
92
|
+
- **Fiat Deposits:**
|
|
93
|
+
- `FIAT_DEPOSITS_APP_LOADED` Sent when the App is loaded in the first time
|
|
94
|
+
- `FIAT_DEPOSITS_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
|
|
95
95
|
- **Fiat Withdrawals:**
|
|
96
96
|
- `FIAT_WITHDRAWALS_APP_LOADED` Sent when the App is loaded in the first time
|
|
97
97
|
- `FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
|
|
@@ -110,9 +110,9 @@ To control the `WebView` you can also send messages *down*, using the `postMessa
|
|
|
110
110
|
- **Crypto Withdrawals**
|
|
111
111
|
- `{type: "OPEN_MODAL", payload:{jwt: "<JWT_HERE>", appIdentifier: "crypto-withdrawals"} }`: It will open the Crypto Withdrawals modal with the JWT provided
|
|
112
112
|
- `{type: "CLOSE_MODAL", payload:{appIdentifier: "crypto-withdrawals"}}`: It will close the Crypto Withdrawals modal
|
|
113
|
-
- **
|
|
114
|
-
- `{type: "OPEN_MODAL", payload:{jwt: "<JWT_HERE>", appIdentifier: "
|
|
115
|
-
- `{type: "CLOSE_MODAL", payload:{appIdentifier: "
|
|
113
|
+
- **Fiat Deposits**
|
|
114
|
+
- `{type: "OPEN_MODAL", payload:{jwt: "<JWT_HERE>", appIdentifier: "fiat-deposits"} }`: It will open the FIAT Deposits modal with the JWT provided
|
|
115
|
+
- `{type: "CLOSE_MODAL", payload:{appIdentifier: "fiat-deposits"}}`: It will close the Fiat Deposits modal
|
|
116
116
|
- **Fiat Withdrawals**
|
|
117
117
|
- `{type: "OPEN_MODAL", payload:{jwt: "<JWT_HERE>", appIdentifier: "fiat-withdrawals"} }`: It will open the Fiat withdrawals modal with the JWT provided
|
|
118
118
|
- `{type: "CLOSE_MODAL", payload:{appIdentifier: "fiat-withdrawals"}}`: It will close the Fiat withdrawals modal
|
|
@@ -125,6 +125,8 @@ To control the `WebView` you can also send messages *down*, using the `postMessa
|
|
|
125
125
|
|
|
126
126
|
#### Notes
|
|
127
127
|
A postMessage call is required to open the modal when the webview is loaded (type: OPEN_MODAL). This requirement was added in version `https://{SDK_SERVER_URL}/v1` and is not present in `https://{SDK_SERVER_URL}/`, which opens the onboarding app automatically. The latter will be deprecated and will not be available for use in the future.
|
|
128
|
+
|
|
129
|
+
To safely trigger the "OPEN_MODAL" event in the version 1, listen for an event sent by sdk-mobile indicating that the app is ready to receive events. This event generate by sdk-mobile is called **SDK_MOBILE_READY**.
|
|
128
130
|
|
|
129
131
|
The example below shows how you can implement the mentioned methods in a `react-native` project
|
|
130
132
|
|
|
@@ -138,19 +140,18 @@ const App = () => {
|
|
|
138
140
|
const mockJWT =
|
|
139
141
|
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6ZXJvaGFzaC5jb20iLCJzdWIiOiJ0ZXN0U3ViamVjdCIsImF1ZCI6WyJ6ZXJvaGFzaC5jb20iXSwiZXhwIjoxNjk1OTc2OTMzLCJpYXQiOjE2OTMzODQ5MzMsInBheWxvYWQiOnsiZW1haWwiOiJteS1lbWFpbEB0ZXN0LmNvbSIsInBhcnRpY2lwYW50X2NvZGUiOiJwYXJ0aWNpcGFudC1jb2RlIiwicGxhdGZvcm1fbmFtZSI6InBsYXRmb3JtLW5hbWUiLCJwbGF0Zm9ybV9jb2RlIjoicGxhdGZvcm0tY29kZSIsInBsYXRmb3JtX2FncmVlbWVudF9saW5rIjoicGxhdGZvcm0tYWdyZWVtZW50LWxpbmsifX0.r549t4J_iQ8wP5pnD2uTdRaRm4nHLO722lDmhbGoIc0E_cKVyVYnxZTO1DnXJ6NUJ6a3DvnkGv78iQHqvnFTmg'
|
|
140
142
|
const apps = {
|
|
141
|
-
|
|
143
|
+
fiatDeposits: { identifier: 'fiat-deposits', jwt: mockJWT },
|
|
142
144
|
cryptoBuy: { identifier: 'crypto-buy', jwt: mockJWT },
|
|
143
145
|
cryptoSell: { identifier: 'crypto-sell', jwt: mockJWT },
|
|
144
146
|
cryptoWithdrawals: { identifier: 'crypto-withdrawals', jwt: mockJWT },
|
|
145
147
|
fiatWithdrawals: { identifier: 'fiat-withdrawals', jwt: mockJWT },
|
|
146
148
|
userOnboarding: { identifier: 'onboarding', jwt: mockJWT },
|
|
147
149
|
}
|
|
148
|
-
|
|
149
150
|
/**
|
|
150
151
|
* Receive messages from sdk-mobile. Currently we expose the following event types:
|
|
151
152
|
* "ONBOARDING_APP_LOADED", "ONBOARDING_CLOSE_BUTTON_CLICKED",
|
|
152
153
|
* "CRYPTO_WITHDRAWALS_APP_LOADED", "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
153
|
-
* "
|
|
154
|
+
* "FIAT_DEPOSITS_APP_LOADED", "FIAT_DEPOSITS_CLOSE_BUTTON_CLICKED",
|
|
154
155
|
* "FIAT_WITHDRAWALS_APP_LOADED", "FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
|
|
155
156
|
* "CRYPTO_BUY_APP_LOADED", "CRYPTO_BUY_CLOSE_BUTTON_CLICKED",
|
|
156
157
|
* "CRYPTO_SELL_APP_LOADED", "CRYPTO_SELL_CLOSE_BUTTON_CLICKED",
|
|
@@ -160,16 +161,21 @@ const App = () => {
|
|
|
160
161
|
const closeModalEvents = [
|
|
161
162
|
'ONBOARDING_CLOSE_BUTTON_CLICKED',
|
|
162
163
|
'CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED',
|
|
163
|
-
'
|
|
164
|
+
'FIAT_DEPOSITS_CLOSE_BUTTON_CLICKED',
|
|
164
165
|
'FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED',
|
|
165
166
|
'CRYPTO_BUY_CLOSE_BUTTON_CLICKED',
|
|
166
167
|
'CRYPTO_SELL_CLOSE_BUTTON_CLICKED',
|
|
167
168
|
]
|
|
168
169
|
try {
|
|
169
170
|
const parsedMessage = JSON.parse(event.nativeEvent.data)
|
|
171
|
+
console.log('Received message:', parsedMessage)
|
|
170
172
|
if (closeModalEvents.includes(parsedMessage.type)) {
|
|
171
173
|
setIsWebViewOpen(false)
|
|
172
174
|
}
|
|
175
|
+
if (parsedMessage.type === 'SDK_MOBILE_READY') {
|
|
176
|
+
console.log('SDK is ready, opening modal...')
|
|
177
|
+
openModal()
|
|
178
|
+
}
|
|
173
179
|
} catch (e) {
|
|
174
180
|
alert(
|
|
175
181
|
`could not parse message: ${JSON.stringify(event.nativeEvent.data)}`,
|
|
@@ -195,7 +201,6 @@ const App = () => {
|
|
|
195
201
|
) {
|
|
196
202
|
throw new Error('Invalid app identifier')
|
|
197
203
|
}
|
|
198
|
-
|
|
199
204
|
if (useJWT) {
|
|
200
205
|
// You can send events with JWTs. See the example below
|
|
201
206
|
// { "type": "OPEN_MODAL", "payload": { "appIdentifier": "onboarding", "jwt": "some-jwt-token"}}
|
|
@@ -207,7 +212,6 @@ const App = () => {
|
|
|
207
212
|
// { "type": "CLOSE_MODAL", "payload": { "appIdentifier": "onboarding"}}
|
|
208
213
|
return `{ "type": "${eventType}", "payload": { "appIdentifier": "${eventAppIdentifier}"}}`
|
|
209
214
|
}
|
|
210
|
-
|
|
211
215
|
const openModal = () => {
|
|
212
216
|
setIsWebViewOpen(true)
|
|
213
217
|
webViewRef.current?.injectJavaScript(
|
|
@@ -282,13 +286,6 @@ const App = () => {
|
|
|
282
286
|
ref={webViewRef}
|
|
283
287
|
onMessage={handleMessage}
|
|
284
288
|
source={{ uri: generateURL() }}
|
|
285
|
-
onNavigationStateChange={(navState) => {
|
|
286
|
-
if (!navState.loading) {
|
|
287
|
-
setTimeout(() => {
|
|
288
|
-
openModal()
|
|
289
|
-
}, 100)
|
|
290
|
-
}
|
|
291
|
-
}}
|
|
292
289
|
/>
|
|
293
290
|
)}
|
|
294
291
|
</View>
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class ZeroHashSDK implements IZeroHashSDK {
|
|
|
12
12
|
*
|
|
13
13
|
* For more information, see {@code IInitializeParameters}
|
|
14
14
|
*/
|
|
15
|
-
constructor({ zeroHashOnboardingURL, rootQuerySelector, userOnboardingJWT, cryptoWithdrawalsJWT,
|
|
15
|
+
constructor({ zeroHashOnboardingURL, rootQuerySelector, userOnboardingJWT, cryptoWithdrawalsJWT, fiatDepositsJWT, fiatWithdrawalsJWT, cryptoBuyJWT, cryptoSellJWT, zeroHashAppsURL, }: IInitializeParameters);
|
|
16
16
|
/**
|
|
17
17
|
* setJWT sets the JWT for the appIdentifier provided.
|
|
18
18
|
* The JWT should be the JWT provided by ZeroHash via the platform
|