forked from stakwork/sphinx-win-linux-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
82 lines (73 loc) · 2.14 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, {useState, useEffect} from 'react'
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper'
import Main from './src/components/main'
import Onboard from './src/components/onboard'
import {useStores} from './src/store'
import {instantiateRelay} from './src/api'
import {useObserver} from 'mobx-react-lite'
import Loading from './src/components/loading'
import AsyncStorage from '@react-native-community/async-storage'
import StatusBar from './src/components/utils/statusBar'
import * as utils from './src/components/utils/utils'
import {Linking} from 'react-native'
import { NavigationContainer } from '@react-navigation/native';
declare var global: {HermesInternal: null | {}}
export default function Wrap(){
const {ui} = useStores()
function deeplinkActions(j){
const action = j['action']
switch (action) {
case 'invoice':
ui.setRawInvoiceModal(j)
default:
return
}
}
function gotLink(e){
if(e && typeof e==='string'){
const j = utils.jsonFromUrl(e)
if(j['action']) deeplinkActions(j)
}
}
useEffect(()=>{
Linking.getInitialURL().then(e=> gotLink(e))
Linking.addEventListener('url', gotLink)
},[])
return useObserver(()=>{
if (ui.ready) return <App /> // hydrated!
return <Loading /> // full screen loading
})
}
function App() {
const {user} = useStores()
const [loading, setLoading] = useState(true) // default
const [signedUp, setSignedUp] = useState(false)
useEffect(()=>{
// AsyncStorage.clear()
const isSignedUp = (user.currentIP && user.authToken)?true:false
setSignedUp(isSignedUp)
if(isSignedUp){
instantiateRelay(user.currentIP, user.authToken)
}
setLoading(false)
},[])
if(loading) return <Loading />
return (<>
<NavigationContainer>
<PaperProvider theme={theme}>
<StatusBar />
{signedUp && <Main />}
{!signedUp && <Onboard onFinish={()=>setSignedUp(true)} />}
</PaperProvider>
</NavigationContainer>
</>)
}
const theme = {
...DefaultTheme,
roundness: 2,
colors: {
...DefaultTheme.colors,
primary: '#6289FD',
accent: '#55D1A9',
},
}