zh-web-sdk 2.3.2 → 2.3.3

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.
Files changed (2) hide show
  1. package/README.md +7 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -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
 
@@ -145,7 +147,6 @@ const App = () => {
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",
@@ -167,9 +168,14 @@ const App = () => {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zh-web-sdk",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "private": false,
5
5
  "description": "ZeroHash Web SDK",
6
6
  "homepage": "https://github.com/seedcx/zh-web-sdk",