Skip to content

Commit

Permalink
handle no connection
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed May 9, 2024
1 parent 9cde791 commit ae16a88
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
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

0 comments on commit ae16a88

Please sign in to comment.