Skip to content

Commit

Permalink
feat(ceremony): save auto
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Sep 12, 2024
1 parent 59081c1 commit 080413d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
21 changes: 21 additions & 0 deletions ceremony/src/lib/stores/persisted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { writable } from "svelte/store"

export function persistedWritable<T>(key: string, data: T) {
const { subscribe, set, update } = writable(data)
const isBrowser = typeof window !== "undefined"

return {
set,
update,
subscribe,
useLocalStorage: () => {
const json = localStorage.getItem(key)
if (!json) return
if (json) set(JSON.parse(json) as T)

subscribe(current => {
localStorage.setItem(key, JSON.stringify(current))
})
}
}
}
15 changes: 14 additions & 1 deletion ceremony/src/routes/app/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
let {data: contribute, isLoading: contributeLoading, error: contributeError} = $derived($contributionQuery)
let {data: client, isLoading: clientLoading, error: clientError} = $derived($clientQuery)
//TODO SAVE IN LOCAL STORAGE AND ADD INFO TEXT ABOUT HAVING THE BROWSER OPEN
let auto = $state(false)
$effect(() => {
if(auto) {
if(contribute?.canContribute && contribute?.shouldContribute) {
if (client) {
start()
}
}
}
})
</script>


Expand Down Expand Up @@ -71,11 +84,11 @@
<Spinner class="size-4 text-red-500"/>
{:else if client}
<Text>{client.status}</Text>
<H2>You can contribute</H2>
<Button onclick={start}>Contribute</Button>
{:else}
<Text>Waiting for client...</Text>
{/if}
<Text>Auto contribute<Button onclick={() => auto = true}>{auto}</Button></Text>

{:else if contribute?.isVerifying}

Expand Down

0 comments on commit 080413d

Please sign in to comment.