zh-web-sdk 2.3.0 → 2.3.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 CHANGED
@@ -72,10 +72,10 @@ The pipeline automatically updates the version in package.json after merge to ma
72
72
  - default is a patch release (`1.0.0` to `1.0.1`)
73
73
 
74
74
  ## Mobile usage
75
- In order to use our SDK on Mobile Apps you should follow the guide below. You won't need to install or have `zh-web-sdk` as a dependency in your project to use it for Mobile Apps.
76
- We use a proxy server that calls the SDK internally in order to make it work for Mobile Applications. This proxy service is referred to as `sdk-mobile` and the URLs are:
77
- - Cert: https://sdk-mobile.cert.zerohash.com
78
- - Prod: https://sdk-mobile.zerohash.com
75
+ In order to use our SDK on Mobile Apps you should follow the guide below. You won't need to install or have `zh-web-sdk` as a dependency in your project to use it for Mobile Apps. We use a proxy server that calls the SDK internally in order to make it work for Mobile Applications. This proxy service is referred to as `sdk-mobile` and the URLs are:
76
+
77
+ - Cert: https://sdk-mobile.cert.zerohash.com/v1
78
+ - Prod: https://sdk-mobile.zerohash.com/v1
79
79
 
80
80
  These are the URLs your `WebView` should use on your Mobile App.
81
81
 
@@ -84,22 +84,22 @@ These are the URLs your `WebView` should use on your Mobile App.
84
84
  #### Events
85
85
  We forward events that come from the UI to the Native App using the `postMessage` API. You can handle these events using `onMessage` from the `WebView` component. Currently these are the events we have, for the respective Apps:
86
86
  - **Onboarding:**
87
- - `ONBOARDING_APP_LOADED` Sent when the App is loaded
87
+ - `ONBOARDING_APP_LOADED` Sent when the App is loaded in the first time
88
88
  - `ONBOARDING_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
89
89
  - **Crypto Withdrawals:**
90
- - `CRYPTO_WITHDRAWALS_APP_LOADED` Sent when the App is loaded
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
92
  - **ACH Deposits:**
93
- - `ACH_DEPOSITS_APP_LOADED` Sent when the App is loaded
93
+ - `ACH_DEPOSITS_APP_LOADED` Sent when the App is loaded in the first time
94
94
  - `ACH_DEPOSITS_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
95
95
  - **Fiat Withdrawals:**
96
- - `FIAT_WITHDRAWALS_APP_LOADED` Sent when the App is loaded
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
98
98
  - **Crypto Buy:**
99
- - `CRYPTO_BUY_APP_LOADED` Sent when the App is loaded
99
+ - `CRYPTO_BUY_APP_LOADED` Sent when the App is loaded in the first time
100
100
  - `CRYPTO_BUY_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
101
101
  - **Crypto Sell:**
102
- - `CRYPTO_SELL_APP_LOADED` Sent when the App is loaded
102
+ - `CRYPTO_SELL_APP_LOADED` Sent when the App is loaded in the first time
103
103
  - `CRYPTO_SELL_CLOSE_BUTTON_CLICKED` Sent when the user clicks the Close button on the top-right corner
104
104
 
105
105
  #### Messages
@@ -123,33 +123,51 @@ To control the `WebView` you can also send messages *down*, using the `postMessa
123
123
  - `{type: "OPEN_MODAL", payload:{jwt: "<JWT_HERE>", appIdentifier: "crypto-sell"} }`: It will open the Crypto sell modal with the JWT provided
124
124
  - `{type: "CLOSE_MODAL", payload:{appIdentifier: "crypto-sell"}}`: It will close the Crypto sell modal
125
125
 
126
+ #### Notes
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
+
126
129
  The example below shows how you can implement the mentioned methods in a `react-native` project
127
130
 
128
131
  ```jsx
129
- const sdkMobileServer = 'https://sdk-mobile.cert.zerohash.com/'
132
+ const sdkMobileServer = 'https://sdk-mobile.cert.zerohash.com/v1'
130
133
  const zeroHashAppsURL = 'https://web-sdk.zerohash.com/'
131
134
  const App = () => {
132
135
  const webViewRef = useRef<WebView>(null)
133
- const jwt = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c`
134
- /*
135
- Receive messages from sdk-mobile. Currently we expose the following event types:
136
- "ONBOARDING_APP_LOADED", "ONBOARDING_CLOSE_BUTTON_CLICKED",
137
- "CRYPTO_WITHDRAWALS_APP_LOADED", "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
138
- "ACH_DEPOSITS_APP_LOADED", "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED",
139
- "FIAT_WITHDRAWALS_APP_LOADED", "FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
140
- "CRYPTO_BUY_APP_LOADED", "CRYPTO_BUY_CLOSE_BUTTON_CLICKED",
141
- "CRYPTO_SELL_APP_LOADED", "CRYPTO_SELL_CLOSE_BUTTON_CLICKED",
142
- you should be able to take action based on these events.
143
- */
136
+ const [isWebViewOpen, setIsWebViewOpen] = React.useState(false)
137
+ const currentAppIdentifier = 'onboarding'
138
+ const mockJWT =
139
+ 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ6ZXJvaGFzaC5jb20iLCJzdWIiOiJ0ZXN0U3ViamVjdCIsImF1ZCI6WyJ6ZXJvaGFzaC5jb20iXSwiZXhwIjoxNjk1OTc2OTMzLCJpYXQiOjE2OTMzODQ5MzMsInBheWxvYWQiOnsiZW1haWwiOiJteS1lbWFpbEB0ZXN0LmNvbSIsInBhcnRpY2lwYW50X2NvZGUiOiJwYXJ0aWNpcGFudC1jb2RlIiwicGxhdGZvcm1fbmFtZSI6InBsYXRmb3JtLW5hbWUiLCJwbGF0Zm9ybV9jb2RlIjoicGxhdGZvcm0tY29kZSIsInBsYXRmb3JtX2FncmVlbWVudF9saW5rIjoicGxhdGZvcm0tYWdyZWVtZW50LWxpbmsifX0.r549t4J_iQ8wP5pnD2uTdRaRm4nHLO722lDmhbGoIc0E_cKVyVYnxZTO1DnXJ6NUJ6a3DvnkGv78iQHqvnFTmg'
140
+ const apps = {
141
+ achDeposits: { identifier: 'ach-deposits', jwt: mockJWT },
142
+ cryptoBuy: { identifier: 'crypto-buy', jwt: mockJWT },
143
+ cryptoSell: { identifier: 'crypto-sell', jwt: mockJWT },
144
+ cryptoWithdrawals: { identifier: 'crypto-withdrawals', jwt: mockJWT },
145
+ fiatWithdrawals: { identifier: 'fiat-withdrawals', jwt: mockJWT },
146
+ userOnboarding: { identifier: 'onboarding', jwt: mockJWT },
147
+ }
148
+
149
+ /**
150
+ * Receive messages from sdk-mobile. Currently we expose the following event types:
151
+ * "ONBOARDING_APP_LOADED", "ONBOARDING_CLOSE_BUTTON_CLICKED",
152
+ * "CRYPTO_WITHDRAWALS_APP_LOADED", "CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
153
+ * "ACH_DEPOSITS_APP_LOADED", "ACH_DEPOSITS_CLOSE_BUTTON_CLICKED",
154
+ * "FIAT_WITHDRAWALS_APP_LOADED", "FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED",
155
+ * "CRYPTO_BUY_APP_LOADED", "CRYPTO_BUY_CLOSE_BUTTON_CLICKED",
156
+ * "CRYPTO_SELL_APP_LOADED", "CRYPTO_SELL_CLOSE_BUTTON_CLICKED",
157
+ * you should be able to take action based on these events.
158
+ */
144
159
  const handleMessage = (event: WebViewMessageEvent) => {
160
+ const closeModalEvents = [
161
+ 'ONBOARDING_CLOSE_BUTTON_CLICKED',
162
+ 'CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED',
163
+ 'ACH_DEPOSITS_CLOSE_BUTTON_CLICKED',
164
+ 'FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED',
165
+ 'CRYPTO_BUY_CLOSE_BUTTON_CLICKED',
166
+ 'CRYPTO_SELL_CLOSE_BUTTON_CLICKED',
167
+ ]
145
168
  try {
146
169
  const parsedMessage = JSON.parse(event.nativeEvent.data)
147
- if (parsedMessage.type === "ONBOARDING_APP_LOADED") {
148
- // setOnboardingAppLoaded(true)
149
- }
150
- if (
151
- parsedMessage.type === "ONBOARDING_CLOSE_BUTTON_CLICKED"
152
- ) {
170
+ if (closeModalEvents.includes(parsedMessage.type)) {
153
171
  setIsWebViewOpen(false)
154
172
  }
155
173
  } catch (e) {
@@ -158,47 +176,125 @@ const App = () => {
158
176
  )
159
177
  }
160
178
  }
161
- /* You can also send messages to sdk-mobile, currently we accept the following messages:
179
+ /**
180
+ * You can also send messages to sdk-mobile, currently we accept the following messages:
162
181
  * "OPEN_MODAL" and "CLOSE_MODAL"
163
182
  * Note that the "true;" after the postMessage is required
164
183
  * and recommended by the official react-native-webview docs
165
184
  * https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#the-injectedjavascript-prop
166
185
  */
167
- const openOnboardingModalType = `{
168
- type: 'OPEN_MODAL',
169
- payload: { jwt: '${jwt}', appIdentifier: 'onboarding' } }`
170
- const openOnboardingModal = () => {
186
+ const makeEventType = (
187
+ eventAppIdentifier: string,
188
+ eventType: string,
189
+ useJWT = false,
190
+ ) => {
191
+ if (
192
+ !Object.entries(apps).some(
193
+ ([_, { identifier }]) => identifier === eventAppIdentifier,
194
+ )
195
+ ) {
196
+ throw new Error('Invalid app identifier')
197
+ }
198
+
199
+ if (useJWT) {
200
+ // You can send events with JWTs. See the example below
201
+ // { "type": "OPEN_MODAL", "payload": { "appIdentifier": "onboarding", "jwt": "some-jwt-token"}}
202
+ // { "type": "CLOSE_MODAL", "payload": { "appIdentifier": "onboarding", "jwt": "some-jwt-token"}}
203
+ return `{ "type": "${eventType}", "payload": { "appIdentifier": "${eventAppIdentifier}", "jwt": "${apps[eventAppIdentifier].jwt}"}}`
204
+ }
205
+ // Send events without JWTs if you already set in the URL with query parameters and don't want to send it again
206
+ // { "type": "OPEN_MODAL", "payload": { "appIdentifier": "onboarding"}}
207
+ // { "type": "CLOSE_MODAL", "payload": { "appIdentifier": "onboarding"}}
208
+ return `{ "type": "${eventType}", "payload": { "appIdentifier": "${eventAppIdentifier}"}}`
209
+ }
210
+
211
+ const openModal = () => {
212
+ setIsWebViewOpen(true)
171
213
  webViewRef.current?.injectJavaScript(
172
- `window.postMessage(${openOnboardingModalType});true;`,
214
+ `window.postMessage(${makeEventType(currentAppIdentifier, 'OPEN_MODAL')});true;`,
173
215
  )
174
216
  }
175
- const closeOnboardingModalType = `{ type: 'CLOSE_MODAL', payload: 'onboarding' }`
176
- const closeOnboardingModal = () =>
217
+ const closeModal = () => {
177
218
  webViewRef.current?.injectJavaScript(
178
- `window.postMessage(${closeOnboardingModalType});true;`,
219
+ `window.postMessage(${makeEventType(currentAppIdentifier, 'CLOSE_MODAL')});true;`,
179
220
  )
221
+ }
222
+ /**
223
+ * Generate the URL with the query parameters required and the JWTs for the apps
224
+ */
225
+ const generateURL = () => {
226
+ const jwtParams = Object.entries(apps)
227
+ .filter(([_, { jwt }]) => jwt)
228
+ .map(([key, { jwt }]) => `${key}JWT=${encodeURIComponent(jwt)}`)
229
+ .join('&')
230
+
231
+ return `${sdkMobileServer}?zeroHashAppsURL=${encodeURIComponent(zeroHashAppsURL)}&${jwtParams}`
232
+ }
180
233
  return (
181
234
  <SafeAreaProvider style={{ flex: 1 }}>
182
- <SafeAreaView style={{ flex: 1 }}>
183
- <TouchableOpacity onPress={() => closeOnboardingModal()}>
184
- <Text>Close modal</Text>
185
- </TouchableOpacity>
186
- <TouchableOpacity onPress={() => openOnboardingModal()}>
187
- <Text>Open modal</Text>
188
- </TouchableOpacity>
189
- <WebView
190
- ref={webViewRef}
191
- onMessage={handleMessage}
192
- source={{
193
- uri: `${sdkMobileServer}?
194
- cryptoSellJWT=${cryptoSellJWT}&
195
- cryptoBuyJWT=${cryptoBuyJWT}&
196
- fiatWithdrawalsJWT=${fiatWithdrawalsJWT}&
197
- achDepositsJWT=${achDepositsJWT}&cryptoWithdrawalsJWT=${cwJWT}userOnboardingJWT=${jwt}&zeroHashAppsURL=${zeroHashOnboardingURL}`,
198
- }}
199
- />
235
+ <SafeAreaView
236
+ style={{
237
+ flex: 1,
238
+ padding: 0,
239
+ }}
240
+ >
241
+ {!isWebViewOpen && (
242
+ <View
243
+ style={{
244
+ flex: 1,
245
+ alignContent: 'center',
246
+ flexDirection: 'row',
247
+ justifyContent: 'center',
248
+ alignItems: 'center',
249
+ }}
250
+ >
251
+ <TouchableOpacity
252
+ style={{
253
+ backgroundColor: '#00f197',
254
+ padding: 10,
255
+ margin: 10,
256
+ borderRadius: 5,
257
+ alignItems: 'center',
258
+ justifyContent: 'center',
259
+ }}
260
+ onPress={() => setIsWebViewOpen(true)}
261
+ >
262
+ <Text>Open modal</Text>
263
+ </TouchableOpacity>
264
+ <TouchableOpacity
265
+ style={{
266
+ backgroundColor: '#00f197',
267
+ padding: 10,
268
+ margin: 10,
269
+ borderRadius: 5,
270
+ alignItems: 'center',
271
+ justifyContent: 'center',
272
+ }}
273
+ onPress={() => closeModal()}
274
+ >
275
+ <Text>Close modal</Text>
276
+ </TouchableOpacity>
277
+ </View>
278
+ )}
279
+ <View style={{ display: isWebViewOpen ? 'flex' : 'none', flex: 1 }}>
280
+ {isWebViewOpen && (
281
+ <WebView
282
+ ref={webViewRef}
283
+ onMessage={handleMessage}
284
+ source={{ uri: generateURL() }}
285
+ onNavigationStateChange={(navState) => {
286
+ if (!navState.loading) {
287
+ setTimeout(() => {
288
+ openModal()
289
+ }, 100)
290
+ }
291
+ }}
292
+ />
293
+ )}
294
+ </View>
200
295
  </SafeAreaView>
201
296
  </SafeAreaProvider>
202
297
  )
203
298
  }
299
+ export default App
204
300
  ```
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ Error generating stack: `+i.message+`
9
9
  The error may be correlated with this previous error:
10
10
  ${Qi.current.stack}
11
11
 
12
- `),Ge}Mn(()=>{Qi.current=void 0,Fn.current=void 0,Hi.current=$r});let Ki=(0,D.useMemo)(()=>D.default.createElement(k,dt({},$r,{ref:H})),[H,k,$r]);return(0,D.useMemo)(()=>w?D.default.createElement(me.Provider,{value:Us},Ki):Ki,[me,Ki,Us])}let A=D.default.memo(v);if(A.WrappedComponent=k,A.displayName=v.displayName=c,s){let _=D.default.forwardRef(function(O,me){return D.default.createElement(A,dt({},O,{reactReduxForwardedRef:me}))});return _.displayName=c,_.WrappedComponent=k,(0,Rs.default)(_,k)}return(0,Rs.default)(A,k)}}var Ds=Bv;var Mr=b(Pe());function Hv({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",noopCheck:i="once"}){let l=(0,Mr.useMemo)(()=>{let a=zi(e);return{store:e,subscription:a,getServerState:r?()=>r:void 0,stabilityCheck:o,noopCheck:i}},[e,r,o,i]),u=(0,Mr.useMemo)(()=>e.getState(),[e]);Mn(()=>{let{subscription:a}=l;return a.onStateChange=a.notifyNestedSubs,a.trySubscribe(),u!==e.getState()&&a.notifyNestedSubs(),()=>{a.tryUnsubscribe(),a.onStateChange=void 0}},[l,u]);let s=t||je;return Mr.default.createElement(s.Provider,{value:l},n)}var Wi=Hv;od(Nd.useSyncExternalStoreWithSelector);Pd(Id.useSyncExternalStore);qp(Es.unstable_batchedUpdates);var Qv=540,zr=[{id:"MTE_SM",size:Qv}],Ld=()=>{for(let e=0;e<zr.length;e++){let{id:t,size:n}=zr[e];if(window.matchMedia(`(min-width: ${n}px`).matches)return t}return"ANY"},Ms={paddingRight:0,paddingLeft:0,marginRight:"auto",marginLeft:"auto",maxHeight:882},Rd={MTE_SM:{width:540},ANY:{width:"100%",height:"100%",maxWidth:"100%",borderRadius:0,maxHeight:"100%"}},Dd={position:"absolute",zIndex:999999,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",width:"100vw",height:CSS.supports("height: 100dvh")?"100dvh":window.innerHeight+"px",maxHeight:window.innerHeight+"px",background:"rgba(0,0,0,0.5)",cursor:"pointer"},Md={display:"none",width:0,height:0},zd={padding:0,borderRadius:5,backgroundColor:"#FFF",height:"calc(100% - 100px)",maxWidth:"calc(100% - 30px)"},jd={width:"100%",height:"100%",border:"none",overflow:"hidden"},Wd={width:"100%",height:"100%",border:"none",margin:0,padding:0,overflow:"hidden",borderRadius:"0 0 15px 15px"};var zs=e=>{Nn(e,de,{isAppActive:!0})},Je=e=>{Nn(e,de,{isAppActive:!1})},qt=e=>{Nn(e,Ee,{isAppLoaded:!0})};var Wr=b(jr()),bv=Date.now(),eg={onboarding:"Onboarding","crypto-withdrawals":"Crypto Withdrawals","ach-deposits":"ACH Deposits","fiat-withdrawals":"Fiat Withdrawals","crypto-buy":"Crypto Buy","crypto-sell":"Crypto Sell"},tg=({isAppActive:e,isAppLoaded:t,jwt:n,zeroHashAppURL:r,appIdentifier:o})=>{let i=eg[o],l=!!n,[u,s]=(0,bt.useState)(Ms),a=xs(h=>h),m=()=>{let h=Ld(),w=Rd[h];s({...Ms,...w})},y=(0,bt.useRef)(null);(0,bt.useEffect)(()=>{r&&t&&l&&y.current?.contentWindow&&Object.keys(a).forEach(h=>{a[h].jwt&&y.current?.contentWindow?.postMessage({type:`${R.get(h)}SEND_JWT_TOKEN`,jwt:a[h].jwt},r)})},[o,l,t,n,r,a]),(0,bt.useEffect)(()=>{if(m(),window)return zr.forEach(({size:h})=>{window.matchMedia(`(min-width: ${h}px)`).addEventListener("change",m)}),()=>zr.forEach(({size:h})=>{window.matchMedia(`(min-width: ${h}px)`).removeEventListener("change",m)})},[]);let d=new URL(r);return d.searchParams.set("name",bv.toString()),window&&d.searchParams.set("origin",window.location.origin),(0,Wr.jsx)("div",{style:e?{...Dd}:Md,onClick:()=>Je(o),children:(0,Wr.jsx)("div",{style:{...zd,...u},children:(0,Wr.jsx)("div",{style:{...jd},children:(0,Wr.jsx)("iframe",{ref:y,title:i,src:d.toString(),allow:"camera *; fullscreen *; accelerometer *; gyroscope *; magnetometer *;",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation",style:Wd})})})})},ng=(e,t)=>({isAppActive:e[t.appIdentifier].isAppActive,isAppLoaded:e[t.appIdentifier].isAppLoaded,jwt:e[t.appIdentifier].jwt}),js=Ds(ng)(tg);var Fr=b(jr()),$i=ys,Hd="",Bd={ONBOARDING_APP_LOADED:()=>{qt("onboarding")},ONBOARDING_CLOSE_BUTTON_CLICKED:()=>{Je("onboarding")},CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-withdrawals")},CRYPTO_WITHDRAWALS_APP_LOADED:()=>{qt("crypto-withdrawals")},ACH_DEPOSITS_CLOSE_BUTTON_CLICKED:()=>{Je("ach-deposits")},ACH_DEPOSITS_APP_LOADED:()=>{qt("ach-deposits")},FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Je("fiat-withdrawals")},FIAT_WITHDRAWALS_APP_LOADED:()=>{qt("fiat-withdrawals")},CRYPTO_BUY_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-buy")},CRYPTO_BUY_APP_LOADED:()=>{qt("crypto-buy")},CRYPTO_SELL_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-sell")},CRYPTO_SELL_APP_LOADED:()=>{qt("crypto-sell")}},rg=e=>{if(e.origin===Hd){let t=e.data;if(t&&t.type&&Bd[t.type])try{Bd[t.type](t.payload)}catch(n){console.error(n)}}},Ui=class{rootQuerySelector="";onboardingInitialized=!1;initializedApps=new Map([["crypto-withdrawals",!1],["onboarding",!1],["ach-deposits",!1],["fiat-withdrawals",!1],["crypto-buy",!1],["crypto-sell",!1]]);constructor({zeroHashOnboardingURL:t=ys,rootQuerySelector:n,userOnboardingJWT:r,cryptoWithdrawalsJWT:o,achDepositsJWT:i,fiatWithdrawalsJWT:l,cryptoBuyJWT:u,cryptoSellJWT:s,zeroHashAppsURL:a}){$i=a||t,Hd=new URL($i).origin,n&&(this.rootQuerySelector=n),window.addEventListener("message",rg,!1),r&&this.setJWT({jwt:r,appIdentifier:"onboarding"}),o&&this.setJWT({jwt:o,appIdentifier:"crypto-withdrawals"}),i&&this.setJWT({jwt:i,appIdentifier:"ach-deposits"}),l&&this.setJWT({jwt:l,appIdentifier:"fiat-withdrawals"}),u&&this.setJWT({jwt:u,appIdentifier:"crypto-buy"}),s&&this.setJWT({jwt:s,appIdentifier:"crypto-sell"})}setJWT({jwt:t,appIdentifier:n}){Nn(n,we,{jwt:t})}setUserOnboardingJWT(t){this.setJWT({jwt:t.userOnboardingJWT,appIdentifier:"onboarding"})}isOnboardingModalOpen(){return Zt.getState().onboarding.isAppActive}isModalOpen(t){return Zt.getState()[t].isAppActive}closeModal(t){Je(t)}openModal({jwt:t,appIdentifier:n}){if(t&&this.setJWT({jwt:t,appIdentifier:n}),zs(n),this.initializedApps.get(n))return;let r=null;if(this.rootQuerySelector&&(r=document.querySelector(this.rootQuerySelector)),!this.initializedApps.get(n)){r=document.createElement("div");let o=gs(n);r.id=o,r.style.position="absolute",r.style.top="0",r.style.left="0",this.rootQuerySelector=`#${o}`,document.querySelector("body").appendChild(r)}if(r){let o=r.attachShadow({mode:"closed"});Ws.default.createRoot(o).render((0,Fr.jsx)(Wi,{store:Zt,children:(0,Fr.jsx)(js,{appIdentifier:n,zeroHashAppURL:`${$i}/${n}`})})),this.initializedApps.set(n,!0)}else{let o="failed to append ZeroHash root to the page: root not found";throw console.error(o),new Error(o)}}openOnboardingModal(t){if(t.userOnboardingJWT&&this.setUserOnboardingJWT({userOnboardingJWT:t.userOnboardingJWT}),zs("onboarding"),this.onboardingInitialized)return;let n=null;if(this.rootQuerySelector&&(n=document.querySelector(this.rootQuerySelector)),!n){n=document.createElement("div");let r=gs();n.id=r,n.style.position="absolute",n.style.top="0",n.style.left="0",this.rootQuerySelector=`#${r}`,document.querySelector("body").appendChild(n)}if(n){let r=n.attachShadow({mode:"closed"});Ws.default.createRoot(r).render((0,Fr.jsx)(Wi,{store:Zt,children:(0,Fr.jsx)(js,{appIdentifier:"onboarding",zeroHashAppURL:$i})})),this.onboardingInitialized=!0}else{let r="failed to append ZeroHash root to the page: root not found";throw console.error(r),new Error(r)}}closeOnboardingModal(){Je("onboarding")}};window&&(window.zerohash=Ui);var WS=Ui;export{pt as AppIdentifier,kp as IncomingMessageType,Ui as ZeroHashSDK,R as appIdentifierToActionPrefixMap,WS as default};
12
+ `),Ge}Mn(()=>{Qi.current=void 0,Fn.current=void 0,Hi.current=$r});let Ki=(0,D.useMemo)(()=>D.default.createElement(k,dt({},$r,{ref:H})),[H,k,$r]);return(0,D.useMemo)(()=>w?D.default.createElement(me.Provider,{value:Us},Ki):Ki,[me,Ki,Us])}let A=D.default.memo(v);if(A.WrappedComponent=k,A.displayName=v.displayName=c,s){let _=D.default.forwardRef(function(O,me){return D.default.createElement(A,dt({},O,{reactReduxForwardedRef:me}))});return _.displayName=c,_.WrappedComponent=k,(0,Rs.default)(_,k)}return(0,Rs.default)(A,k)}}var Ds=Bv;var Mr=b(Pe());function Hv({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",noopCheck:i="once"}){let l=(0,Mr.useMemo)(()=>{let a=zi(e);return{store:e,subscription:a,getServerState:r?()=>r:void 0,stabilityCheck:o,noopCheck:i}},[e,r,o,i]),u=(0,Mr.useMemo)(()=>e.getState(),[e]);Mn(()=>{let{subscription:a}=l;return a.onStateChange=a.notifyNestedSubs,a.trySubscribe(),u!==e.getState()&&a.notifyNestedSubs(),()=>{a.tryUnsubscribe(),a.onStateChange=void 0}},[l,u]);let s=t||je;return Mr.default.createElement(s.Provider,{value:l},n)}var Wi=Hv;od(Nd.useSyncExternalStoreWithSelector);Pd(Id.useSyncExternalStore);qp(Es.unstable_batchedUpdates);var Qv=540,zr=[{id:"MTE_SM",size:Qv}],Ld=()=>{for(let e=0;e<zr.length;e++){let{id:t,size:n}=zr[e];if(window.matchMedia(`(min-width: ${n}px`).matches)return t}return"ANY"},Ms={paddingRight:0,paddingLeft:0,marginRight:"auto",marginLeft:"auto",maxHeight:882},Rd={MTE_SM:{width:540},ANY:{width:"100%",height:"100%",maxWidth:"100%",borderRadius:0,maxHeight:"100%"}},Dd={position:"absolute",zIndex:999999,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",width:"100vw",height:CSS.supports("height: 100dvh")?"100dvh":window.innerHeight+"px",maxHeight:window.innerHeight+"px",background:"rgba(0,0,0,0.5)",cursor:"pointer"},Md={display:"none",width:0,height:0},zd={padding:0,borderRadius:5,backgroundColor:"#FFF",height:"calc(100% - 100px)",maxWidth:"calc(100% - 30px)"},jd={width:"100%",height:"100%",border:"none",overflow:"hidden"},Wd={width:"100%",height:"100%",border:"none",margin:0,padding:0,overflow:"hidden",borderRadius:"0 0 15px 15px"};var zs=e=>{Nn(e,de,{isAppActive:!0})},Je=e=>{Nn(e,de,{isAppActive:!1})},qt=e=>{Nn(e,Ee,{isAppLoaded:!0})};var Wr=b(jr()),bv=Date.now(),eg={onboarding:"Onboarding","crypto-withdrawals":"Crypto Withdrawals","ach-deposits":"ACH Deposits","fiat-withdrawals":"Fiat Withdrawals","crypto-buy":"Crypto Buy","crypto-sell":"Crypto Sell"},tg=({isAppActive:e,isAppLoaded:t,jwt:n,zeroHashAppURL:r,appIdentifier:o})=>{let i=eg[o],l=!!n,[u,s]=(0,bt.useState)(Ms),a=xs(h=>h),m=()=>{let h=Ld(),w=Rd[h];s({...Ms,...w})},y=(0,bt.useRef)(null);(0,bt.useEffect)(()=>{r&&t&&l&&y.current?.contentWindow&&Object.keys(a).forEach(h=>{a[h].jwt&&y.current?.contentWindow?.postMessage({type:`${R.get(h)}SEND_JWT_TOKEN`,jwt:a[h].jwt},r)})},[o,l,t,n,r,a]),(0,bt.useEffect)(()=>{if(m(),window)return zr.forEach(({size:h})=>{window.matchMedia(`(min-width: ${h}px)`).addEventListener("change",m)}),()=>zr.forEach(({size:h})=>{window.matchMedia(`(min-width: ${h}px)`).removeEventListener("change",m)})},[]);let d=new URL(r);return d.searchParams.set("name",bv.toString()),window&&d.searchParams.set("origin",window.location.origin),(0,Wr.jsx)("div",{style:e?{...Dd}:Md,onClick:()=>Je(o),children:(0,Wr.jsx)("div",{style:{...zd,...u},children:(0,Wr.jsx)("div",{style:{...jd},children:(0,Wr.jsx)("iframe",{ref:y,title:i,src:d.toString(),allow:"camera *; fullscreen *; accelerometer *; gyroscope *; magnetometer *;",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation",style:Wd})})})})},ng=(e,t)=>({isAppActive:e[t.appIdentifier].isAppActive,isAppLoaded:e[t.appIdentifier].isAppLoaded,jwt:e[t.appIdentifier].jwt}),js=Ds(ng)(tg);var Fr=b(jr()),$i=ys,Hd="",Bd={ONBOARDING_APP_LOADED:()=>{qt("onboarding")},ONBOARDING_CLOSE_BUTTON_CLICKED:()=>{Je("onboarding")},CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-withdrawals")},CRYPTO_WITHDRAWALS_APP_LOADED:()=>{qt("crypto-withdrawals")},ACH_DEPOSITS_CLOSE_BUTTON_CLICKED:()=>{Je("ach-deposits")},ACH_DEPOSITS_APP_LOADED:()=>{qt("ach-deposits")},FIAT_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Je("fiat-withdrawals")},FIAT_WITHDRAWALS_APP_LOADED:()=>{qt("fiat-withdrawals")},CRYPTO_BUY_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-buy")},CRYPTO_BUY_APP_LOADED:()=>{qt("crypto-buy")},CRYPTO_SELL_CLOSE_BUTTON_CLICKED:()=>{Je("crypto-sell")},CRYPTO_SELL_APP_LOADED:()=>{qt("crypto-sell")}},rg=e=>{if(e.origin===Hd){let t=e.data;if(t&&t.type&&Bd[t.type])try{Bd[t.type](t.payload)}catch(n){console.error(n)}}},Ui=class{rootQuerySelector="";onboardingInitialized=!1;initializedApps=new Map([["crypto-withdrawals",!1],["onboarding",!1],["ach-deposits",!1],["fiat-withdrawals",!1],["crypto-buy",!1],["crypto-sell",!1]]);constructor({zeroHashOnboardingURL:t=ys,rootQuerySelector:n,userOnboardingJWT:r,cryptoWithdrawalsJWT:o,achDepositsJWT:i,fiatWithdrawalsJWT:l,cryptoBuyJWT:u,cryptoSellJWT:s,zeroHashAppsURL:a}){$i=a||t,Hd=new URL($i).origin,n&&(this.rootQuerySelector=n),window.addEventListener("message",rg,!1),r&&this.setJWT({jwt:r,appIdentifier:"onboarding"}),o&&this.setJWT({jwt:o,appIdentifier:"crypto-withdrawals"}),i&&this.setJWT({jwt:i,appIdentifier:"ach-deposits"}),l&&this.setJWT({jwt:l,appIdentifier:"fiat-withdrawals"}),u&&this.setJWT({jwt:u,appIdentifier:"crypto-buy"}),s&&this.setJWT({jwt:s,appIdentifier:"crypto-sell"})}setJWT({jwt:t,appIdentifier:n}){Nn(n,we,{jwt:t})}setUserOnboardingJWT(t){this.setJWT({jwt:t.userOnboardingJWT,appIdentifier:"onboarding"})}isOnboardingModalOpen(){return Zt.getState().onboarding.isAppActive}isModalOpen(t){return Zt.getState()[t].isAppActive}closeModal(t){Je(t)}openModal({jwt:t,appIdentifier:n}){if(t&&this.setJWT({jwt:t,appIdentifier:n}),zs(n),this.initializedApps.get(n))return;let r=null;if(this.rootQuerySelector&&(r=document.querySelector(this.rootQuerySelector)),!this.initializedApps.get(n)){r=document.createElement("div");let o=gs(n);r.id=o,r.style.position="absolute",r.style.top="0",r.style.left="0",this.rootQuerySelector=`#${o}`,document.querySelector("body").appendChild(r)}if(r){let o=r.attachShadow({mode:"closed"}),i=new URL(n,$i).href;Ws.default.createRoot(o).render((0,Fr.jsx)(Wi,{store:Zt,children:(0,Fr.jsx)(js,{appIdentifier:n,zeroHashAppURL:i})})),this.initializedApps.set(n,!0)}else{let o="failed to append ZeroHash root to the page: root not found";throw console.error(o),new Error(o)}}openOnboardingModal(t){if(t.userOnboardingJWT&&this.setUserOnboardingJWT({userOnboardingJWT:t.userOnboardingJWT}),zs("onboarding"),this.onboardingInitialized)return;let n=null;if(this.rootQuerySelector&&(n=document.querySelector(this.rootQuerySelector)),!n){n=document.createElement("div");let r=gs();n.id=r,n.style.position="absolute",n.style.top="0",n.style.left="0",this.rootQuerySelector=`#${r}`,document.querySelector("body").appendChild(n)}if(n){let r=n.attachShadow({mode:"closed"});Ws.default.createRoot(r).render((0,Fr.jsx)(Wi,{store:Zt,children:(0,Fr.jsx)(js,{appIdentifier:"onboarding",zeroHashAppURL:$i})})),this.onboardingInitialized=!0}else{let r="failed to append ZeroHash root to the page: root not found";throw console.error(r),new Error(r)}}closeOnboardingModal(){Je("onboarding")}};window&&(window.zerohash=Ui);var WS=Ui;export{pt as AppIdentifier,kp as IncomingMessageType,Ui as ZeroHashSDK,R as appIdentifierToActionPrefixMap,WS as default};
13
13
  /*! Bundled license information:
14
14
 
15
15
  react/cjs/react.production.min.js: