2022-08-14 18:13:46 +00:00
|
|
|
<script lang="ts">
|
2024-06-18 06:23:06 +00:00
|
|
|
import { writable } from "svelte/store";
|
|
|
|
|
import { onMount, onDestroy, createEventDispatcher } from "svelte";
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
const dispatch = createEventDispatcher<{ change: string }>();
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
let apiPassword = "";
|
|
|
|
|
let state: "edit" | "view" = "edit";
|
|
|
|
|
let unsubscribe: () => void;
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
function onSubmit() {
|
|
|
|
|
state = "view";
|
|
|
|
|
if (localStorage) {
|
|
|
|
|
localStorage.setItem("apiPassword", apiPassword);
|
|
|
|
|
}
|
|
|
|
|
dispatch("change", apiPassword);
|
|
|
|
|
}
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
function onEdit() {
|
|
|
|
|
state = "edit";
|
|
|
|
|
}
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
onMount(() => {
|
|
|
|
|
if (localStorage !== undefined) {
|
|
|
|
|
apiPassword = localStorage.getItem("apiPassword") || "";
|
|
|
|
|
}
|
2022-08-14 18:13:46 +00:00
|
|
|
|
2024-06-18 06:23:06 +00:00
|
|
|
if (apiPassword.length > 0) {
|
|
|
|
|
dispatch("change", apiPassword);
|
|
|
|
|
state = "view";
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-14 18:13:46 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<section>
|
2024-06-18 06:23:06 +00:00
|
|
|
{#if apiPassword.length === 0}
|
|
|
|
|
<p>
|
|
|
|
|
To save things to the ledger you need to enter the password. Right now you
|
|
|
|
|
haven't set one.
|
|
|
|
|
</p>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if state === "view"}
|
|
|
|
|
<button on:click={onEdit}>Edit Password</button>
|
|
|
|
|
{:else}
|
|
|
|
|
<form on:submit|preventDefault={onSubmit}>
|
|
|
|
|
<input type="text" bind:value={apiPassword} />
|
|
|
|
|
<input type="submit" value="Set Password" />
|
|
|
|
|
</form>
|
|
|
|
|
{/if}
|
2022-08-14 18:13:46 +00:00
|
|
|
</section>
|