2021-01-13 01:03:46 +01:00
|
|
|
import { ActionSheetProvider } from '@expo/react-native-action-sheet'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { QueryClientProvider } from '@tanstack/react-query'
|
2021-03-27 00:02:32 +01:00
|
|
|
import AccessibilityManager from '@utils/accessibility/AccessibilityManager'
|
2023-01-29 15:32:40 +01:00
|
|
|
import { connectVerify } from '@utils/api/helpers/connect'
|
2022-12-28 23:41:36 +01:00
|
|
|
import getLanguage from '@utils/helpers/getLanguage'
|
2023-01-03 23:57:23 +01:00
|
|
|
import { queryClient } from '@utils/queryHooks'
|
2022-12-28 23:41:36 +01:00
|
|
|
import audio from '@utils/startup/audio'
|
2023-01-03 23:57:23 +01:00
|
|
|
import { dev } from '@utils/startup/dev'
|
2022-12-28 23:41:36 +01:00
|
|
|
import log from '@utils/startup/log'
|
|
|
|
import netInfo from '@utils/startup/netInfo'
|
|
|
|
import push from '@utils/startup/push'
|
|
|
|
import sentry from '@utils/startup/sentry'
|
2023-02-08 19:22:20 +01:00
|
|
|
import { GLOBAL } from '@utils/storage'
|
2023-01-16 22:11:41 +01:00
|
|
|
import { getGlobalStorage, setAccount, setGlobalStorage } from '@utils/storage/actions'
|
2022-12-29 00:36:35 +01:00
|
|
|
import { migrateFromAsyncStorage, versionStorageGlobal } from '@utils/storage/migrations/toMMKV'
|
2020-12-27 18:43:49 +01:00
|
|
|
import ThemeManager from '@utils/styles/ThemeManager'
|
2022-10-11 22:28:59 +02:00
|
|
|
import * as Localization from 'expo-localization'
|
2020-12-13 22:31:55 +01:00
|
|
|
import * as SplashScreen from 'expo-splash-screen'
|
2020-12-22 00:50:47 +01:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react'
|
2023-02-11 22:04:32 +01:00
|
|
|
import { Platform } from 'react-native'
|
2021-12-18 12:06:35 +01:00
|
|
|
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
2022-11-20 16:14:08 +01:00
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
2021-12-18 19:59:38 +01:00
|
|
|
import { enableFreeze } from 'react-native-screens'
|
2022-12-28 23:41:36 +01:00
|
|
|
import i18n from './i18n'
|
|
|
|
import Screens from './screens'
|
2021-01-13 01:03:46 +01:00
|
|
|
|
2023-02-11 22:04:32 +01:00
|
|
|
log('log', 'App', 'delay splash')
|
|
|
|
SplashScreen.preventAutoHideAsync()
|
2020-11-04 22:26:38 +01:00
|
|
|
|
2023-01-03 23:57:23 +01:00
|
|
|
dev()
|
2021-01-23 02:41:50 +01:00
|
|
|
sentry()
|
2023-01-16 22:11:41 +01:00
|
|
|
netInfo()
|
2021-01-07 19:13:09 +01:00
|
|
|
audio()
|
2021-02-27 16:33:54 +01:00
|
|
|
push()
|
2022-02-02 22:47:30 +01:00
|
|
|
enableFreeze(true)
|
2020-12-27 18:43:49 +01:00
|
|
|
|
2020-11-23 00:07:32 +01:00
|
|
|
const App: React.FC = () => {
|
2021-01-07 19:13:09 +01:00
|
|
|
log('log', 'App', 'rendering App')
|
2022-12-28 23:41:36 +01:00
|
|
|
const [appIsReady, setAppIsReady] = useState(false)
|
2020-12-28 23:20:18 +01:00
|
|
|
|
2022-12-29 00:36:35 +01:00
|
|
|
const [hasMigrated, setHasMigrated] = useState<boolean>(versionStorageGlobal !== undefined)
|
2022-12-28 23:41:36 +01:00
|
|
|
|
2020-12-13 22:31:55 +01:00
|
|
|
useEffect(() => {
|
2022-12-28 23:41:36 +01:00
|
|
|
const prepare = async () => {
|
2022-12-29 00:36:35 +01:00
|
|
|
if (!hasMigrated) {
|
2022-12-28 23:41:36 +01:00
|
|
|
try {
|
|
|
|
await migrateFromAsyncStorage()
|
|
|
|
setHasMigrated(true)
|
2022-12-29 00:36:35 +01:00
|
|
|
} catch {}
|
2023-01-29 15:32:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const useConnect = getGlobalStorage.boolean('app.connect')
|
2023-01-29 19:02:47 +01:00
|
|
|
GLOBAL.connect = useConnect
|
2023-01-29 15:32:40 +01:00
|
|
|
log('log', 'App', `connect: ${useConnect}`)
|
|
|
|
if (useConnect) {
|
|
|
|
await connectVerify()
|
|
|
|
.then(() => log('log', 'App', 'connected'))
|
|
|
|
.catch(() => log('warn', 'App', 'connect verify failed'))
|
|
|
|
}
|
|
|
|
|
|
|
|
log('log', 'App', 'loading from MMKV')
|
|
|
|
const account = getGlobalStorage.string('account.active')
|
|
|
|
if (account) {
|
|
|
|
await setAccount(account)
|
2022-12-28 23:41:36 +01:00
|
|
|
} else {
|
2023-01-29 15:32:40 +01:00
|
|
|
log('log', 'App', 'No active account available')
|
|
|
|
const accounts = getGlobalStorage.object('accounts')
|
|
|
|
if (accounts?.length) {
|
|
|
|
log('log', 'App', `Setting active account ${accounts[accounts.length - 1]}`)
|
|
|
|
await setAccount(accounts[accounts.length - 1])
|
2022-12-28 23:41:36 +01:00
|
|
|
} else {
|
2023-01-29 15:32:40 +01:00
|
|
|
setGlobalStorage('account.active', undefined)
|
2022-12-28 23:41:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log('log', 'App', `locale: ${Localization.locale}`)
|
|
|
|
const language = getLanguage()
|
|
|
|
if (!language) {
|
|
|
|
if (Platform.OS !== 'ios') {
|
|
|
|
setGlobalStorage('app.language', 'en')
|
|
|
|
}
|
|
|
|
i18n.changeLanguage('en')
|
|
|
|
} else {
|
|
|
|
i18n.changeLanguage(language)
|
|
|
|
}
|
2021-01-07 19:13:09 +01:00
|
|
|
|
2022-12-28 23:41:36 +01:00
|
|
|
setAppIsReady(true)
|
2020-12-13 22:31:55 +01:00
|
|
|
}
|
|
|
|
|
2022-12-28 23:41:36 +01:00
|
|
|
prepare()
|
|
|
|
}, [])
|
|
|
|
const onLayoutRootView = useCallback(async () => {
|
|
|
|
if (appIsReady) {
|
|
|
|
log('log', 'App', 'hide splash')
|
2021-01-07 19:13:09 +01:00
|
|
|
await SplashScreen.hideAsync()
|
|
|
|
}
|
2022-12-28 23:41:36 +01:00
|
|
|
}, [appIsReady])
|
|
|
|
if (!appIsReady) {
|
|
|
|
return null
|
|
|
|
}
|
2020-12-22 00:50:47 +01:00
|
|
|
|
2020-11-23 00:07:32 +01:00
|
|
|
return (
|
2022-12-28 23:41:36 +01:00
|
|
|
<GestureHandlerRootView style={{ flex: 1 }} onLayout={onLayoutRootView}>
|
2021-12-18 12:06:35 +01:00
|
|
|
<QueryClientProvider client={queryClient}>
|
2022-12-28 23:41:36 +01:00
|
|
|
<SafeAreaProvider>
|
|
|
|
<ActionSheetProvider>
|
|
|
|
<AccessibilityManager>
|
|
|
|
<ThemeManager>
|
2023-01-16 22:11:41 +01:00
|
|
|
<Screens />
|
2022-12-28 23:41:36 +01:00
|
|
|
</ThemeManager>
|
|
|
|
</AccessibilityManager>
|
|
|
|
</ActionSheetProvider>
|
|
|
|
</SafeAreaProvider>
|
2021-12-18 12:06:35 +01:00
|
|
|
</QueryClientProvider>
|
|
|
|
</GestureHandlerRootView>
|
2020-11-23 00:07:32 +01:00
|
|
|
)
|
|
|
|
}
|
2020-10-31 21:04:46 +01:00
|
|
|
|
2023-02-16 23:36:01 +01:00
|
|
|
export default App
|