This repository was archived by the owner on Apr 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathrouter.tsx
More file actions
211 lines (201 loc) · 7.11 KB
/
Copy pathrouter.tsx
File metadata and controls
211 lines (201 loc) · 7.11 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { App as CapacitorApp } from "@capacitor/app";
import { Capacitor } from "@capacitor/core";
import { StatusBar, Style } from "@capacitor/status-bar";
import { MetaProvider, Title } from "@solidjs/meta";
import { Route, Router as SolidRouter, useNavigate } from "@solidjs/router";
import {
ErrorBoundary,
JSX,
Match,
onCleanup,
onMount,
Suspense,
Switch
} from "solid-js";
import {
ErrorDisplay,
I18nProvider,
NoConnection,
SetupErrorDisplay,
Toaster
} from "~/components";
import {
Chat,
EditProfile,
Feedback,
Main,
NotFound,
Profile,
Receive,
Redeem,
RequestRoute,
Scanner,
Search,
Send,
Swap,
SwapLightning
} from "~/routes";
import {
Admin,
Backup,
Channels,
Connections,
Currency,
EmergencyKit,
Encrypt,
ImportProfileSettings,
Language,
LightningAddress,
ManageFederations,
NostrKeys,
Plus,
Restore,
Servers,
Settings
} from "~/routes/settings";
import {
AddFederation,
ImportProfile,
NewProfile,
Setup,
SetupRestore
} from "~/routes/setup";
import { Provider as MegaStoreProvider, useMegaStore } from "~/state/megaStore";
const setStatusBarStyleDark = async () => {
await StatusBar.setStyle({ style: Style.Dark });
};
if (Capacitor.isNativePlatform()) {
await setStatusBarStyleDark();
}
function ChildrenOrError(props: { children: JSX.Element }) {
const [state] = useMegaStore();
return (
<Switch>
<Match when={state.network_status?.connectionType === "none"}>
<NoConnection />
</Match>
<Match when={state.setup_error}>
<SetupErrorDisplay
initialError={state.setup_error!}
password={state.password}
/>
</Match>
<Match when={true}>{props.children}</Match>
</Switch>
);
}
export function Router() {
// listeners for native navigation handling
// Check if the platform is Android to handle back
onMount(async () => {
if (Capacitor.getPlatform() === "android") {
const { remove } = await CapacitorApp.addListener(
"backButton",
({ canGoBack }) => {
if (!canGoBack) {
CapacitorApp.exitApp();
} else {
window.history.back();
}
}
);
// Ensure the listener is cleaned up when the component is destroyed
onCleanup(() => {
console.debug("cleaning up backButton listener");
remove();
});
}
// Handle app links on native platforms
if (Capacitor.isNativePlatform()) {
const navigate = useNavigate();
const { remove } = await CapacitorApp.addListener(
"appUrlOpen",
(data) => {
const url = new URL(data.url);
const path = url.pathname;
const urlParams = new URLSearchParams(url.search);
console.log(
`Navigating to ${path}?${urlParams.toString()}`
);
navigate(`${path}?${urlParams.toString()}`);
}
);
onCleanup(() => {
console.debug("cleaning up appUrlOpen listener");
remove();
});
}
});
return (
<SolidRouter
root={(props) => (
<MetaProvider>
<Title>Mutiny Wallet</Title>
<ErrorBoundary fallback={(e) => <ErrorDisplay error={e} />}>
<Suspense>
<ErrorBoundary
fallback={(e) => <ErrorDisplay error={e} />}
>
<MegaStoreProvider>
<I18nProvider>
<ErrorBoundary
fallback={(e) => (
<ErrorDisplay error={e} />
)}
>
<ChildrenOrError>
{props.children}
</ChildrenOrError>
<Toaster />
</ErrorBoundary>
</I18nProvider>
</MegaStoreProvider>
</ErrorBoundary>
</Suspense>
</ErrorBoundary>
</MetaProvider>
)}
>
<Route path="/" component={Main} />
<Route path="/setup" component={Setup} />
<Route path="/setup/restore" component={SetupRestore} />
<Route path="/addfederation" component={AddFederation} />
<Route path="/newprofile" component={NewProfile} />
<Route path="/editprofile" component={EditProfile} />
<Route path="/importprofile" component={ImportProfile} />
<Route path="/profile" component={Profile} />
<Route path="/chat/:id" component={Chat} />
<Route path="/feedback" component={Feedback} />
<Route path="/receive" component={Receive} />
<Route path="/redeem" component={Redeem} />
<Route path="/request/:id" component={RequestRoute} />
<Route path="/scanner" component={Scanner} />
<Route path="/send" component={Send} />
<Route path="/swap" component={Swap} />
<Route path="/swaplightning" component={SwapLightning} />
<Route path="/search" component={Search} />
<Route path="/settings">
<Route path="/" component={Settings} />
<Route path="/admin" component={Admin} />
<Route path="/backup" component={Backup} />
<Route path="/channels" component={Channels} />
<Route path="/connections" component={Connections} />
<Route path="/currency" component={Currency} />
<Route path="/language" component={Language} />
<Route path="/emergencykit" component={EmergencyKit} />
<Route path="/encrypt" component={Encrypt} />
<Route path="/plus" component={Plus} />
<Route path="/restore" component={Restore} />
<Route path="/servers" component={Servers} />
<Route path="/nostrkeys" component={NostrKeys} />
<Route
path="/importprofile"
component={ImportProfileSettings}
/>
<Route path="/federations" component={ManageFederations} />
<Route path="/lightningaddress" component={LightningAddress} />
</Route>
<Route path="/*all" component={NotFound} />
</SolidRouter>
);
}