forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork.ts
35 lines (29 loc) · 1.1 KB
/
Network.ts
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
import Onyx from 'react-native-onyx';
import Log from '@libs/Log';
import type {NetworkStatus} from '@libs/NetworkConnection';
import ONYXKEYS from '@src/ONYXKEYS';
function setIsOffline(isOffline: boolean, reason = '') {
if (reason) {
let textToLog = '[Network] Client is';
textToLog += isOffline ? ' entering offline mode' : ' back online';
textToLog += ` because: ${reason}`;
Log.info(textToLog);
}
Onyx.merge(ONYXKEYS.NETWORK, {isOffline});
}
function setNetWorkStatus(status: NetworkStatus) {
Onyx.merge(ONYXKEYS.NETWORK, {networkStatus: status});
}
function setTimeSkew(skew: number) {
Onyx.merge(ONYXKEYS.NETWORK, {timeSkew: skew});
}
function setShouldForceOffline(shouldForceOffline: boolean) {
Onyx.merge(ONYXKEYS.NETWORK, {shouldForceOffline});
}
/**
* Test tool that will fail all network requests when enabled
*/
function setShouldFailAllRequests(shouldFailAllRequests: boolean) {
Onyx.merge(ONYXKEYS.NETWORK, {shouldFailAllRequests});
}
export {setIsOffline, setShouldForceOffline, setShouldFailAllRequests, setTimeSkew, setNetWorkStatus};