Skip to content

Commit

Permalink
Fixed import-seed and manually entering seed words, also save func to…
Browse files Browse the repository at this point in the history
…do fixed
  • Loading branch information
n9lsjr committed Dec 11, 2023
1 parent 89b796c commit 1e89916
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 54 deletions.
8 changes: 1 addition & 7 deletions src/backend/electron.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,8 @@ ipcMain.handle("import-seed", async (e, seed, walletName, password, height, node
return false;
}

const saved = await saveWallet(userDataDir, walletName, password)

if (!saved) {
console.log("Failed to save wallet!");
return false;
}
await saveWallet(userDataDir, walletName, password)

//TODO fix a save wallet function
let knownWallets = await wallets.get("wallets") ?? [];
knownWallets.unshift({ wallet: walletName.toLowerCase() });
await wallets.set("wallets", knownWallets);
Expand Down
131 changes: 84 additions & 47 deletions src/routes/auth/import-wallet/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
<script>
import { fade, fly } from "svelte/transition";
import toast from "svelte-french-toast";
import { onMount } from "svelte";
import { wordlist } from '$lib/stores/wordlist.js'
import { Moon } from "svelte-loading-spinners";
import ArrowRight from "$lib/components/icons/ArrowRight.svelte";
import { goto } from "$app/navigation";
import Backward from "$lib/components/icons/Backward.svelte";
import NodeSelector from "$lib/components/NodeSelector.svelte";
import { node } from "$lib/stores/node.js";
import { fade, fly } from 'svelte/transition';
import toast from 'svelte-french-toast';
import { onMount } from 'svelte';
import { wordlist } from '$lib/stores/wordlist.js';
import { Moon } from 'svelte-loading-spinners';
import ArrowRight from '$lib/components/icons/ArrowRight.svelte';
import { goto } from '$app/navigation';
import Backward from '$lib/components/icons/Backward.svelte';
import NodeSelector from '$lib/components/NodeSelector.svelte';
import { node } from '$lib/stores/node.js';
let step = 1;
let seedWordsStr;
let seedWordsArray = Array(25).fill("");
let seedWordsArray = Array(25).fill('');
let inputs;
let loading;
let password = "";
let password = '';
let blockHeight;
let walletName = "";
let walletName = '';
onMount(() => {
inputs = document.querySelectorAll("input");
inputs = document.querySelectorAll('input');
inputs[0].focus();
});
const paste = async () => {
seedWordsArray = Array(25).fill("");
seedWordsArray = Array(25).fill('');
seedWordsStr = await navigator.clipboard.readText();
let arr = seedWordsStr.split(" ");
let arr = seedWordsStr.split(' ');
arr = arr.filter((e) => {
return e;
});
if (arr.length === 25) {
seedWordsArray = arr;
seedWordsStr = arr.join(" ");
toast.success("Pasted", {
position: "top-right",
style: "border-radius: 5px; background: var(--toast-bg-color); border: 1px solid var(--toast-b-color); color: var(--toast-text-color);"
seedWordsStr = arr.join(' ');
toast.success('Pasted', {
position: 'top-right',
style:
'border-radius: 5px; background: var(--toast-bg-color); border: 1px solid var(--toast-b-color); color: var(--toast-text-color);',
});
} else {
toast.error("Error", {
position: "top-right",
style: "border-radius: 5px; background: var(--toast-bg-color); border: 1px solid var(--toast-b-color); color: var(--toast-text-color);"
toast.error('Error', {
position: 'top-right',
style:
'border-radius: 5px; background: var(--toast-bg-color); border: 1px solid var(--toast-b-color); color: var(--toast-text-color);',
});
}
};
Expand All @@ -53,30 +54,39 @@
$node.selectedNode = selectedNode;
if (await window.api.checkNode(selectedNode)) {
//If you manually enter the words
if (seedWordsStr === undefined) {
seedWordsStr = seedWordsArray.join(' ');
}
console.log(seedWordsStr, walletName, password, parseInt(blockHeight), selectedNode);
const walletImport = await window.api.importSeed(seedWordsStr, walletName, password, parseInt(blockHeight), selectedNode);
if (walletImport) await goto("/");
seedWordsStr = "";
walletName = "";
blockHeight = "";
const walletImport = await window.api.importSeed(
seedWordsStr,
walletName,
password,
parseInt(blockHeight),
selectedNode,
);
if (walletImport) await goto('/');
seedWordsStr = '';
walletName = '';
blockHeight = '';
}
};
let meta;
let ctrl;
const keyDown = (e) => {
if (e.key === "Meta") meta = true;
if (e.key === "v" && meta) paste();
if (e.key === 'Meta') meta = true;
if (e.key === 'v' && meta) paste();
};
const keyUp = () => {
ctrl = false;
meta = false;
};
</script>

<svelte:window on:keydown="{keyDown}" on:keyup={keyUp} />
<svelte:window on:keydown={keyDown} on:keyup={keyUp} />

{#if step === 1}
<section in:fade>
Expand All @@ -85,13 +95,16 @@
{#each seedWordsArray ?? [] as word, i}
<div style="display: flex; flex-direction: column; align-items: center">
<p style="margin-bottom: 5px">{i + 1}</p>
<input id={i} class="card"
class:correct={wordlist.includes(seedWordsArray[i])}
bind:value={seedWordsArray[i]}
on:input={e => {
if(wordlist.includes(seedWordsArray[i])) inputs[i + 1].focus()
if(!e.target.value) inputs[i -1].focus()
}} />
<input
id={i}
class="card"
class:correct={wordlist.includes(seedWordsArray[i])}
bind:value={seedWordsArray[i]}
on:input={(e) => {
if (wordlist.includes(seedWordsArray[i])) inputs[i + 1].focus();
if (!e.target.value) inputs[i - 1].focus();
}}
/>
</div>
{/each}
<button class="card" on:click={() => goto('/auth/create-wallet')}>Back</button>
Expand All @@ -103,7 +116,7 @@
<section>
<h1>Name wallet</h1>
<div class="field">
<input in:fly={{y: 20}} placeholder="Name.." type="text" bind:value={walletName} />
<input in:fly={{ y: 20 }} placeholder="Name.." type="text" bind:value={walletName} />
<button on:click on:click={() => step++}>
{#if loading}
<Moon color="#ffffff" size="20" unit="px" />
Expand All @@ -112,15 +125,21 @@
{/if}
</button>
</div>
<div style="margin-top: 2rem" in:fade on:click={() => {if(step > 1) step--}}>
<div
style="margin-top: 2rem"
in:fade
on:click={() => {
if (step > 1) step--;
}}
>
<Backward />
</div>
</section>
{:else if step === 3}
<section>
<h1>Create password</h1>
<div class="field">
<input in:fly={{y: 20}} placeholder="Password.." type="password" bind:value={password} />
<input in:fly={{ y: 20 }} placeholder="Password.." type="password" bind:value={password} />
<button on:click on:click={() => step++}>
{#if loading}
<Moon color="#ffffff" size="20" unit="px" />
Expand All @@ -129,15 +148,21 @@
{/if}
</button>
</div>
<div style="margin-top: 2rem" in:fade on:click={() => {if(step > 1) step--}}>
<div
style="margin-top: 2rem"
in:fade
on:click={() => {
if (step > 1) step--;
}}
>
<Backward />
</div>
</section>
{:else if step === 4}
<section>
<h1>Scan from block height</h1>
<div class="field">
<input in:fly={{y: 20}} placeholder="Block height" type="text" bind:value={blockHeight} />
<input in:fly={{ y: 20 }} placeholder="Block height" type="text" bind:value={blockHeight} />
<button on:click={() => step++}>
{#if loading}
<Moon color="#ffffff" size="20" unit="px" />
Expand All @@ -146,14 +171,26 @@
{/if}
</button>
</div>
<div style="margin-top: 2rem" in:fade on:click={() => {if(step > 1) step--}}>
<div
style="margin-top: 2rem"
in:fade
on:click={() => {
if (step > 1) step--;
}}
>
<Backward />
</div>
</section>
{:else if step === 5}
<section>
<NodeSelector on:connect={(e) => importSeed(e)} />
<div style="margin-top: 2rem" in:fade on:click={() => {if(step > 1) step--}}>
<div
style="margin-top: 2rem"
in:fade
on:click={() => {
if (step > 1) step--;
}}
>
<Backward />
</div>
</section>
Expand Down

0 comments on commit 1e89916

Please sign in to comment.