forked from EdgeApp/edge-react-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
173 lines (150 loc) · 4.66 KB
/
app.js
File metadata and controls
173 lines (150 loc) · 4.66 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// @flow
/* global __DEV__ */
import Bugsnag from '@bugsnag/react-native'
import * as React from 'react'
import { Platform, StatusBar, Text, TextInput } from 'react-native'
import RNFS from 'react-native-fs'
import ENV from '../env.json'
import { THEME } from './theme/variables/airbitz.js'
import { log, logToServer } from './util/logger'
Bugsnag.start({
apiKey: ENV.BUGSNAG_API_KEY,
onError: event => {
log(`Bugsnag Device ID: ${event.device.id ?? ''}`)
return event
}
})
// Set up the transparent status bar at boot time on Android:
StatusBar.setBarStyle('light-content')
if (StatusBar.setTranslucent != null) {
StatusBar.setTranslucent(true)
StatusBar.setBackgroundColor(THEME.COLORS.APP_STATUS_BAR)
}
const ENABLE_WHY_DID_YOU_UPDATE = false
const ENABLE_PERF_LOGGING = false
const PERF_LOGGING_ONLY = false
const perfTimers = {}
const perfCounters = {}
const perfTotals = {}
console.log('***********************')
console.log('App directory: ' + RNFS.DocumentDirectoryPath)
console.log('***********************')
global.clog = console.log
// TODO: Remove isMounted from IGNORED_WARNINGS once we upgrade to RN 0.57
const IGNORED_WARNINGS = ['slowlog', 'Setting a timer for a long period of time', 'Warning: isMounted(...) is deprecated']
// $FlowExpectedError
console.ignoredYellowBox = IGNORED_WARNINGS
global.OS = Platform.OS
// Disable the font scaling
if (!Text.defaultProps) {
Text.defaultProps = {}
}
Text.defaultProps.allowFontScaling = false
if (!TextInput.defaultProps) {
TextInput.defaultProps = {}
}
TextInput.defaultProps.allowFontScaling = false
// $FlowFixMe
if (!__DEV__) {
// TODO: Fix logger to append data vs read/modify/write
// $FlowFixMe
console.log = log
// $FlowFixMe
console.info = log
// $FlowFixMe
console.warn = log
// $FlowFixMe
console.error = log
}
if (__DEV__ && ENABLE_WHY_DID_YOU_UPDATE) {
const { whyDidYouUpdate } = require('why-did-you-update')
whyDidYouUpdate(React)
}
if (ENV.LOG_SERVER) {
// $FlowFixMe: suppressing this error until we can find a workaround
console.log = function () {
logToServer(arguments)
}
// $FlowFixMe
console.info = console.log
// $FlowFixMe
console.warn = console.log
// $FlowFixMe
console.error = console.log
}
const clog = console.log
if (PERF_LOGGING_ONLY) {
// $FlowFixMe: suppressing this error until we can find a workaround
console.log = () => {}
}
if (ENABLE_PERF_LOGGING) {
if (!global.nativePerformanceNow && window && window.performance) {
global.nativePerformanceNow = () => window.performance.now()
}
const makeDate = () => {
const d = new Date(Date.now())
const h = ('0' + d.getHours().toString()).slice(-2)
const m = ('0' + d.getMinutes().toString()).slice(-2)
const s = ('0' + d.getSeconds().toString()).slice(-2)
const ms = ('00' + d.getMilliseconds().toString()).slice(-3)
return `${h}:${m}:${s}.${ms}`
}
global.pnow = function (label: string) {
const d = makeDate()
clog(`${d} PTIMER PNOW: ${label}`)
}
global.pstart = function (label: string) {
const d = makeDate()
if (!perfTotals[label]) {
perfTotals[label] = 0
perfCounters[label] = 0
}
if (typeof perfTimers[label] === 'undefined') {
perfTimers[label] = global.nativePerformanceNow()
} else {
clog(`${d}: PTIMER Error: PTimer already started: ${label}`)
}
}
global.pend = function (label: string) {
const d = makeDate()
if (typeof perfTimers[label] === 'number') {
const elapsed = global.nativePerformanceNow() - perfTimers[label]
perfTotals[label] += elapsed
perfCounters[label]++
clog(`${d}: PTIMER ${label}:${elapsed}ms total:${perfTotals[label]}ms count:${perfCounters[label]}`)
perfTimers[label] = undefined
} else {
clog(`${d}: PTIMER Error: PTimer not started: ${label}`)
}
}
global.pcount = function (label: string) {
const d = makeDate()
if (typeof perfCounters[label] === 'undefined') {
perfCounters[label] = 1
} else {
perfCounters[label] = perfCounters[label] + 1
}
if (perfCounters[label] % 1 === 0) {
clog(`${d}: PTIMER PCOUNT ${label}:${perfCounters[label]}`)
}
}
} else {
global.pnow = function (label: string) {}
global.pstart = function (label: string) {}
global.pend = function (label: string) {}
global.pcount = function (label: string) {}
}
const realFetch = fetch
fetch = (...args: any) => {
return realFetch(...args).catch(e => {
Bugsnag.leaveBreadcrumb('realFetchError', {
url: args[0],
errorName: e.name,
errorMsg: e.message
})
console.log(`realFetchError: ${args[0]} ${e.name} ${e.message}`)
throw e
})
}
// FIO disable changes below
global.isFioDisabled = false