Repository navigation
Expand file tree
/
Copy pathApp.tsx
More file actions
118 lines (106 loc) · 5.2 KB
/
Copy pathApp.tsx
File metadata and controls
118 lines (106 loc) · 5.2 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
import { NavigationContainer } from '@react-navigation/native';
import React, { useEffect, useState } from 'react';
import { KeyboardProvider } from 'react-native-keyboard-controller';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { SizeClassProvider } from './components/Context/SizeClassProvider';
import { SettingsProvider } from './components/Context/SettingsProvider';
import { getEffectiveTheme } from './components/themes';
import { ContactsProvider } from './components/Context/ContactsProvider';
import MasterView from './navigation/MasterView';
import AppLock from './components/AppLock';
import UpdateGate from './components/UpdateGate';
import DialogHost from './components/Dialog/DialogHost';
import { markNavigationReady, navigationRef } from './NavigationService';
import { useLogger } from '@react-navigation/devtools';
import { StorageProvider } from './components/Context/StorageProvider';
import { useSettings } from './hooks/context/useSettings';
import { initializeRustJsiBridge } from './modules/RustJsiBridge';
import { configureIndexerEndpoints, getNetwork } from './modules/network';
import { bootActiveNetwork } from './modules/networkPreference';
import presentAlert from './components/Alert';
import { useColorScheme } from 'react-native';
// Optional indexer overrides. Expo CLI inlines EXPO_PUBLIC_* variables at bundle time: from .env
// locally, from the EAS environment in store builds, and from the publisher's shell in OTA updates
// (RELEASE.md). Only direct `process.env.EXPO_PUBLIC_*` reads are inlined.
const INDEXER_BASE_URL = process.env.EXPO_PUBLIC_INDEXER_BASE_URL;
const INDEXER_BASE_URL_MAINNET = process.env.EXPO_PUBLIC_INDEXER_BASE_URL_MAINNET;
const INDEXER_BASE_URL_TESTNET4 = process.env.EXPO_PUBLIC_INDEXER_BASE_URL_TESTNET4;
const INDEXER_BASE_URL_SIGNET = process.env.EXPO_PUBLIC_INDEXER_BASE_URL_SIGNET;
const INDEXER_ONION_URL = process.env.EXPO_PUBLIC_INDEXER_ONION_URL;
const INDEXER_ONION_URL_TESTNET4 = process.env.EXPO_PUBLIC_INDEXER_ONION_URL_TESTNET4;
const INDEXER_ONION_URL_SIGNET = process.env.EXPO_PUBLIC_INDEXER_ONION_URL_SIGNET;
const ThemedNavigationContainer = () => {
const colorScheme = useColorScheme();
const { themePreference, settingsLoaded } = useSettings();
useLogger(navigationRef);
if (!settingsLoaded) return null;
return (
<NavigationContainer ref={navigationRef} onReady={markNavigationReady} theme={getEffectiveTheme(themePreference, colorScheme)}>
<UpdateGate>
<MasterView />
</UpdateGate>
{/* Outside the gate on purpose: a locked AppLock swapped out with the app would come back unlocked. */}
<AppLock />
<DialogHost />
</NavigationContainer>
);
};
const App = () => {
// The provider tree does not mount until the active network is known. StorageProvider loads
// wallets on mount and `getActiveNetwork()` is synchronous with a mainnet default, so mounting
// first and hydrating after would briefly show the wrong chain's wallets — and worse, let a
// scan start against the wrong indexer.
const [networkReady, setNetworkReady] = useState(false);
useEffect(() => {
// The only place that reads the environment: the network registry is a leaf module so wallet
// classes (and their unit tests) can import it without any build-time inlining. Every network
// ships its own indexer addresses; these are optional overrides, and a blank one is ignored.
configureIndexerEndpoints(
{
// EXPO_PUBLIC_INDEXER_BASE_URL is the old single-network name, still honoured for mainnet.
bitcoin: INDEXER_BASE_URL_MAINNET || INDEXER_BASE_URL,
testnet4: INDEXER_BASE_URL_TESTNET4,
signet: INDEXER_BASE_URL_SIGNET,
},
// Each chain's own onion address; EXPO_PUBLIC_INDEXER_ONION_URL is mainnet's. A shared one
// would route test-chain scans to the mainnet indexer over Tor.
{
bitcoin: INDEXER_ONION_URL,
testnet4: INDEXER_ONION_URL_TESTNET4,
signet: INDEXER_ONION_URL_SIGNET,
},
);
initializeRustJsiBridge();
bootActiveNetwork()
.then(({ id, fellBackFrom, reason }) => {
if (fellBackFrom) {
const from = getNetwork(fellBackFrom).displayName;
const why = reason === 'disabled' ? `${from} is currently disabled` : `No silent payment indexer is configured for ${from}`;
presentAlert({ message: `${why}, so the app started on ${getNetwork(id).displayName} instead.` });
}
})
.catch((error: any) => {
presentAlert({ message: error?.message ?? String(error) });
})
.finally(() => setNetworkReady(true));
}, []);
if (!networkReady) return null;
return (
// Edge-to-edge Android no longer resizes the window for the keyboard, so keyboard avoidance
// comes from react-native-keyboard-controller on both platforms.
<KeyboardProvider>
<SizeClassProvider>
<SafeAreaProvider>
<StorageProvider>
<SettingsProvider>
<ContactsProvider>
<ThemedNavigationContainer />
</ContactsProvider>
</SettingsProvider>
</StorageProvider>
</SafeAreaProvider>
</SizeClassProvider>
</KeyboardProvider>
);
};
export default App;