Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 9515f1b

Browse files
committed
handle no connection
1 parent 713c1a6 commit 9515f1b

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"workbox-window": "^7.0.0"
4040
},
4141
"dependencies": {
42-
"i18next-http-backend": "^2.5.0",
4342
"@capacitor-mlkit/barcode-scanning": "^5.3.0",
4443
"@capacitor/android": "^5.5.1",
4544
"@capacitor/app": "^5.0.6",
@@ -49,19 +48,21 @@
4948
"@capacitor/filesystem": "^5.1.4",
5049
"@capacitor/haptics": "^5.0.6",
5150
"@capacitor/ios": "^5.5.1",
51+
"@capacitor/network": "^6.0.0",
5252
"@capacitor/share": "^5.0.6",
5353
"@capacitor/status-bar": "^5.0.6",
5454
"@capacitor/toast": "^5.0.6",
5555
"@kobalte/core": "^0.12.6",
5656
"@kobalte/tailwindcss": "^0.9.0",
57-
"@mutinywallet/mutiny-wasm": "0.6.5",
5857
"@modular-forms/solid": "^0.20.0",
58+
"@mutinywallet/mutiny-wasm": "0.6.5",
5959
"@solid-primitives/upload": "^0.0.117",
6060
"@solidjs/meta": "^0.29.3",
6161
"@solidjs/router": "^0.13.1",
6262
"capacitor-secure-storage-plugin": "^0.9.0",
6363
"i18next": "^23.10.1",
6464
"i18next-browser-languagedetector": "^7.1.0",
65+
"i18next-http-backend": "^2.5.0",
6566
"lucide-solid": "^0.363.0",
6667
"qr-scanner": "^1.4.2",
6768
"solid-js": "^1.8.16",

pnpm-lock.yaml

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/i18n/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,5 +780,10 @@
780780
"nowish": "Nowish",
781781
"seconds_future": "Seconds from now",
782782
"seconds_past": "Just now"
783+
},
784+
"no_connection": {
785+
"title": "No internet connection",
786+
"prompt": "Get back online to start using Mutiny.",
787+
"reload": "Reload"
783788
}
784789
}

src/components/NoConnection.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { WifiOff } from "lucide-solid";
2+
3+
import { Button, DefaultMain } from "~/components/layout";
4+
import { useI18n } from "~/i18n/context";
5+
6+
export function NoConnection() {
7+
const i18n = useI18n();
8+
return (
9+
<DefaultMain>
10+
<div class="mx-auto flex max-w-[20rem] flex-1 flex-col items-center gap-4">
11+
<div class="flex-1" />
12+
<WifiOff class="h-8 w-8" />
13+
<h1 class="text-center text-3xl font-semibold">
14+
{i18n.t("no_connection.title")}
15+
</h1>
16+
<p class="text-center text-xl font-light text-m-grey-350">
17+
{i18n.t("no_connection.prompt")}
18+
</p>
19+
<div class="flex-1" />
20+
<Button layout="full" onClick={() => window.location.reload()}>
21+
{i18n.t("no_connection.reload")}
22+
</Button>
23+
</div>
24+
</DefaultMain>
25+
);
26+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ export * from "./EditProfileForm";
5858
export * from "./ImportNsecForm";
5959
export * from "./LightningAddressShower";
6060
export * from "./FederationInviteShower";
61+
export * from "./NoConnection";

src/router.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
ErrorDisplay,
1717
I18nProvider,
18+
NoConnection,
1819
SetupErrorDisplay,
1920
Toaster
2021
} from "~/components";
@@ -125,6 +126,9 @@ function ChildrenOrError(props: { children: JSX.Element }) {
125126
password={state.password}
126127
/>
127128
</Match>
129+
<Match when={state.network_status?.connectionType === "none"}>
130+
<NoConnection />
131+
</Match>
128132
<Match when={true}>{props.children}</Match>
129133
</Switch>
130134
);

src/state/megaStore.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @refresh reload */
22

33
// Inspired by https://github.com/solidjs/solid-realworld/blob/main/src/store/index.js
4+
import { ConnectionStatus, Network } from "@capacitor/network";
45
import {
56
MutinyBalance,
67
MutinyWallet,
@@ -74,6 +75,7 @@ type MegaStore = [
7475
should_zap_hodl: boolean;
7576
federations?: MutinyFederationIdentity[];
7677
balanceView: "sats" | "fiat" | "hidden";
78+
network_status?: ConnectionStatus;
7779
},
7880
{
7981
setup(password?: string): Promise<void>;
@@ -140,7 +142,8 @@ export const Provider: ParentComponent = (props) => {
140142
testflightPromptDismissed:
141143
localStorage.getItem("testflightPromptDismissed") === "true",
142144
federations: undefined as MutinyFederationIdentity[] | undefined,
143-
balanceView: localStorage.getItem("balanceView") || "sats"
145+
balanceView: localStorage.getItem("balanceView") || "sats",
146+
network_status: undefined as ConnectionStatus | undefined
144147
});
145148

146149
const actions = {
@@ -527,6 +530,15 @@ export const Provider: ParentComponent = (props) => {
527530
return;
528531
}
529532

533+
const _networkListener = Network.addListener(
534+
"networkStatusChange",
535+
async (status) => {
536+
setState({
537+
network_status: status
538+
});
539+
}
540+
);
541+
530542
console.log("checking for browser compatibility");
531543
try {
532544
await checkBrowserCompatibility();

0 commit comments

Comments
 (0)