Skip to content

Commit

Permalink
feat(ceremony): tag localstorage with id
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Oct 4, 2024
1 parent 5525196 commit 2c2b213
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
9 changes: 4 additions & 5 deletions ceremony/src/lib/components/Terminal/Missed.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ async function trigger(value: "retry" | "help") {
await sleep(1000)
terminal.updateHistory({ text: "Clearing old user data..." })
localStorage.removeItem("ceremony:show-boot-sequence")
localStorage.removeItem("downloaded-secret")
localStorage.removeItem(`${contributor.userId}:downloaded-secret`)
const bootSequenceCleared = !localStorage.getItem("ceremony:show-boot-sequence")
const secretCleared = !localStorage.getItem("downloaded-secret")
const secretCleared = !localStorage.getItem(`${contributor.userId}:downloaded-secret`)
if (bootSequenceCleared && secretCleared) {
if (secretCleared) {
await sleep(1000)
terminal.updateHistory({ text: "Successfully cleared user data." })
await sleep(1000)
Expand All @@ -76,6 +74,7 @@ async function trigger(value: "retry" | "help") {
if (rejoined) {
terminal.updateHistory({ text: "Successfully added user to queue." })
await sleep(1000)
localStorage.removeItem("ceremony:show-boot-sequence")
terminal.updateHistory({ text: "Redirecting..." })
await sleep(1000)
window.location.href = "/"
Expand Down
10 changes: 5 additions & 5 deletions ceremony/src/lib/components/Terminal/Secret.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let generating = $state(false)
onMount(() => {
terminal.setStep(4)
axiom.ingest("monitor", [{ user: user.session?.user.id, type: "mount_secret" }])
axiom.ingest("monitor", [{ user: contributor.userId, type: "mount_secret" }])
})
function handleDownload() {
Expand All @@ -22,16 +22,16 @@ function handleDownload() {
}
function stored() {
localStorage.setItem("downloaded-secret", "true")
axiom.ingest("monitor", [{ user: user.session?.user.id, type: "stored_secret" }])
contributor.downloadedSecret = true
localStorage.setItem(`${contributor.userId}:downloaded-secret`, "true")
axiom.ingest("monitor", [{ user: contributor.userId, type: "stored_secret" }])
contributor.storedSecret = true
}
async function generate() {
if (contributor.state !== "noClient") {
generating = true
terminal.updateHistory({ text: "Generating secret..." })
axiom.ingest("monitor", [{ user: user.session?.user.id, type: "generated_secret" }])
axiom.ingest("monitor", [{ user: contributor.userId, type: "generated_secret" }])
await sleep(3000)
generateSecret(user.session?.user.email)
terminal.updateHistory({ text: "Initialize saving..." })
Expand Down
9 changes: 7 additions & 2 deletions ceremony/src/lib/state/contributor.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Contributor {
clientState = $state<ClientState>(undefined)
contributionState = $state<ContributionState>(undefined)
userWallet = $state<string | null>()
downloadedSecret = $state<boolean>(localStorage.getItem("downloaded-secret") === "true")
storedSecret = $state<boolean>(false)

queueState = $state<QueueState>({
position: null,
Expand Down Expand Up @@ -112,13 +112,18 @@ export class Contributor {
if (this.userId === undefined && userId) {
this.userId = userId
this.loggedIn = true
this.checkStoredSecret(userId)
this.checkUserWallet(userId)
this.checkCurrentUserState(userId)
this.startPolling()
}
}

async checkCurrentUserState(userId: string | undefined): Promise<AllowanceState> {
checkStoredSecret(userId: string) {
this.storedSecret = localStorage.getItem(`${userId}:downloaded-secret`) === "true"
}

async checkCurrentUserState(userId: string): Promise<AllowanceState> {
this.currentUserState = await getCurrentUserState(userId)
return this.currentUserState
}
Expand Down
2 changes: 1 addition & 1 deletion ceremony/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $effect(() => {
if (
contributor.contributionState === "contribute" &&
contributor.state !== "contributing" &&
contributor.downloadedSecret
contributor.storedSecret
) {
axiom.ingest("monitor", [{ user: user.session?.user.id, type: "start_contribution" }])
start()
Expand Down
2 changes: 1 addition & 1 deletion ceremony/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ onMount(() => {
{:else if contributor.clientState === "offline"}
<Install/>

{:else if !contributor.downloadedSecret && contributor.clientState === "idle"}
{:else if !contributor.storedSecret && contributor.clientState === "idle"}
<Secret/>

{:else if contributor.userWallet === null}
Expand Down

0 comments on commit 2c2b213

Please sign in to comment.