Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nortonandreev committed Mar 14, 2024
1 parent 86ab28e commit de40a2c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 55 deletions.
111 changes: 59 additions & 52 deletions web-wallet/src/lib/dusk/components/Mnemonic/Mnemonic.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
enteredMnemonicPhrase = Array(wordLimit).fill("");
}
const isTriggeredByLogin =
enteredMnemonicPhrase.some((word) => word !== "") && currentIndex === 0;
/**
* @param {string} word
* @param {string} index
Expand Down Expand Up @@ -118,63 +121,67 @@
</script>
<div {...$$restProps} class={classes}>
<div class="dusk-mnemonic__actions-wrapper">
{#if type === "authenticate" && shouldShowPaste}
{#if !isTriggeredByLogin}
<div class="dusk-mnemonic__actions-wrapper">
{#if type === "authenticate" && shouldShowPaste}
<Button
icon={{ path: mdiContentPaste }}
text="Paste seed phrase"
variant="tertiary"
on:click={pasteSeed}
/>
{/if}
<Button
icon={{ path: mdiContentPaste }}
text="Paste seed phrase"
disabled={!currentIndex}
on:click={undoLastWord}
icon={{ path: mdiRedoVariant }}
text="Undo"
variant="tertiary"
on:click={pasteSeed}
/>
{/if}
<Button
disabled={!currentIndex}
on:click={undoLastWord}
icon={{ path: mdiRedoVariant }}
text="Undo"
variant="tertiary"
/>
</div>
</div>
{/if}
<Words words={enteredMnemonicPhrase} />
<div
class={type === "authenticate"
? "dusk-mnemonic__authenticate-actions-wrapper"
: "dusk-mnemonic__validate-actions-wrapper"}
>
{#if type === "authenticate" && enteredWordIndex.includes("")}
<Textbox
placeholder={`Enter word ${currentIndex + 1}`}
bind:this={textboxElement}
on:keydown={(e) =>
handleKeyDownOnAuthenticateTextbox(e, currentIndex.toString())}
maxlength={8}
type="text"
bind:value={currentInput}
/>
{#if suggestions.length}
<div class="dusk-mnemonic__suggestions-wrapper">
{#each suggestions as suggestion, index (`${suggestion}-${index}`)}
<Button
variant="tertiary"
text={suggestion}
data-value={suggestion}
on:click={handleWordButtonClick}
/>
{/each}
</div>
{/if}
{:else}
{#each mnemonicPhrase as word, index (`${word}-${index}`)}
<Button
variant="tertiary"
text={word}
data-value={word}
disabled={enteredWordIndex.includes(index.toString())}
on:click={(e) => handleWordButtonClick(e, index.toString())}
{#if !isTriggeredByLogin}
<div
class={type === "authenticate"
? "dusk-mnemonic__authenticate-actions-wrapper"
: "dusk-mnemonic__validate-actions-wrapper"}
>
{#if type === "authenticate" && enteredWordIndex.includes("")}
<Textbox
placeholder={`Enter word ${currentIndex + 1}`}
bind:this={textboxElement}
on:keydown={(e) =>
handleKeyDownOnAuthenticateTextbox(e, currentIndex.toString())}
maxlength={8}
type="text"
bind:value={currentInput}
/>
{/each}
{/if}
</div>
{#if suggestions.length}
<div class="dusk-mnemonic__suggestions-wrapper">
{#each suggestions as suggestion, index (`${suggestion}-${index}`)}
<Button
variant="tertiary"
text={suggestion}
data-value={suggestion}
on:click={handleWordButtonClick}
/>
{/each}
</div>
{/if}
{:else}
{#each mnemonicPhrase as word, index (`${word}-${index}`)}
<Button
variant="tertiary"
text={word}
data-value={word}
disabled={enteredWordIndex.includes(index.toString())}
on:click={(e) => handleWordButtonClick(e, index.toString())}
/>
{/each}
{/if}
</div>
{/if}
</div>
1 change: 1 addition & 0 deletions web-wallet/src/lib/stores/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as gasStore } from "./gasStore";
export { default as operationsStore } from "./operationsStore";
export { default as mnemonicPhraseResetStore } from "./mnemonicPhraseResetStore";
export { default as settingsStore } from "./settingsStore";
export { default as walletStore } from "./walletStore";
6 changes: 6 additions & 0 deletions web-wallet/src/lib/stores/mnemonicPhraseResetStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { writable } from "svelte/store";

/** @type {import('svelte/store').Writable<string[]>} */
const mnemonicPhraseResetStore = writable([]);

export default mnemonicPhraseResetStore;
9 changes: 8 additions & 1 deletion web-wallet/src/routes/(welcome)/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import { validateMnemonic } from "bip39";
import { goto } from "$lib/navigation";
import { settingsStore, walletStore } from "$lib/stores";
import {
mnemonicPhraseResetStore,
settingsStore,
walletStore,
} from "$lib/stores";
import { decryptMnemonic, getSeedFromMnemonic } from "$lib/wallet";
import loginInfoStorage from "$lib/services/loginInfoStorage";
import { getWallet } from "$lib/services/wallet";
Expand All @@ -31,6 +35,8 @@
const currentUserAddress = $settingsStore.userId;
if (defaultAddress !== currentUserAddress) {
const enteredMnemonicPhrase = secretText.split(" ");
mnemonicPhraseResetStore.set(enteredMnemonicPhrase);
await goto("/setup/restore");
throw new Error(existingWalletDetectedErrorMessage);
}
Expand Down Expand Up @@ -114,6 +120,7 @@
icon={{ path: mdiWalletOutline }}
/>
<AppAnchorButton
on:click={() => mnemonicPhraseResetStore.set([])}
href="/setup/restore"
variant="tertiary"
text="Restore"
Expand Down
4 changes: 2 additions & 2 deletions web-wallet/src/routes/(welcome)/setup/restore/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import MnemonicAuthenticate from "./MnemonicAuthenticate.svelte";
import { Wizard, WizardStep } from "$lib/dusk/components";
import { ExistingWalletNotice } from "$lib/components";
import { settingsStore } from "$lib/stores";
import { mnemonicPhraseResetStore, settingsStore } from "$lib/stores";
import {
initializeWallet,
refreshLocalStoragePasswordInfo,
Expand All @@ -34,7 +34,7 @@
let isValidMnemonic = false;
/** @type {string[]} */
let mnemonicPhrase = [];
let mnemonicPhrase = $mnemonicPhraseResetStore;
const { userId } = $settingsStore;
Expand Down

0 comments on commit de40a2c

Please sign in to comment.