add safe mode view

This commit is contained in:
Paul Miller
2023-08-16 15:23:31 -05:00
parent 2d5f96788f
commit 754b8ab7c2
6 changed files with 67 additions and 23 deletions

View File

@@ -69,7 +69,7 @@ export default function App() {
</Show> </Show>
<BalanceBox loading={state.wallet_loading} /> <BalanceBox loading={state.wallet_loading} />
<Suspense> <Suspense>
<Show when={!state.wallet_loading}> <Show when={!state.wallet_loading && !state.safe_mode}>
<PendingNwc /> <PendingNwc />
</Show> </Show>
</Suspense> </Suspense>

View File

@@ -1,10 +1,11 @@
import { Show } from "solid-js"; import { Match, Show, Switch } from "solid-js";
import { Button, FancyCard, Indicator } from "~/components/layout"; import { Button, FancyCard, Indicator } from "~/components/layout";
import { useMegaStore } from "~/state/megaStore"; import { useMegaStore } from "~/state/megaStore";
import { AmountSats, AmountFiat } from "./Amount"; import { AmountSats, AmountFiat } from "./Amount";
import { A, useNavigate } from "solid-start"; import { A, useNavigate } from "solid-start";
import shuffle from "~/assets/icons/shuffle.svg"; import shuffle from "~/assets/icons/shuffle.svg";
import { useI18n } from "~/i18n/context"; import { useI18n } from "~/i18n/context";
import { InfoBox } from "./InfoBox";
export function LoadingShimmer() { export function LoadingShimmer() {
return ( return (
@@ -43,22 +44,38 @@ export default function BalanceBox(props: { loading?: boolean }) {
<> <>
<FancyCard> <FancyCard>
<Show when={!props.loading} fallback={<LoadingShimmer />}> <Show when={!props.loading} fallback={<LoadingShimmer />}>
<Switch>
<Match when={state.safe_mode}>
<div class="flex flex-col gap-1">
<InfoBox accent="red">
{i18n.t("common.error_safe_mode")}
</InfoBox>
</div>
</Match>
<Match when={true}>
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
<div class="text-2xl"> <div class="text-2xl">
<AmountSats <AmountSats
amountSats={state.balance?.lightning || 0} amountSats={
state.balance?.lightning || 0
}
icon="lightning" icon="lightning"
denominationSize="lg" denominationSize="lg"
/> />
</div> </div>
<div class="text-lg text-white/70"> <div class="text-lg text-white/70">
<AmountFiat <AmountFiat
amountSats={state.balance?.lightning || 0} amountSats={
state.balance?.lightning || 0
}
denominationSize="sm" denominationSize="sm"
/> />
</div> </div>
</div> </div>
</Match>
</Switch>
</Show> </Show>
<hr class="my-2 border-m-grey-750" /> <hr class="my-2 border-m-grey-750" />
<Show when={!props.loading} fallback={<LoadingShimmer />}> <Show when={!props.loading} fallback={<LoadingShimmer />}>
<div class="flex justify-between"> <div class="flex justify-between">

View File

@@ -60,6 +60,18 @@ export default function SetupErrorDisplay(props: { initialError: Error }) {
</ExternalLink>{" "} </ExternalLink>{" "}
for updates. for updates.
</NiceP> </NiceP>
<NiceP>
{i18n.t(
"error.on_boot.loading_failed.in_the_meantime"
)}{" "}
<a href="/?safe_mode=true">
{" "}
{i18n.t(
"error.on_boot.loading_failed.safe_mode"
)}
</a>
.
</NiceP>
<ErrorFooter /> <ErrorFooter />
</DefaultMain> </DefaultMain>

View File

@@ -19,7 +19,9 @@ export default {
why: "Why?", why: "Why?",
private_tags: "Private tags", private_tags: "Private tags",
view_transaction: "View Transaction", view_transaction: "View Transaction",
pending: "Pending" pending: "Pending",
error_safe_mode:
"Mutiny is running in safe mode. Lightning is disabled."
}, },
contacts: { contacts: {
new: "new", new: "new",
@@ -479,7 +481,10 @@ export default {
"If you have any questions on what these buttons do, please", "If you have any questions on what these buttons do, please",
support_link: "reach out to us for support.", support_link: "reach out to us for support.",
services_down: services_down:
"It looks like one of Mutiny's services is down. Please try again later." "It looks like one of Mutiny's services is down. Please try again later.",
in_the_meantime:
"In the meantime if you want to access your on-chain funds you can load Mutiny in",
safe_mode: "Safe Mode"
} }
} }
}, },

View File

@@ -163,7 +163,8 @@ export async function initializeWasm() {
export async function setupMutinyWallet( export async function setupMutinyWallet(
settings: MutinyWalletSettingStrings, settings: MutinyWalletSettingStrings,
password?: string password?: string,
safeMode?: boolean
): Promise<MutinyWallet> { ): Promise<MutinyWallet> {
console.log("Starting setup..."); console.log("Starting setup...");
@@ -189,6 +190,7 @@ export async function setupMutinyWallet(
console.log("Using subscriptions address", subscriptions); console.log("Using subscriptions address", subscriptions);
console.log("Using storage address", storage); console.log("Using storage address", storage);
console.log("Using scorer address", scorer); console.log("Using scorer address", scorer);
console.log(safeMode ? "Safe mode enabled" : "Safe mode disabled");
const mutinyWallet = await new MutinyWallet( const mutinyWallet = await new MutinyWallet(
// Password // Password
@@ -207,7 +209,9 @@ export async function setupMutinyWallet(
// Do not connect peers // Do not connect peers
undefined, undefined,
// Do not skip device lock // Do not skip device lock
undefined undefined,
// Safe mode
safeMode || undefined
); );
sessionStorage.setItem("MUTINY_WALLET_INITIALIZED", Date.now().toString()); sessionStorage.setItem("MUTINY_WALLET_INITIALIZED", Date.now().toString());

View File

@@ -24,6 +24,7 @@ import eify from "~/utils/eify";
import { timeout } from "~/utils/timeout"; import { timeout } from "~/utils/timeout";
import { ParsedParams } from "~/logic/waila"; import { ParsedParams } from "~/logic/waila";
import { subscriptionValid } from "~/utils/subscriptions"; import { subscriptionValid } from "~/utils/subscriptions";
import { useSearchParams } from "solid-start";
const MegaStoreContext = createContext<MegaStore>(); const MegaStoreContext = createContext<MegaStore>();
@@ -53,6 +54,7 @@ export type MegaStore = [
needs_password: boolean; needs_password: boolean;
load_stage: LoadStage; load_stage: LoadStage;
settings?: MutinyWalletSettingStrings; settings?: MutinyWalletSettingStrings;
safe_mode?: boolean;
}, },
{ {
setup(password?: string): Promise<void>; setup(password?: string): Promise<void>;
@@ -67,6 +69,8 @@ export type MegaStore = [
]; ];
export const Provider: ParentComponent = (props) => { export const Provider: ParentComponent = (props) => {
const [searchParams] = useSearchParams();
const [state, setState] = createStore({ const [state, setState] = createStore({
mutiny_wallet: undefined as MutinyWallet | undefined, mutiny_wallet: undefined as MutinyWallet | undefined,
deleting: false, deleting: false,
@@ -87,7 +91,8 @@ export const Provider: ParentComponent = (props) => {
}, },
needs_password: false, needs_password: false,
load_stage: "fresh" as LoadStage, load_stage: "fresh" as LoadStage,
settings: undefined as MutinyWalletSettingStrings | undefined settings: undefined as MutinyWalletSettingStrings | undefined,
safe_mode: searchParams.safe_mode === "true"
}); });
const actions = { const actions = {
@@ -132,7 +137,8 @@ export const Provider: ParentComponent = (props) => {
const mutinyWallet = await setupMutinyWallet( const mutinyWallet = await setupMutinyWallet(
settings, settings,
password password,
state.safe_mode
); );
// Give other components access to settings via the store // Give other components access to settings via the store