-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathApp.tsx
52 lines (45 loc) · 1.41 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react'
import {I18nContext, I18nManager} from '@shopify/react-i18n'
import {ExtensionServerProvider, isValidSurface} from '@shopify/ui-extensions-server-kit'
import {Layout} from '@/foundation/Layout'
import {Routes} from '@/foundation/Routes'
import {Toast} from '@/foundation/Toast'
import {Theme} from '@/foundation/Theme'
import {ModalContainer} from '@/foundation/ModalContainer'
function getConnectionUrl() {
if (import.meta.env.VITE_CONNECTION_URL) {
return import.meta.env.VITE_CONNECTION_URL.replace('https', 'wss').replace('/dev-console', '')
}
const protocol = location.protocol === 'http:' ? 'ws:' : 'wss:'
return `${protocol}//${location.host}/extensions`
}
const surface = new URLSearchParams(location.search).get('surface')
const extensionServerOptions = {
connection: {
url: getConnectionUrl(),
},
surface: isValidSurface(surface) ? surface : undefined,
}
const i18nManager = new I18nManager({
locale: 'en',
onError(error) {
// eslint-disable-next-line no-console
console.log(error)
},
})
function App() {
return (
<ExtensionServerProvider options={extensionServerOptions}>
<I18nContext.Provider value={i18nManager}>
<Theme>
<Layout>
<Routes />
<Toast />
<ModalContainer />
</Layout>
</Theme>
</I18nContext.Provider>
</ExtensionServerProvider>
)
}
export default App