This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
148 lines (137 loc) · 4.02 KB
/
App.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React from 'react';
import {Alert, BackHandler} from 'react-native';
import {ContactStackNavigator, MainStackNavigator} from './src/navigator';
import {
getUniqueId,
getManufacturer,
getDeviceName,
} from 'react-native-device-info';
import * as Sentry from '@sentry/react-native';
import {NavigationContainer} from '@react-navigation/native';
import AsyncStorage from '@react-native-community/async-storage';
import {getVersion} from './src/api/appinfo';
import {ErrorMessage} from './src/constant/Error';
import RNBootSplash from 'react-native-bootsplash';
import NetInfo from '@react-native-community/netinfo';
import JailMonkey from 'jail-monkey';
import EncryptedStorage from 'react-native-encrypted-storage';
Sentry.init({
dsn:
'https://d426d2cc424e4a1e88180fe4b61b629d@o449610.ingest.sentry.io/5432874',
enableNative: false,
});
const RootStackScreen = ({userToken}) => (
<NavigationContainer>
{userToken ? <MainStackNavigator /> : <ContactStackNavigator />}
</NavigationContainer>
);
export default class App extends React.Component {
state = {
isLoading: true,
isSignedIn: false,
isError: false,
};
constructor(props) {
super(props);
this.state = {isLoading: true};
}
async componentDidMount() {
const getConnection = await NetInfo.fetch();
NetInfo.fetch().then((state) => {
if (!state.isConnected) {
RNBootSplash.show();
this.setState({
isLoading: true,
isError: true,
});
Alert.alert(
ErrorMessage.TITLE_API_ERROR,
ErrorMessage.APP_CONNECTION_FAILED,
[{text: 'OK', onPress: () => BackHandler.exitApp()}],
);
}
console.log('Connection type', state.type);
console.log('Is connected?', state.isConnected);
});
const isRooted = await JailMonkey.isJailBroken();
const isHooked = await JailMonkey.hookDetected();
if (isRooted) {
const alert = () => {
Alert.alert(
ErrorMessage.TITLE_LOGIN_ERROR,
ErrorMessage.APP_ROOT_DETECTED,
[{text: 'OK', onPress: () => alert()}],
);
};
alert();
RNBootSplash.show();
}
if (isHooked) {
const alert = () => {
Alert.alert(
ErrorMessage.TITLE_LOGIN_ERROR,
ErrorMessage.APP_HOOK_DETECTED,
[{text: 'OK', onPress: () => alert()}],
);
};
alert();
RNBootSplash.show();
}
const response = await getVersion();
//console.log(response.json());
if (!response.ok) {
const message = await response.json();
if (message.message) {
Alert.alert(
ErrorMessage.TITLE_API_ERROR,
'ไม่สามารถให้บริการได้ขณะนี้ เนื่องจากข้อผิดพลาดของระบบ',
);
} else {
Alert.alert(
ErrorMessage.TITLE_API_ERROR,
ErrorMessage.APP_SERVER_ERROR,
);
}
RNBootSplash.show();
} else {
const token = await EncryptedStorage.getItem('accessToken')
.then((result) => {
console.log({result});
if (result != null) {
this.setState({
isSignedIn: true,
isLoading: false,
});
} else {
this.setState({
isSignedIn: false,
isLoading: false,
});
}
})
.catch((err) => {
this.setState({
isLoading: false,
});
});
}
const DeviceID = await getUniqueId();
const DeviceManufacturer = await getManufacturer();
const DeviceName = await getDeviceName();
}
render() {
if (this.state.isLoading) {
RNBootSplash.show();
return null;
} else {
RNBootSplash.hide({fade: true}); // fade
return <RootStackScreen userToken={this.state.isSignedIn} />;
}
// if (this.state.isLoading) {
// RNBootSplash.hide({fade: true}); // fade
//
// } else {
// RNBootSplash.show();
// }
}
}