@@ -3,13 +3,15 @@ import {appleAuth} from '@invertase/react-native-apple-authentication';
3
3
import dynamicLinks from '@react-native-firebase/dynamic-links' ;
4
4
import { GoogleSignin } from '@react-native-google-signin/google-signin' ;
5
5
import { subMinutes } from 'date-fns' ;
6
+ import { when } from 'mobx' ;
6
7
import { Alert , AppState , Appearance , Platform , StatusBar } from 'react-native' ;
7
8
import Config from 'react-native-config' ;
8
9
import Keychain , {
9
10
STORAGE_TYPE ,
10
11
getGenericPassword ,
11
12
setGenericPassword ,
12
13
} from 'react-native-keychain' ;
14
+ import SplashScreen from 'react-native-splash-screen' ;
13
15
import TouchID from 'react-native-touch-id' ;
14
16
15
17
import { DEBUG_VARS } from '@app/debug-vars' ;
@@ -19,6 +21,7 @@ import {Events} from '@app/events';
19
21
import { AsyncEventEmitter } from '@app/helpers/async-event-emitter' ;
20
22
import { awaitForEventDone } from '@app/helpers/await-for-event-done' ;
21
23
import { checkNeedUpdate } from '@app/helpers/check-app-version' ;
24
+ import { isConnected } from '@app/helpers/check-internet' ;
22
25
import { getRpcProvider } from '@app/helpers/get-rpc-provider' ;
23
26
import { getUid } from '@app/helpers/get-uid' ;
24
27
import { SecurePinUtils } from '@app/helpers/secure-pin-utils' ;
@@ -35,12 +38,14 @@ import {Cosmos} from '@app/services/cosmos';
35
38
import { EventTracker } from '@app/services/event-tracker' ;
36
39
import { HapticEffects , vibrate } from '@app/services/haptic' ;
37
40
import { RemoteConfig } from '@app/services/remote-config' ;
41
+ import { sleep } from '@app/utils' ;
38
42
39
43
import { showModal } from '../helpers' ;
40
44
import { User } from '../models/user' ;
41
45
import {
42
46
AppTheme ,
43
47
BiometryType ,
48
+ DataFetchSource ,
44
49
DynamicLink ,
45
50
MarketingEvents ,
46
51
ModalType ,
@@ -110,29 +115,77 @@ class App extends AsyncEventEmitter {
110
115
111
116
this . user = User . getOrCreate ( ) ;
112
117
113
- Provider . init ( )
114
- . then ( RemoteProviderConfig . init )
115
- . then ( ( ) => {
116
- EthNetwork . init ( Provider . selectedProvider ) ;
117
-
118
- this . checkBalance ( ) ;
119
-
120
- this . handleDynamicLink = this . handleDynamicLink . bind ( this ) ;
121
-
122
- dynamicLinks ( ) . onLink ( this . handleDynamicLink ) ;
123
- dynamicLinks ( ) . getInitialLink ( ) . then ( this . handleDynamicLink ) ;
124
-
125
- this . listenTheme = this . listenTheme . bind ( this ) ;
126
-
127
- Appearance . addChangeListener ( this . listenTheme ) ;
128
- AppState . addEventListener ( 'change' , this . listenTheme ) ;
129
- this . listenTheme ( ) ;
130
- AppState . addEventListener ( 'change' , this . onAppStatusChanged . bind ( this ) ) ;
118
+ when (
119
+ ( ) => AppStore . isHydrated ,
120
+ async ( ) => {
121
+ if ( AppStore . dataFetchMode === DataFetchSource . Backend ) {
122
+ await isConnected ( ) . then ( async connected => {
123
+ if ( connected ) {
124
+ let isBackendAvailable = true ;
125
+
126
+ try {
127
+ await Backend . instance . news ( new Date ( ) ) ;
128
+ Logger . log ( 'Backend is available' ) ;
129
+ } catch {
130
+ isBackendAvailable = false ;
131
+ }
132
+
133
+ Logger . log ( 'isBackendAvailable' , isBackendAvailable ) ;
134
+ if ( ! isBackendAvailable ) {
135
+ SplashScreen . hide ( ) ;
136
+ await sleep ( 1000 ) ;
137
+ return new Promise ( ( ) => {
138
+ Alert . alert (
139
+ 'Haqq Wallet Backend Shutdown' ,
140
+ 'The backend service for Haqq Wallet is no longer maintained. Please switch to RPC mode.' ,
141
+ [
142
+ {
143
+ text : 'Switch to RPC' ,
144
+ onPress : ( ) => {
145
+ AppStore . dataFetchMode = DataFetchSource . Rpc ;
146
+ } ,
147
+ } ,
148
+ ] ,
149
+ ) ;
150
+ } ) ;
151
+ }
152
+ }
153
+ } ) ;
154
+ }
131
155
132
- this . setEnabledLoggersForTestMode ( ) ;
133
- this . stopInitialization ( ) ;
134
- } )
135
- . catch ( this . stopInitialization ) ;
156
+ Logger . log ( 'AppStore isHydrated done' ) ;
157
+ Provider . init ( )
158
+ . then ( RemoteProviderConfig . init )
159
+ . then ( ( ) => {
160
+ EthNetwork . init ( Provider . selectedProvider ) ;
161
+
162
+ this . checkBalance ( ) ;
163
+
164
+ this . handleDynamicLink = this . handleDynamicLink . bind ( this ) ;
165
+
166
+ dynamicLinks ( ) . onLink ( this . handleDynamicLink ) ;
167
+ dynamicLinks ( ) . getInitialLink ( ) . then ( this . handleDynamicLink ) ;
168
+
169
+ this . listenTheme = this . listenTheme . bind ( this ) ;
170
+
171
+ Appearance . addChangeListener ( this . listenTheme ) ;
172
+ AppState . addEventListener ( 'change' , this . listenTheme ) ;
173
+ this . listenTheme ( ) ;
174
+ AppState . addEventListener (
175
+ 'change' ,
176
+ this . onAppStatusChanged . bind ( this ) ,
177
+ ) ;
178
+
179
+ this . setEnabledLoggersForTestMode ( ) ;
180
+ this . stopInitialization ( ) ;
181
+ } )
182
+ . catch ( e => {
183
+ Logger . error ( e , 'App init error' ) ;
184
+ this . stopInitialization ( ) ;
185
+ } )
186
+ . finally ( this . stopInitialization ) ;
187
+ } ,
188
+ ) ;
136
189
}
137
190
138
191
private _startUpTime : number ;
0 commit comments