Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
feat(ui): lock screen on key store unseal (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Merle Breitkreuz committed Nov 5, 2020
1 parent 4df7986 commit 4a8213b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
7 changes: 1 addition & 6 deletions ui/App.svelte
Expand Up @@ -107,12 +107,7 @@
<Bsod />
</div>

<!-- TODO(julien): Dress up loading screen -->
<div slot="loading" class="error">
{#if $location === path.lock()}
<EmptyState headerText="Unlocking the app..." emoji="🚪" text="" />
{:else}
<EmptyState headerText="Loading..." emoji="🕵️" text="" />
{/if}
<EmptyState headerText="Loading..." emoji="🕵️" text="" />
</div>
</Remote>
14 changes: 11 additions & 3 deletions ui/Screen/Lock.svelte
@@ -1,16 +1,23 @@
<script lang="ts">
import * as screen from "../src/screen";
import * as session from "../src/session";
import { Button, Emoji, Input } from "../DesignSystem/Primitive";
let passphrase = "";
let unlockInProgress = false;
const unlock = async () => {
await session.unseal(passphrase);
unlockInProgress = true;
screen.lock();
await session.unseal(passphrase).finally(() => {
screen.unlock();
unlockInProgress = false;
});
};
const onEnter = () => {
if (passphrase.length > 0) {
if (passphrase.length > 0 && !unlockInProgress) {
unlock();
}
};
Expand Down Expand Up @@ -42,12 +49,13 @@
autofocus
placeholder="Enter your passphrase"
bind:value={passphrase}
disabled={unlockInProgress}
dataCy="passphrase-input"
on:enter={onEnter}
style="width: 16rem; margin-right: 1rem;" />
<Button
dataCy="unlock-button"
disabled={passphrase.length === 0}
disabled={passphrase.length === 0 || unlockInProgress}
on:click={unlock}>
Unlock
</Button>
Expand Down
9 changes: 8 additions & 1 deletion ui/Screen/Onboarding.svelte
Expand Up @@ -5,6 +5,7 @@
import * as notification from "../src/notification.ts";
import { State } from "../src/onboarding.ts";
import { createIdentity } from "../src/identity.ts";
import * as screen from "../src/screen.ts";
import * as session from "../src/session.ts";
import * as urn from "../src/urn.ts";
Expand All @@ -16,6 +17,7 @@
let identity;
let handle;
let state = State.Welcome;
let createIdentityInProgress = false;
let inY = 1000;
let outY = -1000;
Expand All @@ -38,9 +40,10 @@
const onCreateIdentity = async (handle, passphrase) => {
try {
screen.lock();
createIdentityInProgress = true;
await session.createKeystore(passphrase);
// Retry until the API is up
notification.info("Creating the identity...");
identity = await withRetry(() => createIdentity({ handle }), 200);
state = State.SuccessView;
} catch (error) {
Expand All @@ -49,6 +52,9 @@
notification.error(
`Could not create identity: ${urn.shorten(error.message)}`
);
} finally {
screen.unlock();
createIdentityInProgress = false;
}
};
</script>
Expand Down Expand Up @@ -98,6 +104,7 @@
<div class="content" in:fly={{ y: inY }} out:fly={{ y: outY }}>
<div class="inner">
<EnterPassphrase
disabled={createIdentityInProgress}
on:previous={() => {
animateBackward();
state = State.EnterName;
Expand Down
16 changes: 12 additions & 4 deletions ui/Screen/Onboarding/EnterPassphrase.svelte
Expand Up @@ -8,6 +8,8 @@
import { Button, Input } from "../../DesignSystem/Primitive";
export let disabled = false;
const dispatch = createEventDispatcher();
let repeatedPassphraseInput;
Expand Down Expand Up @@ -76,7 +78,10 @@
}
$: allowNext =
passphrase && passphrase === repeatedPassphrase && !validations;
passphrase &&
passphrase === repeatedPassphrase &&
!validations &&
!disabled;
let ran = false;
Expand Down Expand Up @@ -139,7 +144,8 @@
hint=""
style="margin-top: 1.5rem;"
validation={passphraseValidation}
bind:value={passphrase} />
bind:value={passphrase}
{disabled} />

<div class="repeat" hidden={!passphrase}>
<p style="margin-bottom: 0.5rem;">And enter it again, just to be safe.</p>
Expand All @@ -150,15 +156,17 @@
placeholder="Repeat the secure passphrase"
hint=""
validation={repeatedPassphraseValidation}
bind:value={repeatedPassphrase} />
bind:value={repeatedPassphrase}
{disabled} />
</div>

<div class="buttons">
<Button
dataCy="back-button"
variant="transparent"
style="margin-right: 1rem;"
on:click={() => dispatch('previous')}>
on:click={() => dispatch('previous')}
{disabled}>
Back
</Button>

Expand Down
2 changes: 0 additions & 2 deletions ui/src/session.ts
Expand Up @@ -105,8 +105,6 @@ export const unseal = async (passphrase: string): Promise<boolean> => {
try {
await api.set<unknown>(`keystore/unseal`, { passphrase });
} catch (error) {
sessionStore.loading();
sessionStore.success({ status: Status.SealedSession });
notification.error(`Could not unlock the session: ${error.message}`);
return false;
}
Expand Down

0 comments on commit 4a8213b

Please sign in to comment.