forked from LedgerHQ/ledger-live-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (82 loc) · 2.98 KB
/
index.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
// @flow
// Fix for crash with `Unsupported top level event type "onGestureHandlerStateChange" dispatched`
// https://github.com/kmagiera/react-native-gesture-handler/issues/320#issuecomment-443815828
import "react-native-gesture-handler";
/** URL polyfill */
// URL object `intentionally` lightweight, does not support URLSearchParams features
// https://github.com/facebook/react-native/issues/23922
import "react-native-url-polyfill/auto";
// cosmjs use TextEncoder that's not available in React Native but on Node
import "text-encoding-polyfill";
import { AppRegistry } from "react-native";
import * as Sentry from "@sentry/react-native";
import Config from "react-native-config";
import VersionNumber from "react-native-version-number";
import App, { routingInstrumentation } from "./src";
import { getEnabled } from "./src/components/HookSentry";
import logReport from "./src/log-report";
import pkg from "./package.json";
const blacklistErrorName = [
"NetworkDown",
"Network Error",
"WebsocketConnectionError",
"DisconnectedDeviceDuringOperation",
"BleError",
];
const blacklistErrorDescription = [
"Transaction signing request was rejected by the user",
];
if (Config.SENTRY_DSN && !__DEV__ && !Config.MOCK) {
Sentry.init({
dsn: Config.SENTRY_DSN,
environment: Config.SENTRY_ENVIRONMENT,
// NB we do not need to explicitly set the release. we let the native side infers it.
// release: `com.ledger.live@${pkg.version}+${VersionNumber.buildVersion}`,
// dist: String(VersionNumber.buildVersion),
sampleRate: 0.05,
tracesSampleRate: 0.001,
integrations: [
new Sentry.ReactNativeTracing({
routingInstrumentation,
}),
],
beforeSend(event: any) {
if (!getEnabled()) return null;
// If the error matches blacklistErrorName or blacklistErrorDescription,
// we will not send it to Sentry.
if (event && typeof event === "object") {
const { exception } = event;
if (
exception &&
typeof exception === "object" &&
Array.isArray(exception.values)
) {
const { values } = exception;
const shouldBlacklist = values.some(item => {
if (item && typeof item === "object") {
const { type, value } = item;
return (typeof type === "string" &&
blacklistErrorName.some(pattern => type.match(pattern))) ||
(typeof value === "string" &&
blacklistErrorDescription.some(pattern =>
value.match(pattern),
))
? event
: null;
}
return null;
});
if (shouldBlacklist) return null;
}
}
return event;
},
});
}
if (Config.DISABLE_YELLOW_BOX) {
// $FlowFixMe
console.disableYellowBox = true; // eslint-disable-line no-console
}
logReport.logReportInit();
const AppWithSentry = Sentry.wrap(App);
AppRegistry.registerComponent("ledgerlivemobile", () => AppWithSentry);