This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
App.svelte
293 lines (271 loc) · 9.7 KB
/
App.svelte
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!--
Copyright © 2021 The Radicle Upstream Contributors
This file is part of radicle-upstream, distributed under the GPLv3
with Radicle Linking Exception. For full terms see the included
LICENSE file.
-->
<script lang="ts">
import * as Session from "ui/src/session";
import * as config from "ui/src/config";
import * as customProtocolHandler from "ui/src/customProtocolHandler";
import * as error from "ui/src/error";
import * as ethereum from "ui/src/ethereum";
import * as hotkeys from "ui/src/hotkeys";
import * as ipc from "ui/src/ipc";
import * as notification from "ui/src/notification";
import * as org from "./src/org";
import * as remote from "ui/src/remote";
import * as router from "ui/src/router";
import * as transaction from "ui/src/transaction";
import * as walletModule from "ui/src/wallet";
import { unreachable } from "ui/src/unreachable";
import "ui/src/localPeer";
import Hotkeys from "ui/App/Hotkeys.svelte";
import ModalLayout from "ui/App/ModalLayout.svelte";
import Notifications from "ui/App/Notifications.svelte";
import Theme from "ui/App/Theme.svelte";
import DesignSystemShowcaseModal from "design-system/Showcase.svelte";
import Tooltip from "design-system/Tooltip.svelte";
import Loading from "ui/App/SharedComponents/Loading.svelte";
import SharedComponentShowcase from "ui/App/SharedComponents/SharedComponentShowcase.svelte";
import CodeFontSetting from "ui/App/SharedComponents/CodeFontSetting.svelte";
import PrimaryColorSetting from "ui/App/SharedComponents/PrimaryColorSetting.svelte";
import ThemeSetting from "ui/App/SharedComponents/ThemeSetting.svelte";
import UiFontSetting from "ui/App/SharedComponents/UiFontSetting.svelte";
import OnboardingModal from "ui/App/OnboardingModal.svelte";
import {
INSTALL_GIT_URL,
REQUIRED_GIT_VERSION,
checkGit,
} from "ui/App/OnboardingModal.svelte";
import LockScreen from "ui/App/LockScreen.svelte";
import DiagnosticsScreen from "ui/App/DiagnosticsScreen.svelte";
import PushPullNetworkScreen from "ui/App/PushPullNetworkScreen.svelte";
import OrgsScreen from "ui/App/OrgsScreen.svelte";
import OrgScreen from "ui/App/OrgScreen.svelte";
import ProfileScreen from "ui/App/ProfileScreen.svelte";
import ProjectScreen from "ui/App/ProjectScreen.svelte";
import SettingsScreen from "ui/App/SettingsScreen.svelte";
import SingleSigOrgScreen from "ui/App/SingleSigOrgScreen.svelte";
import ProxyErrorScreen from "ui/App/ProxyErrorScreen.svelte";
import UserProfileScreen from "ui/App/UserProfileScreen.svelte";
import WalletScreen from "ui/App/WalletScreen.svelte";
router.initialize();
customProtocolHandler.register();
org.initialize();
transaction.initialize();
// If we’re not in any kind of test environment we show unhandled
// errors to the user.
if (!config.isNodeTestEnv) {
window.addEventListener("unhandledrejection", ev => {
ev.preventDefault();
notification.showException(
error.fromUnknown(ev.reason, error.Code.UnhandledRejection)
);
});
window.addEventListener("error", ev => {
ev.preventDefault();
notification.showException(
error.fromUnknown(ev.error, error.Code.UnhandledError)
);
});
}
const activeRouteStore = router.activeRouteStore;
const ethereumEnvironment = ethereum.selectedEnvironment;
const sessionStore = Session.session;
const walletStore = walletModule.store;
async function notifyMissingGit(): Promise<void> {
const result = await checkGit();
if (!result.passed) {
const message = `Required git version ${REQUIRED_GIT_VERSION} could not be found`;
notification.show({
type: "error",
message,
persist: true,
actions: [
{
label: "Install git",
handler: () => {
ipc.openUrl(INSTALL_GIT_URL);
},
},
{
label: "Copy error",
handler: () => {
ipc.copyToClipboard(
JSON.stringify(
{
message,
detectedGitVersion: result.version,
requiredGitVersion: REQUIRED_GIT_VERSION,
searchPath: config.config.path,
},
null,
2
)
);
},
},
{
label: "Dismiss",
handler: () => {},
},
],
});
}
}
async function showDeprecationNotification(): Promise<void> {
notification.show({
type: "error",
message: "Upstream is being sunsetted",
persist: true,
actions: [
{
label: "Read more",
handler: () => {
ipc.openUrl(
"https://radicle.community/t/upstream-july-2022-community-update"
);
},
},
],
});
}
sessionStore.subscribe(session => {
// We’re not using a reactive statement here to prevent this code from
// running when `activeRouteStore` is updated.
switch (session.status) {
case remote.Status.NotAsked:
Session.fetch();
break;
case remote.Status.Success:
showDeprecationNotification();
if (session.data.status === Session.Status.NoSession) {
hotkeys.disable();
router.replace({ type: "onboarding" });
} else if (session.data.status === Session.Status.SealedSession) {
hotkeys.disable();
router.replace({ type: "lock" });
} else if (session.data.status === Session.Status.UnsealedSession) {
hotkeys.enable();
if (
$activeRouteStore.type === "onboarding" ||
$activeRouteStore.type === "lock" ||
$activeRouteStore.type === "boot"
) {
router.replace({ type: "profile" });
notifyMissingGit();
}
} else if (session.data.status === Session.Status.ProxyDown) {
router.replace({ type: "onboarding" });
} else {
unreachable(session.data);
}
break;
case remote.Status.Error:
notification.showException(session.error);
break;
}
});
$: connectedNetwork = ethereum.supportedNetwork($ethereumEnvironment);
$: wallet = $walletStore;
$: walletState = $wallet;
// If we're on an org screen and there's a wallet mismatch, go to the wallet
// screen to inform the user about the mismatch.
$: if (
walletState.status === walletModule.Status.Connected &&
connectedNetwork !== walletState.connected.network &&
($activeRouteStore.type === "singleSigOrg" ||
$activeRouteStore.type === "multiSigOrg")
) {
router.push({ type: "wallet", activeTab: "transactions" });
}
</script>
<style>
.settings {
right: 132px;
top: 24px;
position: absolute;
z-index: 10;
display: flex;
align-items: center;
gap: 1rem;
}
</style>
<ProxyErrorScreen />
<Hotkeys />
<ModalLayout />
<Notifications />
<Theme />
{#if $sessionStore.status === remote.Status.Success}
{#if $activeRouteStore.type === "designSystemGuide"}
<DesignSystemShowcaseModal onClose={() => router.pop()}>
<div class="settings" slot="top">
<Tooltip value="Theme" position="bottom">
<ThemeSetting />
</Tooltip>
<Tooltip value="UI font" position="bottom">
<UiFontSetting />
</Tooltip>
<Tooltip value="Code font" position="bottom">
<CodeFontSetting />
</Tooltip>
<Tooltip value="Primary color" position="bottom">
<PrimaryColorSetting />
</Tooltip>
</div>
<div slot="bottom">
<SharedComponentShowcase />
</div>
</DesignSystemShowcaseModal>
{:else if $activeRouteStore.type === "lock"}
<LockScreen />
{:else if $activeRouteStore.type === "onboarding"}
<OnboardingModal />
{:else if $activeRouteStore.type === "profile"}
<ProfileScreen />
{:else if $activeRouteStore.type === "userProfile"}
<UserProfileScreen
ownUserUrn={$activeRouteStore.ownUserUrn}
user={$activeRouteStore.user}
projects={$activeRouteStore.projects} />
{:else if $activeRouteStore.type === "diagnostics"}
<DiagnosticsScreen activeTab={$activeRouteStore.activeTab} />
{:else if $activeRouteStore.type === "singleSigOrg"}
<SingleSigOrgScreen
registration={$activeRouteStore.registration}
address={$activeRouteStore.address}
owner={$activeRouteStore.owner}
projectCount={$activeRouteStore.projectCount}
showWriteActions={$activeRouteStore.showWriteActions}
anchors={$activeRouteStore.anchors} />
{:else if $activeRouteStore.type === "multiSigOrg"}
<OrgScreen
registration={$activeRouteStore.registration}
activeTab={$activeRouteStore.view}
address={$activeRouteStore.address}
gnosisSafeAddress={$activeRouteStore.gnosisSafeAddress}
threshold={$activeRouteStore.threshold}
showWriteActions={$activeRouteStore.showWriteActions}
memberCount={$activeRouteStore.memberCount} />
{:else if $activeRouteStore.type === "project"}
<ProjectScreen
activeView={$activeRouteStore.activeView}
urn={$activeRouteStore.urn}
anchors={$activeRouteStore.anchors} />
{:else if $activeRouteStore.type === "network"}
<PushPullNetworkScreen />
{:else if $activeRouteStore.type === "orgs"}
<OrgsScreen />
{:else if $activeRouteStore.type === "settings"}
<SettingsScreen />
{:else if $activeRouteStore.type === "wallet"}
<WalletScreen activeTab={$activeRouteStore.activeTab} />
{:else if $activeRouteStore.type === "boot"}
<Loading style="width: 100vw; height: 100vh;" />
{:else}
{unreachable($activeRouteStore)}
{/if}
{:else}
<Loading style="width: 100vw; height: 100vh;" />
{/if}