Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle no connection #1078

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions public/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,10 @@
"nowish": "Nowish",
"seconds_future": "Seconds from now",
"seconds_past": "Just now"
},
"no_connection": {
"title": "No internet connection",
"prompt": "Get back online to start using Mutiny.",
"reload": "Reload"
}
}
26 changes: 26 additions & 0 deletions src/components/NoConnection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { WifiOff } from "lucide-solid";

import { Button, DefaultMain } from "~/components/layout";
import { useI18n } from "~/i18n/context";

export function NoConnection() {
const i18n = useI18n();
return (
<DefaultMain>
<div class="mx-auto flex max-w-[20rem] flex-1 flex-col items-center gap-4">
<div class="flex-1" />
<WifiOff class="h-8 w-8" />
<h1 class="text-center text-3xl font-semibold">
{i18n.t("no_connection.title")}
</h1>
<p class="text-center text-xl font-light text-m-grey-350">
{i18n.t("no_connection.prompt")}
</p>
<div class="flex-1" />
<Button layout="full" onClick={() => window.location.reload()}>
{i18n.t("no_connection.reload")}
</Button>
</div>
</DefaultMain>
);
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ export * from "./EditProfileForm";
export * from "./ImportNsecForm";
export * from "./LightningAddressShower";
export * from "./FederationInviteShower";
export * from "./NoConnection";
4 changes: 4 additions & 0 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {
ErrorDisplay,
I18nProvider,
NoConnection,
SetupErrorDisplay,
Toaster
} from "~/components";
Expand Down Expand Up @@ -75,6 +76,9 @@ function ChildrenOrError(props: { children: JSX.Element }) {

return (
<Switch>
<Match when={state.network_status?.connectionType === "none"}>
<NoConnection />
</Match>
<Match when={state.setup_error}>
<SetupErrorDisplay
initialError={state.setup_error!}
Expand Down
16 changes: 15 additions & 1 deletion src/state/megaStore.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Inspired by https://github.com/solidjs/solid-realworld/blob/main/src/store/index.js
import {
Network as CapacitorNetwork,
ConnectionStatus
} from "@capacitor/network";
import { MutinyBalance, TagItem } from "@mutinywallet/mutiny-wasm";
import { useNavigate, useSearchParams } from "@solidjs/router";
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin";
Expand Down Expand Up @@ -87,7 +91,8 @@ export const makeMegaStoreContext = () => {
testflightPromptDismissed:
localStorage.getItem("testflightPromptDismissed") === "true",
federations: undefined as MutinyFederationIdentity[] | undefined,
balanceView: localStorage.getItem("balanceView") || "sats"
balanceView: localStorage.getItem("balanceView") || "sats",
network_status: undefined as ConnectionStatus | undefined
});

const actions = {
Expand Down Expand Up @@ -506,6 +511,9 @@ export const makeMegaStoreContext = () => {
channel.postMessage({ type: "EXISTING_TAB" });
}
};
},
setNetworkStatus(status: ConnectionStatus) {
setState({ network_status: status });
}
};

Expand All @@ -521,6 +529,12 @@ export const Provider: ParentComponent = (props) => {
const [state, actions, sw] = makeMegaStoreContext();

onMount(async () => {
const _networkListener = CapacitorNetwork.addListener(
"networkStatusChange",
async (status) => {
actions.setNetworkStatus(status);
}
);
const shouldSetup = await actions.preSetup();
console.log("Should run setup?", shouldSetup);
if (
Expand Down