-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
158 lines (137 loc) · 4.1 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
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
/**
* @format
*/
import '@ethersproject/shims';
import '@walletconnect/react-native-compat';
import {AppRegistry, I18nManager, LogBox} from 'react-native';
import './global';
import {DEBUG_VARS} from '@app/debug-vars';
import {enableBatchedStateUpdates} from '@app/hooks/batched-set-state';
import {Provider} from '@app/models/provider';
import {EventTracker} from '@app/services/event-tracker';
import {MarketingEvents} from '@app/types';
import {IS_IOS, RTL_LANGUAGES} from '@app/variables/common';
import {JsonRpcProvider} from '@ethersproject/providers';
import messaging from '@react-native-firebase/messaging';
import * as Sentry from '@sentry/react-native';
import {ethers} from 'ethers';
import Config from 'react-native-config';
import {enableFreeze, enableScreens} from 'react-native-screens';
import {name as appName} from './app.json';
import {App} from './src/app';
import './src/event-actions';
import {Jailbreak} from './src/jailbreak';
import {Language} from '@app/models/language';
if (!global.BigInt) {
const BigInt = require('big-integer');
Object.assign(global, {
BigInt: BigInt,
});
}
const isRTL = RTL_LANGUAGES.includes(Language.current);
I18nManager.allowRTL(isRTL);
enableScreens();
enableFreeze(true);
enableBatchedStateUpdates();
LogBox.ignoreLogs(["The 'navigation' object hasn't been initialized"]);
if (__DEV__ && IS_IOS) {
messaging().setAPNSToken('dev-apns-token', 'sandbox');
}
if (Config.SENTRY_DSN && DEBUG_VARS.enableSentry) {
try {
Sentry.init({
dsn: Config.SENTRY_DSN,
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
tracesSampleRate: 1.0,
environment: Config.ENVIRONMENT ?? 'development',
enableWatchdogTerminationTracking: false,
attachScreenshot: true,
attachStacktrace: true,
beforeSend(event, hint) {
if (event.level !== 'fatal') {
delete hint.attachments;
}
return event;
},
});
} catch (e) {
console.log('sentry init failed');
}
}
function getResult(payload) {
if (payload.error) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
throw error;
}
return payload.result;
}
JsonRpcProvider.prototype.send = async function (method, params) {
const request = {
method: method,
params: params,
id: this._nextId++,
jsonrpc: '2.0',
};
const isSendMethod =
['eth_sendRawTransaction', 'eth_sendTransaction'].indexOf(method) >= 0;
const cache = ['eth_chainId', 'eth_blockNumber'].indexOf(method) >= 0;
if (cache && this._cache[method]) {
return this._cache[method];
}
let parsedAddressFrom = 'unknown';
try {
const hexString = params[0].replace(/^0x/, '');
parsedAddressFrom = ethers.utils.parseTransaction(
Buffer.from(hexString, 'hex'),
)?.from;
} catch (e) {}
const eventParams = {
type: 'EVM',
network: Provider.selectedProvider.name,
chainId: `${Provider.selectedProvider.ethChainId}`,
address: parsedAddressFrom,
};
try {
if (isSendMethod) {
EventTracker.instance.trackEvent(
MarketingEvents.sendTxStart,
eventParams,
);
}
const req = await fetch(`${this.connection.url}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
});
if (isSendMethod) {
EventTracker.instance.trackEvent(
MarketingEvents.sendTxSuccess,
eventParams,
);
}
const resp = await req.json();
const result = getResult(resp);
if (cache) {
this._cache[method] = result;
setTimeout(() => {
this._cache[method] = null;
}, 0);
}
return result;
} catch (error) {
if (isSendMethod) {
EventTracker.instance.trackEvent(MarketingEvents.sendTxFail, eventParams);
}
throw error;
}
};
const Wrapped = Sentry.wrap(App);
AppRegistry.registerComponent(appName, () => Wrapped);
AppRegistry.registerComponent('jailbreak', () =>
Config.FOR_DETOX ? Wrapped : Jailbreak,
);