Skip to content

Commit

Permalink
add safe mode view
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Aug 16, 2023
1 parent 2d5f967 commit 754b8ab
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function App() {
</Show>
<BalanceBox loading={state.wallet_loading} />
<Suspense>
<Show when={!state.wallet_loading}>
<Show when={!state.wallet_loading && !state.safe_mode}>
<PendingNwc />
</Show>
</Suspense>
Expand Down
49 changes: 33 additions & 16 deletions src/components/BalanceBox.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Show } from "solid-js";
import { Match, Show, Switch } from "solid-js";
import { Button, FancyCard, Indicator } from "~/components/layout";
import { useMegaStore } from "~/state/megaStore";
import { AmountSats, AmountFiat } from "./Amount";
import { A, useNavigate } from "solid-start";
import shuffle from "~/assets/icons/shuffle.svg";
import { useI18n } from "~/i18n/context";
import { InfoBox } from "./InfoBox";

export function LoadingShimmer() {
return (
Expand Down Expand Up @@ -43,22 +44,38 @@ export default function BalanceBox(props: { loading?: boolean }) {
<>
<FancyCard>
<Show when={!props.loading} fallback={<LoadingShimmer />}>
<div class="flex flex-col gap-1">
<div class="text-2xl">
<AmountSats
amountSats={state.balance?.lightning || 0}
icon="lightning"
denominationSize="lg"
/>
</div>
<div class="text-lg text-white/70">
<AmountFiat
amountSats={state.balance?.lightning || 0}
denominationSize="sm"
/>
</div>
</div>
<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="text-2xl">
<AmountSats
amountSats={
state.balance?.lightning || 0
}
icon="lightning"
denominationSize="lg"
/>
</div>
<div class="text-lg text-white/70">
<AmountFiat
amountSats={
state.balance?.lightning || 0
}
denominationSize="sm"
/>
</div>
</div>
</Match>
</Switch>
</Show>

<hr class="my-2 border-m-grey-750" />
<Show when={!props.loading} fallback={<LoadingShimmer />}>
<div class="flex justify-between">
Expand Down
12 changes: 12 additions & 0 deletions src/components/SetupErrorDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export default function SetupErrorDisplay(props: { initialError: Error }) {
</ExternalLink>{" "}
for updates.
</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 />
</DefaultMain>
Expand Down
9 changes: 7 additions & 2 deletions src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default {
why: "Why?",
private_tags: "Private tags",
view_transaction: "View Transaction",
pending: "Pending"
pending: "Pending",
error_safe_mode:
"Mutiny is running in safe mode. Lightning is disabled."
},
contacts: {
new: "new",
Expand Down Expand Up @@ -479,7 +481,10 @@ export default {
"If you have any questions on what these buttons do, please",
support_link: "reach out to us for support.",
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"
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export async function initializeWasm() {

export async function setupMutinyWallet(
settings: MutinyWalletSettingStrings,
password?: string
password?: string,
safeMode?: boolean
): Promise<MutinyWallet> {
console.log("Starting setup...");

Expand All @@ -189,6 +190,7 @@ export async function setupMutinyWallet(
console.log("Using subscriptions address", subscriptions);
console.log("Using storage address", storage);
console.log("Using scorer address", scorer);
console.log(safeMode ? "Safe mode enabled" : "Safe mode disabled");

const mutinyWallet = await new MutinyWallet(
// Password
Expand All @@ -207,7 +209,9 @@ export async function setupMutinyWallet(
// Do not connect peers
undefined,
// Do not skip device lock
undefined
undefined,
// Safe mode
safeMode || undefined
);

sessionStorage.setItem("MUTINY_WALLET_INITIALIZED", Date.now().toString());
Expand Down
10 changes: 8 additions & 2 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import eify from "~/utils/eify";
import { timeout } from "~/utils/timeout";
import { ParsedParams } from "~/logic/waila";
import { subscriptionValid } from "~/utils/subscriptions";
import { useSearchParams } from "solid-start";

const MegaStoreContext = createContext<MegaStore>();

Expand Down Expand Up @@ -53,6 +54,7 @@ export type MegaStore = [
needs_password: boolean;
load_stage: LoadStage;
settings?: MutinyWalletSettingStrings;
safe_mode?: boolean;
},
{
setup(password?: string): Promise<void>;
Expand All @@ -67,6 +69,8 @@ export type MegaStore = [
];

export const Provider: ParentComponent = (props) => {
const [searchParams] = useSearchParams();

const [state, setState] = createStore({
mutiny_wallet: undefined as MutinyWallet | undefined,
deleting: false,
Expand All @@ -87,7 +91,8 @@ export const Provider: ParentComponent = (props) => {
},
needs_password: false,
load_stage: "fresh" as LoadStage,
settings: undefined as MutinyWalletSettingStrings | undefined
settings: undefined as MutinyWalletSettingStrings | undefined,
safe_mode: searchParams.safe_mode === "true"
});

const actions = {
Expand Down Expand Up @@ -132,7 +137,8 @@ export const Provider: ParentComponent = (props) => {

const mutinyWallet = await setupMutinyWallet(
settings,
password
password,
state.safe_mode
);

// Give other components access to settings via the store
Expand Down

0 comments on commit 754b8ab

Please sign in to comment.