Skip to content

Commit

Permalink
use password for lock checking
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Nov 21, 2023
1 parent 6f99e36 commit 63ad126
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/components/SetupErrorDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ function ErrorFooter() {
);
}

export function SetupErrorDisplay(props: { initialError: Error }) {
export function SetupErrorDisplay(props: {
initialError: Error;
password?: string;
}) {
// Error shouldn't be reactive, so we assign to it so it just gets rendered with the first value
const i18n = useI18n();
const error = props.initialError;

const [lockSeconds, { mutate }] = createResource(async () => {
if (error.message.startsWith("Mutiny is already running")) {
const settings: MutinyWalletSettingStrings = await getSettings();
// todo set password
try {
const secs = await MutinyWallet.get_device_lock_remaining_secs(
undefined,
props.password,
settings.auth,
settings.storage
);
Expand Down
5 changes: 4 additions & 1 deletion src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export function Router() {
return (
<Switch>
<Match when={state.setup_error}>
<SetupErrorDisplay initialError={state.setup_error!} />
<SetupErrorDisplay
initialError={state.setup_error!}
password={state.password}
/>
</Match>
<Match when={true}>
<GlobalListeners />
Expand Down
6 changes: 5 additions & 1 deletion src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type MegaStore = [
subscription_timestamp?: number;
readonly mutiny_plus: boolean;
needs_password: boolean;
password?: string;
load_stage: LoadStage;
settings?: MutinyWalletSettingStrings;
safe_mode?: boolean;
Expand Down Expand Up @@ -122,6 +123,8 @@ export const Provider: ParentComponent = (props) => {
return subscriptionValid(state.subscription_timestamp);
},
needs_password: false,
// If setup fails we can remember the password for checking the device lock
password: undefined as string | undefined,
load_stage: "fresh" as LoadStage,
settings: undefined as MutinyWalletSettingStrings | undefined,
safe_mode: searchParams.safe_mode === "true",
Expand Down Expand Up @@ -218,7 +221,8 @@ export const Provider: ParentComponent = (props) => {
if (eify(e).message === "Incorrect password entered.") {
setState({ needs_password: true });
} else {
setState({ setup_error: eify(e) });
// We only save the password for checking the timelock, will be blown away by the reload
setState({ setup_error: eify(e), password: password });
}
}
},
Expand Down

0 comments on commit 63ad126

Please sign in to comment.