From 523034c000d63db52c19eb325762ed088acd34a9 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 25 Sep 2024 02:35:37 +0200 Subject: [PATCH 01/40] feat(ceremony): terminal progress --- ceremony/.gitattributes | 14 ++ ceremony/src/lib/components/Ceremony.svelte | 6 +- ceremony/src/lib/components/Download.svelte | 3 - .../components/TerminalApp/Activity.svelte | 45 ++++++ .../TerminalApp/Authenticate.svelte | 69 +++++++++ .../components/TerminalApp/CommandBar.svelte | 4 + .../TerminalApp/Contributors.svelte | 71 +++++++++ .../lib/components/TerminalApp/Join.svelte | 55 +++++++ .../lib/components/TerminalApp/Print.svelte | 5 + .../TerminalApp/TerminalWindow.svelte | 107 +++++++++++++ .../components/TerminalApp/Waitlist.svelte | 23 +++ .../lib/components/address/AddressForm.svelte | 2 +- ceremony/src/lib/layout/Navbar/index.svelte | 2 +- ceremony/src/lib/state/client.svelte.ts | 59 +++++++ .../src/lib/state/contributions.svelte.ts | 25 +++ ceremony/src/lib/state/contributor.svelte.ts | 146 ++++++++++++++++++ ceremony/src/lib/state/index.svelte.ts | 37 +++++ ceremony/src/lib/state/live.svelte.ts | 50 ++++++ ceremony/src/lib/state/session.svelte.ts | 42 +++++ ceremony/src/lib/state/terminal.svelte.ts | 42 +++++ ceremony/src/lib/stores/auth.svelte.ts | 0 ceremony/src/lib/stores/user.svelte.ts | 7 - ceremony/src/lib/supabase/index.ts | 2 +- ceremony/src/lib/utils/Keydown.svelte | 34 ++++ ceremony/src/lib/utils/auth.ts | 24 --- ceremony/src/routes/+layout.svelte | 49 +----- ceremony/src/routes/+layout.ts | 48 +++--- ceremony/src/routes/+page.svelte | 79 ++-------- ceremony/src/routes/0____0/+page.svelte | 23 --- .../[hash]/+page.svelte | 73 +++++---- .../{contributions => 0____0}/[hash]/+page.ts | 0 .../src/routes/contributions/+page.svelte | 59 ------- ceremony/src/routes/terminal/+page.svelte | 31 ++++ 33 files changed, 943 insertions(+), 293 deletions(-) create mode 100644 ceremony/.gitattributes create mode 100644 ceremony/src/lib/components/TerminalApp/Activity.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Authenticate.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/CommandBar.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Contributors.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Join.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Print.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Waitlist.svelte create mode 100644 ceremony/src/lib/state/client.svelte.ts create mode 100644 ceremony/src/lib/state/contributions.svelte.ts create mode 100644 ceremony/src/lib/state/contributor.svelte.ts create mode 100644 ceremony/src/lib/state/index.svelte.ts create mode 100644 ceremony/src/lib/state/live.svelte.ts create mode 100644 ceremony/src/lib/state/session.svelte.ts create mode 100644 ceremony/src/lib/state/terminal.svelte.ts create mode 100644 ceremony/src/lib/stores/auth.svelte.ts delete mode 100644 ceremony/src/lib/stores/user.svelte.ts create mode 100644 ceremony/src/lib/utils/Keydown.svelte delete mode 100644 ceremony/src/lib/utils/auth.ts delete mode 100644 ceremony/src/routes/0____0/+page.svelte rename ceremony/src/routes/{contributions => 0____0}/[hash]/+page.svelte (53%) rename ceremony/src/routes/{contributions => 0____0}/[hash]/+page.ts (100%) delete mode 100644 ceremony/src/routes/contributions/+page.svelte create mode 100644 ceremony/src/routes/terminal/+page.svelte diff --git a/ceremony/.gitattributes b/ceremony/.gitattributes new file mode 100644 index 0000000000..00c3449ec4 --- /dev/null +++ b/ceremony/.gitattributes @@ -0,0 +1,14 @@ +.webp filter=lfs diff=lfs merge=lfs -text +.avif filter=lfs diff=lfs merge=lfs -text +.gif filter=lfs diff=lfs merge=lfs -text +*.otf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.woff2 filter=lfs diff=lfs merge=lfs -text +*.woff filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.psd filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text +*.jpeg filter=lfs diff=lfs merge=lfs -text +*.splinecode filter=lfs diff=lfs merge=lfs -text diff --git a/ceremony/src/lib/components/Ceremony.svelte b/ceremony/src/lib/components/Ceremony.svelte index 82223efa56..9e67731cb2 100644 --- a/ceremony/src/lib/components/Ceremony.svelte +++ b/ceremony/src/lib/components/Ceremony.svelte @@ -1,5 +1,4 @@ + +{#if activity.data} + {#each activity.data as item, i (item)} + {@const type = item.message.type} + {@const user = item.message.user} + + {formatTimestamp(item.created_at)} - + {#if type === "join_waitlist"} + {user} joined the waitlist + {:else if type === "redeem"} + {user} have redeemed a code + {:else if type === "join_queue"} + {user} joined the queue + {:else if type === "contribution_started"} + {user} have started their contribution + {:else if type === "contribution_submitted"} + {user} has submitted their contribution + {:else if type === "contribution_verified"} + {user} contribution just verified + {/if} + + + {/each} +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Authenticate.svelte b/ceremony/src/lib/components/TerminalApp/Authenticate.svelte new file mode 100644 index 0000000000..148891c314 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Authenticate.svelte @@ -0,0 +1,69 @@ + + +{#if !redirecting} + + {#each providers as provider, index} + + {/each} + +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/CommandBar.svelte b/ceremony/src/lib/components/TerminalApp/CommandBar.svelte new file mode 100644 index 0000000000..67ae89f729 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/CommandBar.svelte @@ -0,0 +1,4 @@ + + diff --git a/ceremony/src/lib/components/TerminalApp/Contributors.svelte b/ceremony/src/lib/components/TerminalApp/Contributors.svelte new file mode 100644 index 0000000000..12b7d456e5 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Contributors.svelte @@ -0,0 +1,71 @@ + + +{#if contributions.data} + ceremony contributors + {#each contributions.data as contributor, index} + + {/each} +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Join.svelte b/ceremony/src/lib/components/TerminalApp/Join.svelte new file mode 100644 index 0000000000..ad0e7bc269 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Join.svelte @@ -0,0 +1,55 @@ + + +

Join the ceremony

+Have an invite? Enter your code below. +
+ + +Or +

Don't have an invite?

+You can join the waitlist now to get priority access when the ceremony opens. + diff --git a/ceremony/src/lib/components/TerminalApp/Print.svelte b/ceremony/src/lib/components/TerminalApp/Print.svelte new file mode 100644 index 0000000000..bcb5fa1305 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Print.svelte @@ -0,0 +1,5 @@ + + +

{@render children()}

diff --git a/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte b/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte new file mode 100644 index 0000000000..d15135da68 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte @@ -0,0 +1,107 @@ + + +
+
+
+
+ + + + {#if terminal.hash !== undefined} + + {/if} +
+ +
+
+ + {#if terminal.tab === 1 } +
+ {#each terminal.history as text} + {text} + {/each} +
+ {@render children()} + + {:else if terminal.tab === 2} + + + {:else if terminal.tab === 3} + + + {:else if terminal.tab === 4} + {@render children()} + + {/if} +
+
+
diff --git a/ceremony/src/lib/components/TerminalApp/Waitlist.svelte b/ceremony/src/lib/components/TerminalApp/Waitlist.svelte new file mode 100644 index 0000000000..378cf582d1 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Waitlist.svelte @@ -0,0 +1,23 @@ + + +

You're on the waitlist

+When the ceremony opens to the public, you will be {contributor.waitListPosition}{getNumberSuffix(contributor.waitListPosition)} in the public queue. +You will receive an email 12-18 hours before the public phase begins. +

Received an invite?

+You can skip the waitlist and join now. +
+ + \ No newline at end of file diff --git a/ceremony/src/lib/components/address/AddressForm.svelte b/ceremony/src/lib/components/address/AddressForm.svelte index cc744564a8..db465a344c 100644 --- a/ceremony/src/lib/components/address/AddressForm.svelte +++ b/ceremony/src/lib/components/address/AddressForm.svelte @@ -6,8 +6,8 @@ import type { ValidState } from "./index.ts" import { isValidBech32Address } from "./validator.ts" import type { HTMLInputAttributes } from "svelte/elements" import { insertWalletData } from "$lib/supabase" -import { user } from "$lib/stores/user.svelte.ts" import type { ContributorState } from "$lib/stores/state.svelte.ts" +import { user } from "$lib/state/session.svelte.ts" interface Props extends HTMLInputAttributes { class?: string diff --git a/ceremony/src/lib/layout/Navbar/index.svelte b/ceremony/src/lib/layout/Navbar/index.svelte index bc1046dcf0..452e9bd4d6 100644 --- a/ceremony/src/lib/layout/Navbar/index.svelte +++ b/ceremony/src/lib/layout/Navbar/index.svelte @@ -1,10 +1,10 @@ \ No newline at end of file diff --git a/ceremony/src/lib/utils/auth.ts b/ceremony/src/lib/utils/auth.ts deleted file mode 100644 index a9646cb5a9..0000000000 --- a/ceremony/src/lib/utils/auth.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { supabase } from "$lib/supabase/client.ts" -import { err, ok, type Result } from "neverthrow" -import { user } from "$lib/stores/user.svelte.ts" - -export type SessionError = { - message: string -} - -export async function checkAuth(): Promise> { - const { - data: { session }, - error - } = await supabase.auth.getSession() - - if (error || !session) { - return err({ message: "User not authenticated" }) - } - - if (session) { - user.session = session - } - - return ok(null) -} diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index 5ffabf2c51..c4aa4864a6 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -1,48 +1,13 @@ + + -
{@render children()} diff --git a/ceremony/src/routes/+layout.ts b/ceremony/src/routes/+layout.ts index 2eb647d441..98eaf2c1a6 100644 --- a/ceremony/src/routes/+layout.ts +++ b/ceremony/src/routes/+layout.ts @@ -1,29 +1,27 @@ -import { checkAuth, type SessionError } from "$lib/utils/auth.ts" -import type { LayoutLoad } from "./$types.ts" -import { redirect } from "@sveltejs/kit" - export const ssr = false export const prerender = true export const trailingSlash = "ignore" -export const load: LayoutLoad = async ({ url }) => { - const pathname = url.pathname - - if (pathname) { - const segments = pathname.split("/").filter(Boolean) - if (segments[0] === "0____0") { - const authCheck = await checkAuth() - return authCheck.match( - () => { - return {} - }, - (error: SessionError) => { - console.error(error.message) - throw redirect(302, "/") - } - ) - } - } - - return {} -} +// export const load: LayoutLoad = async ({ url }) => { +// const pathname = url.pathname +// +// console.log('load') +// +// if (pathname) { +// const segments = pathname.split("/").filter(Boolean) +// if (segments[0] === "terminal") { +// const authCheck = await checkAuth() +// return authCheck.match( +// () => { +// return {} +// }, +// (error: SessionError) => { +// console.error(error.message) +// throw redirect(302, "/") +// } +// ) +// } +// } +// +// return {} +// } diff --git a/ceremony/src/routes/+page.svelte b/ceremony/src/routes/+page.svelte index 5131e0ae0e..ab4f929459 100644 --- a/ceremony/src/routes/+page.svelte +++ b/ceremony/src/routes/+page.svelte @@ -1,68 +1,19 @@ -{#snippet Dive(provider: AuthProviders)} - -{/snippet} - - -
-
- -
-

Welcome to the Union Ceremony

-
- Participation is currently invite only. - If you don’t have an invitation, please join the waitlist. -
-
-
-
- {#each providers as provider} - {@render Dive(provider)} - {/each} -
-
-
-
- -
-
- I acknowledge that my name, email address, and optional wallet address will be part of the publicly viewable MPC ceremony data. I agree that this data will never be deleted as it is encoded in my contribution. -
-
-
-
\ No newline at end of file + + {terminal.updateHistory("welcome to union ceremony")} + {#if user.session} + {terminal.updateHistory(`authenticated user: ${user.session.user.email}`)} + {:else if user.session === null} + + {:else} + Loading... + {/if} + \ No newline at end of file diff --git a/ceremony/src/routes/0____0/+page.svelte b/ceremony/src/routes/0____0/+page.svelte deleted file mode 100644 index a7236a634f..0000000000 --- a/ceremony/src/routes/0____0/+page.svelte +++ /dev/null @@ -1,23 +0,0 @@ - - -
- {#if contributor.loggedIn} - {#if !contributor.currentUserState} - - {:else if contributor.currentUserState === "hasRedeemed" || contributor.currentUserState === "inQueue"} - - {:else if contributor.currentUserState === "inWaitlist"} - - {:else if contributor.currentUserState === "join"} - - {/if} - {/if} -
\ No newline at end of file diff --git a/ceremony/src/routes/contributions/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte similarity index 53% rename from ceremony/src/routes/contributions/[hash]/+page.svelte rename to ceremony/src/routes/0____0/[hash]/+page.svelte index 6a31a4286e..86e2745fec 100644 --- a/ceremony/src/routes/contributions/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -1,13 +1,21 @@ - -{#if contributions} -
-
-
-
- - Next contribution... -
- {@render ContributionConnector()} - {#each contributions as contribution, index } - {@render ContributionBox(contribution)} - {@render ContributionConnector()} - {/each} - {@render ContributionBox({ user_name: "Genesis", payload_id: "00000000-0000-0000-0000-000000000000"})} -
-
- -{:else} - -{/if} - - -{#snippet ContributionBox(contribution: unknown)} - -
{getFirstLetter(contribution.user_name)}
- {contribution.payload_id} -
-{/snippet} - -{#snippet ContributionConnector()} -
-{/snippet} diff --git a/ceremony/src/routes/terminal/+page.svelte b/ceremony/src/routes/terminal/+page.svelte new file mode 100644 index 0000000000..7ebb832b44 --- /dev/null +++ b/ceremony/src/routes/terminal/+page.svelte @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + Hello + \ No newline at end of file From 2737101135206c373ef57581f296b6592159d5b1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 25 Sep 2024 18:25:39 +0200 Subject: [PATCH 02/40] feat(ceremony): save terminal progress --- ceremony/src/lib/components/Ceremony.svelte | 88 ------ ceremony/src/lib/components/Code.svelte | 132 ++++----- .../src/lib/components/Contributions.svelte | 6 +- .../src/lib/components/Counter/index.svelte | 68 ----- .../components/Counter/numbers/eight.svelte | 26 -- .../components/Counter/numbers/five.svelte | 26 -- .../components/Counter/numbers/four.svelte | 27 -- .../components/Counter/numbers/nine.svelte | 27 -- .../lib/components/Counter/numbers/one.svelte | 26 -- .../components/Counter/numbers/seven.svelte | 26 -- .../lib/components/Counter/numbers/six.svelte | 26 -- .../components/Counter/numbers/three.svelte | 26 -- .../lib/components/Counter/numbers/two.svelte | 26 -- .../components/Counter/numbers/zero.svelte | 26 -- ceremony/src/lib/components/Download.svelte | 21 +- ceremony/src/lib/components/Install.svelte | 42 ++- ceremony/src/lib/components/Join.svelte | 61 ---- ceremony/src/lib/components/Queue.svelte | 22 +- ceremony/src/lib/components/Reward.svelte | 66 ++--- ceremony/src/lib/components/SwimLoad.svelte | 8 +- .../components/TerminalApp/Activity.svelte | 1 + .../TerminalApp/Authenticate.svelte | 84 +++--- .../components/TerminalApp/Ceremony.svelte | 67 +++++ .../components/TerminalApp/CommandBar.svelte | 4 - .../TerminalApp/Contributors.svelte | 65 ++--- .../lib/components/TerminalApp/Join.svelte | 139 +++++---- .../lib/components/TerminalApp/Print.svelte | 2 +- .../TerminalApp/TerminalWindow.svelte | 118 ++++---- .../components/TerminalApp/Waitlist.svelte | 27 +- ceremony/src/lib/components/Thanks.svelte | 19 +- ceremony/src/lib/components/Waitlist.svelte | 14 +- ceremony/src/lib/components/Warning.svelte | 11 +- .../lib/components/address/AddressForm.svelte | 174 ++++++------ ceremony/src/lib/components/address/index.ts | 2 +- .../src/lib/components/typography/H1.svelte | 7 - .../src/lib/components/typography/H2.svelte | 7 - .../src/lib/components/typography/H3.svelte | 6 - .../src/lib/components/typography/H4.svelte | 7 - .../src/lib/components/typography/H5.svelte | 7 - .../src/lib/components/typography/H6.svelte | 7 - .../src/lib/components/typography/Link.svelte | 7 - .../src/lib/components/typography/Text.svelte | 7 - ceremony/src/lib/state/client.svelte.ts | 6 +- ceremony/src/lib/state/contributor.svelte.ts | 264 ++++++++++++------ ceremony/src/lib/state/session.svelte.ts | 66 +++-- ceremony/src/lib/state/terminal.svelte.ts | 56 +++- ceremony/src/lib/supabase/index.ts | 24 +- ceremony/src/lib/supabase/queries.ts | 2 +- ceremony/src/lib/utils/Keydown.svelte | 34 --- ceremony/src/lib/utils/utils.ts | 5 + ceremony/src/routes/+layout.svelte | 15 +- ceremony/src/routes/+layout.ts | 48 ++-- ceremony/src/routes/+page.svelte | 41 ++- .../src/routes/0____0/[hash]/+page.svelte | 101 ++++--- ceremony/src/routes/terminal/+page.svelte | 31 -- 55 files changed, 947 insertions(+), 1304 deletions(-) delete mode 100644 ceremony/src/lib/components/Ceremony.svelte delete mode 100644 ceremony/src/lib/components/Counter/index.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/eight.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/five.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/four.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/nine.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/one.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/seven.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/six.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/three.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/two.svelte delete mode 100644 ceremony/src/lib/components/Counter/numbers/zero.svelte delete mode 100644 ceremony/src/lib/components/Join.svelte create mode 100644 ceremony/src/lib/components/TerminalApp/Ceremony.svelte delete mode 100644 ceremony/src/lib/components/TerminalApp/CommandBar.svelte delete mode 100644 ceremony/src/lib/components/typography/H1.svelte delete mode 100644 ceremony/src/lib/components/typography/H2.svelte delete mode 100644 ceremony/src/lib/components/typography/H3.svelte delete mode 100644 ceremony/src/lib/components/typography/H4.svelte delete mode 100644 ceremony/src/lib/components/typography/H5.svelte delete mode 100644 ceremony/src/lib/components/typography/H6.svelte delete mode 100644 ceremony/src/lib/components/typography/Link.svelte delete mode 100644 ceremony/src/lib/components/typography/Text.svelte delete mode 100644 ceremony/src/lib/utils/Keydown.svelte delete mode 100644 ceremony/src/routes/terminal/+page.svelte diff --git a/ceremony/src/lib/components/Ceremony.svelte b/ceremony/src/lib/components/Ceremony.svelte deleted file mode 100644 index 9e67731cb2..0000000000 --- a/ceremony/src/lib/components/Ceremony.svelte +++ /dev/null @@ -1,88 +0,0 @@ - - -
- - {#if !contributor.userWallet} - - - {:else if contributor.state === 'contributed'} - - - {:else if contributor.state === 'verifying'} -

- -

-

Verifying your contribution...

- - - {:else if contributor.clientState === 'offline'} - - - {:else if !contributor.downloadedSecret} - - - {:else if contributor.state === "inQueue"} - - - {:else if contributor.state === 'contribute'} -

- -

-

Starting contribution...

- - - {:else if contributor.state === 'contributing'} -

- -

-

Contributing...

- - - {:else} -

Not able to contribute at this time

- - {/if} - -
- -
\ No newline at end of file diff --git a/ceremony/src/lib/components/Code.svelte b/ceremony/src/lib/components/Code.svelte index b0421785d5..de3b41a5aa 100644 --- a/ceremony/src/lib/components/Code.svelte +++ b/ceremony/src/lib/components/Code.svelte @@ -1,93 +1,71 @@ -
- {#each words as word, index} +{#if showInput} +
+
+ Enter code: +
handleKeyDown(e, index)} - class="bg-transparent border-b border-white w-20 text-center text-union-accent-500 outline-none focus:ring-0 focus:border-union-accent-500" + autofocus + bind:this={inputElement} + bind:value={inputCode} + onkeydown={handleKeyDown} + class="inline-flex bg-transparent w-full text-union-accent-500 outline-none focus:ring-0 focus:border-none" style="--tw-ring-color: transparent;" /> - {#if index !== words.length - 1} -

-

- {/if} - {/each} -
- - - +
+{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Contributions.svelte b/ceremony/src/lib/components/Contributions.svelte index bc23543ad1..12eb0b4d0f 100644 --- a/ceremony/src/lib/components/Contributions.svelte +++ b/ceremony/src/lib/components/Contributions.svelte @@ -1,7 +1,7 @@ - -
-

Ceremony set to begin

-

2024-09-20 | 10:00 AM (CEST)

-
- {@render pair(hours, 'h')} - {@render pair(minutes, 'm')} - {@render pair(seconds, 's')} -
-
-s - -{#snippet pair(time: string, timeType: string)} -
- {#each time.split('') as digit, index (index + time)} -
-
{digit}
-
- {/each} -
{timeType}
-
-{/snippet} \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/eight.svelte b/ceremony/src/lib/components/Counter/numbers/eight.svelte deleted file mode 100644 index ed3001c792..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/eight.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/five.svelte b/ceremony/src/lib/components/Counter/numbers/five.svelte deleted file mode 100644 index a2f871c3b0..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/five.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/four.svelte b/ceremony/src/lib/components/Counter/numbers/four.svelte deleted file mode 100644 index 7b37a2a133..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/four.svelte +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/nine.svelte b/ceremony/src/lib/components/Counter/numbers/nine.svelte deleted file mode 100644 index 220bedb8c3..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/nine.svelte +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/one.svelte b/ceremony/src/lib/components/Counter/numbers/one.svelte deleted file mode 100644 index c6d3c1a452..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/one.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/seven.svelte b/ceremony/src/lib/components/Counter/numbers/seven.svelte deleted file mode 100644 index a752500cde..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/seven.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/six.svelte b/ceremony/src/lib/components/Counter/numbers/six.svelte deleted file mode 100644 index 2531052ddf..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/six.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/three.svelte b/ceremony/src/lib/components/Counter/numbers/three.svelte deleted file mode 100644 index bc086b99b6..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/three.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/two.svelte b/ceremony/src/lib/components/Counter/numbers/two.svelte deleted file mode 100644 index ce802d0871..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/two.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Counter/numbers/zero.svelte b/ceremony/src/lib/components/Counter/numbers/zero.svelte deleted file mode 100644 index c07ecef452..0000000000 --- a/ceremony/src/lib/components/Counter/numbers/zero.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Download.svelte b/ceremony/src/lib/components/Download.svelte index 7cc5a20c21..29568c9e6c 100644 --- a/ceremony/src/lib/components/Download.svelte +++ b/ceremony/src/lib/components/Download.svelte @@ -1,11 +1,10 @@ {#if !download} -

Generate your PGP secret

- + Generate your PGP secret + The MPC client automatically uses this secret to sign your contribution.
Your secret is locally generated through the MPC client. -
+ {:else} -

Store your PGP secret

- + Store your PGP secret + Please store your secret somewhere safe, such as in your password manager.
There's no need to open the file and remember to never share a secret.
This secret key is the only way to prove that you have contributed. -
-
+ +
diff --git a/ceremony/src/lib/components/Install.svelte b/ceremony/src/lib/components/Install.svelte index 74a0c8a313..0ef8705e53 100644 --- a/ceremony/src/lib/components/Install.svelte +++ b/ceremony/src/lib/components/Install.svelte @@ -1,13 +1,11 @@ - -
- -

Join the ceremony

- Have an invite? Enter your code below. -
- - - Or -

Don't have an invite?

- You can join the waitlist now to get priority access when the ceremony opens. - -
diff --git a/ceremony/src/lib/components/Queue.svelte b/ceremony/src/lib/components/Queue.svelte index 6740d88375..e08655856b 100644 --- a/ceremony/src/lib/components/Queue.svelte +++ b/ceremony/src/lib/components/Queue.svelte @@ -1,16 +1,13 @@ -

- -

-

You are {contributor.queueState.position}{getNumberSuffix(contributor.queueState.position)} in queue

+ You are {contributor.queueState.position}{getNumberSuffix(contributor.queueState.position)} in queue
-

Queue length: {contributor.queueState.count}

-

Waiting time: {contributor.queueState.estimatedTime} minutes + Queue length: {contributor.queueState.count} + Waiting time: {contributor.queueState.estimatedTime} minutes (est.). -

+
\ No newline at end of file diff --git a/ceremony/src/lib/components/Reward.svelte b/ceremony/src/lib/components/Reward.svelte index 807b40515c..cc847aae6d 100644 --- a/ceremony/src/lib/components/Reward.svelte +++ b/ceremony/src/lib/components/Reward.svelte @@ -1,50 +1,30 @@ -
-

Add an address

- You may receive rewards for successful contributions. - You can enter your union or any cosmos address. - (addressValidState = result)} {contributor} /> - Or -

I don't want rewards

- You can contribute without adding an address. - -
\ No newline at end of file +{#if showInput} +
+
+ Enter address: +
+ +
+{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/SwimLoad.svelte b/ceremony/src/lib/components/SwimLoad.svelte index 24c358a796..7289c7c091 100644 --- a/ceremony/src/lib/components/SwimLoad.svelte +++ b/ceremony/src/lib/components/SwimLoad.svelte @@ -1,5 +1,7 @@ {#if activity.data} + ceremony activity {#each activity.data as item, i (item)} {@const type = item.message.type} {@const user = item.message.user} diff --git a/ceremony/src/lib/components/TerminalApp/Authenticate.svelte b/ceremony/src/lib/components/TerminalApp/Authenticate.svelte index 148891c314..84804c49ed 100644 --- a/ceremony/src/lib/components/TerminalApp/Authenticate.svelte +++ b/ceremony/src/lib/components/TerminalApp/Authenticate.svelte @@ -1,56 +1,54 @@ {#if !redirecting} diff --git a/ceremony/src/lib/components/TerminalApp/Ceremony.svelte b/ceremony/src/lib/components/TerminalApp/Ceremony.svelte new file mode 100644 index 0000000000..62c2ffdf39 --- /dev/null +++ b/ceremony/src/lib/components/TerminalApp/Ceremony.svelte @@ -0,0 +1,67 @@ + + +{#if !contributor.userWallet} + + +{:else if contributor.state === 'contributed'} + + +{:else if contributor.state === 'verifying'} + {terminal.updateHistory("Verifying your contribution...")} + + +{:else if client.state === 'offline'} + + +{:else if !contributor.downloadedSecret} + + +{:else if contributor.state === "inQueue"} + + +{:else if contributor.state === 'contribute'} + {terminal.updateHistory("Starting contribution...")} + + +{:else if contributor.state === 'contributing'} + {terminal.updateHistory("Contributing...")} + + +{:else} + Not able to contribute at this time + +{/if} diff --git a/ceremony/src/lib/components/TerminalApp/CommandBar.svelte b/ceremony/src/lib/components/TerminalApp/CommandBar.svelte deleted file mode 100644 index 67ae89f729..0000000000 --- a/ceremony/src/lib/components/TerminalApp/CommandBar.svelte +++ /dev/null @@ -1,4 +0,0 @@ - - diff --git a/ceremony/src/lib/components/TerminalApp/Contributors.svelte b/ceremony/src/lib/components/TerminalApp/Contributors.svelte index 12b7d456e5..5535857b1a 100644 --- a/ceremony/src/lib/components/TerminalApp/Contributors.svelte +++ b/ceremony/src/lib/components/TerminalApp/Contributors.svelte @@ -1,6 +1,6 @@ {#if contributions.data} @@ -63,7 +59,6 @@ onMount(() => { class="text-start w-full max-w-5xl whitespace-nowrap truncate focus:outline-none" class:text-union-accent-500={index === selectedIndex} onclick={() => fireEvent(contributor)} - onkeydown={handleKeydown} > > {contributor.payload_id} diff --git a/ceremony/src/lib/components/TerminalApp/Join.svelte b/ceremony/src/lib/components/TerminalApp/Join.svelte index ad0e7bc269..6e94995903 100644 --- a/ceremony/src/lib/components/TerminalApp/Join.svelte +++ b/ceremony/src/lib/components/TerminalApp/Join.svelte @@ -1,55 +1,100 @@ -

Join the ceremony

-Have an invite? Enter your code below. -
- - -Or -

Don't have an invite?

-You can join the waitlist now to get priority access when the ceremony opens. +{terminal.updateHistory("Access the ceremony")} + +{#if !selected} + + {#if code } + + {:else } + {#each buttons as button, index} + + {/each} + {/if} + +{/if} + diff --git a/ceremony/src/lib/components/TerminalApp/Print.svelte b/ceremony/src/lib/components/TerminalApp/Print.svelte index bcb5fa1305..5b0c904ec1 100644 --- a/ceremony/src/lib/components/TerminalApp/Print.svelte +++ b/ceremony/src/lib/components/TerminalApp/Print.svelte @@ -2,4 +2,4 @@ let { children } = $props() -

{@render children()}

+

{@render children()}

diff --git a/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte b/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte index d15135da68..85b6237877 100644 --- a/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte +++ b/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte @@ -1,65 +1,58 @@
@@ -77,31 +70,36 @@ const changeTab = async (tab: number) => { {#if terminal.hash !== undefined} + class:text-white={terminal.tab === 4}> + {#if terminal.hash} + {terminal.hash.slice(0, 5)}...{terminal.hash.slice(-5)} + {:else} + {terminal.hash} + {/if} + {/if}
+
- {#if terminal.tab === 1 } + {#if terminal.tab === 1}
{#each terminal.history as text} {text} {/each}
{@render children()} - {:else if terminal.tab === 2} - {:else if terminal.tab === 3} - - {:else if terminal.tab === 4} + {:else if terminal.tab === 4 && terminal.hash} {@render children()} - {/if} +
+ diff --git a/ceremony/src/lib/components/TerminalApp/Waitlist.svelte b/ceremony/src/lib/components/TerminalApp/Waitlist.svelte index 378cf582d1..1ab681a10d 100644 --- a/ceremony/src/lib/components/TerminalApp/Waitlist.svelte +++ b/ceremony/src/lib/components/TerminalApp/Waitlist.svelte @@ -1,23 +1,14 @@ -

You're on the waitlist

-When the ceremony opens to the public, you will be {contributor.waitListPosition}{getNumberSuffix(contributor.waitListPosition)} in the public queue. -You will receive an email 12-18 hours before the public phase begins. -

Received an invite?

-You can skip the waitlist and join now. -
- - \ No newline at end of file +{terminal.updateHistory("You're on the waitlist")} +{terminal.updateHistory(`When the ceremony opens to the public, you will be ${contributor.waitListPosition}${getNumberSuffix(contributor.waitListPosition)} in the public queue.`)} +{terminal.updateHistory("You will receive an email 12-18 hours before the public phase begins.")} +{terminal.updateHistory("Received an invite? You can skip the waitlist and join now.")} + diff --git a/ceremony/src/lib/components/Thanks.svelte b/ceremony/src/lib/components/Thanks.svelte index e3ae2717e8..4fc0f8d908 100644 --- a/ceremony/src/lib/components/Thanks.svelte +++ b/ceremony/src/lib/components/Thanks.svelte @@ -1,23 +1,12 @@
-

-

Thank you!

- Your contribution is complete. Thank you for securing the Union network.
Tweet your cryptographic attestation for extra transparency:
- + Thank you! + Your contribution is complete. Thank you for securing the Union network.
Tweet your cryptographic attestation for extra transparency:
- View contributions - + View contributions
\ No newline at end of file diff --git a/ceremony/src/lib/components/Waitlist.svelte b/ceremony/src/lib/components/Waitlist.svelte index 378cf582d1..60f7ab59f2 100644 --- a/ceremony/src/lib/components/Waitlist.svelte +++ b/ceremony/src/lib/components/Waitlist.svelte @@ -1,10 +1,8 @@ -

You're on the waitlist

-When the ceremony opens to the public, you will be {contributor.waitListPosition}{getNumberSuffix(contributor.waitListPosition)} in the public queue. -You will receive an email 12-18 hours before the public phase begins. -

Received an invite?

-You can skip the waitlist and join now. +You're on the waitlist +When the ceremony opens to the public, you will be {contributor.waitListPosition}{getNumberSuffix(contributor.waitListPosition)} in the public queue. +You will receive an email 12-18 hours before the public phase begins. +Received an invite? +You can skip the waitlist and join now.
\ No newline at end of file diff --git a/ceremony/src/lib/components/Warning.svelte b/ceremony/src/lib/components/Warning.svelte index fae0dc7a2d..869f17d44f 100644 --- a/ceremony/src/lib/components/Warning.svelte +++ b/ceremony/src/lib/components/Warning.svelte @@ -1,5 +1,6 @@ -
+ -
diff --git a/ceremony/src/lib/components/address/index.ts b/ceremony/src/lib/components/address/index.ts index 9603cf679d..837d28ee9b 100644 --- a/ceremony/src/lib/components/address/index.ts +++ b/ceremony/src/lib/components/address/index.ts @@ -1,5 +1,5 @@ import AddressForm from "./AddressForm.svelte" -export type ValidState = "PENDING" | "VALID" | "INVALID" +export type ValidState = "PENDING" | "VALID" | "INVALID" | "SKIPPED" | undefined export { AddressForm } diff --git a/ceremony/src/lib/components/typography/H1.svelte b/ceremony/src/lib/components/typography/H1.svelte deleted file mode 100644 index 67ef60ffcd..0000000000 --- a/ceremony/src/lib/components/typography/H1.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -

- {@render children()} -

diff --git a/ceremony/src/lib/components/typography/H2.svelte b/ceremony/src/lib/components/typography/H2.svelte deleted file mode 100644 index 68edddf547..0000000000 --- a/ceremony/src/lib/components/typography/H2.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -

- {@render children()} -

diff --git a/ceremony/src/lib/components/typography/H3.svelte b/ceremony/src/lib/components/typography/H3.svelte deleted file mode 100644 index 174bf012a7..0000000000 --- a/ceremony/src/lib/components/typography/H3.svelte +++ /dev/null @@ -1,6 +0,0 @@ - -

- {@render children()} -

diff --git a/ceremony/src/lib/components/typography/H4.svelte b/ceremony/src/lib/components/typography/H4.svelte deleted file mode 100644 index c9bc1165a2..0000000000 --- a/ceremony/src/lib/components/typography/H4.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -

- {@render children()} -

diff --git a/ceremony/src/lib/components/typography/H5.svelte b/ceremony/src/lib/components/typography/H5.svelte deleted file mode 100644 index f998ecbe96..0000000000 --- a/ceremony/src/lib/components/typography/H5.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -
- {@render children()} -
diff --git a/ceremony/src/lib/components/typography/H6.svelte b/ceremony/src/lib/components/typography/H6.svelte deleted file mode 100644 index 04431af3bd..0000000000 --- a/ceremony/src/lib/components/typography/H6.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -
- {@render children()} -
diff --git a/ceremony/src/lib/components/typography/Link.svelte b/ceremony/src/lib/components/typography/Link.svelte deleted file mode 100644 index de0ef67884..0000000000 --- a/ceremony/src/lib/components/typography/Link.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - - - {@render children()} - \ No newline at end of file diff --git a/ceremony/src/lib/components/typography/Text.svelte b/ceremony/src/lib/components/typography/Text.svelte deleted file mode 100644 index 5315bdb170..0000000000 --- a/ceremony/src/lib/components/typography/Text.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - -

- {@render children()} -

diff --git a/ceremony/src/lib/state/client.svelte.ts b/ceremony/src/lib/state/client.svelte.ts index e77fd71aa8..9ccc461380 100644 --- a/ceremony/src/lib/state/client.svelte.ts +++ b/ceremony/src/lib/state/client.svelte.ts @@ -44,16 +44,16 @@ export class Client { this.pollingInterval = setInterval( () => this.checkStatus(), CLIENT_POLLING_INTERVAL - ) as unknown as number + ) this.isPolling = true } } stopPolling(): void { - if (this.isPolling) { + if (this.isPolling && this.pollingInterval !== null) { clearInterval(this.pollingInterval) this.pollingInterval = null this.isPolling = false } } -} +} \ No newline at end of file diff --git a/ceremony/src/lib/state/contributor.svelte.ts b/ceremony/src/lib/state/contributor.svelte.ts index 38eff51cd7..187f12dc26 100644 --- a/ceremony/src/lib/state/contributor.svelte.ts +++ b/ceremony/src/lib/state/contributor.svelte.ts @@ -1,146 +1,252 @@ +import { getContext, onDestroy, setContext } from "svelte" import { getCurrentUserState, getUserQueueInfo, getContributionState, getUserWallet, - getWaitListPosition + getWaitListPosition, checkIfOpen } from "$lib/supabase" -import type { Session } from "@supabase/supabase-js" + +type IntervalID = NodeJS.Timeout | number + +type State = + | "loading" + | "inQueue" + | "contribute" + | "contributing" + | "verifying" + | "contributed" + | "error" + | "offline" + | "noClient" export type AllowanceState = "hasRedeemed" | "inWaitlist" | "inQueue" | "join" | undefined export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed" -interface QueueState { +interface UserContext { position: number | null count: number | null estimatedTime: number | null error: string | null } -type UserState = Session | null +interface QueueInfoSuccess { + inQueue: true + position: number + count: number +} -const QUEUE_POLLING_INTERVAL = 5000 -const CONTRIBUTION_POLLING_INTERVAL = 5000 +interface QueueInfoError { + inQueue: false + message: string +} + +type QueueInfoResult = QueueInfoSuccess | QueueInfoError + +const second = 1000 +const CONTRIBUTION_POLLING_INTERVAL = second * 5 +const QUEUE_POLLING_INTERVAL = second * 5 export class Contributor { + userId = $state(undefined) + loggedIn = $state(false) currentUserState = $state(undefined) + pollingState = $state<"stopped" | "polling">("stopped") + state = $state("loading") + + openToPublic = $state(false) contributionState = $state("notContributed") userWallet = $state("") - waitListPosition = $state(undefined) + downloadedSecret = $state(localStorage.getItem("downloaded-secret") === "true") - queueState = $state({ + queueState = $state({ position: null, count: null, estimatedTime: null, error: null }) - private queuePollingInterval: number | null = null - private contributionPollingInterval: number | null = null + private pollIntervals: { + client: IntervalID | null + queue: IntervalID | null + contribution: IntervalID | null + } = { + client: null, + queue: null, + contribution: null + } - // if(this.session) { - // await Promise.all([ - // this.checkWaitListPosition(), - // this.checkUserWallet(), - // this.checkCurrentUserState() - // ]) - // this.startPolling() - //} + constructor(userId?: string) { + if (userId) { + this.userId = userId + this.loggedIn = true + this.checkCurrentUserState(userId) + this.checkIfOpen() + this.startPolling() + } + onDestroy(() => { + this.stopPolling() + }) + } - private async checkWaitListPosition(): Promise { + setUserId(userId: string | undefined) { + if (this.userId === undefined && userId) { + this.userId = userId + this.loggedIn = true + this.checkWaitListPosition(userId) + this.checkUserWallet(userId) + this.checkCurrentUserState(userId) + this.startPolling() + } + } + + async checkIfOpen() { + this.openToPublic = await checkIfOpen() + } + + async checkWaitListPosition(_userId: string | undefined): Promise { this.waitListPosition = await getWaitListPosition() + return this.waitListPosition } - private async checkCurrentUserState(): Promise { - this.currentUserState = await getCurrentUserState("") + async checkCurrentUserState(userId: string | undefined): Promise { + this.currentUserState = await getCurrentUserState(userId) + return this.currentUserState } - private async checkUserWallet(): Promise { - this.userWallet = await getUserWallet("") + async checkUserWallet(userId: string | undefined): Promise { + this.userWallet = await getUserWallet(userId) + return this.userWallet } - startPolling(): void { - this.startQueuePolling() - this.startContributionPolling() + setAllowanceState(state: AllowanceState) { + this.currentUserState = state + this.pollQueueInfo() + this.pollContributionState() } - stopPolling(): void { - this.stopQueuePolling() - this.stopContributionPolling() + startPolling() { + if (this.pollingState === "polling") { + console.log("Polling is already running.") + return + } + + if (!this.userId) { + console.log("Cannot start polling without userId.") + return + } + + this.pollingState = "polling" + this.startQueueInfoPolling() + this.startContributionStatePolling() } - private startQueuePolling(): void { - if (this.queuePollingInterval === null) { - this.pollQueueInfo() - this.queuePollingInterval = setInterval( - () => this.pollQueueInfo(), - QUEUE_POLLING_INTERVAL - ) as unknown as number + stopPolling() { + if (this.pollingState === "stopped") { + console.log("Polling is already stopped.") + return } + + this.pollingState = "stopped" + this.stopClientStatePolling() + this.stopQueueInfoPolling() + this.stopContributionStatePolling() } - private stopQueuePolling(): void { - if (this.queuePollingInterval !== null) { - clearInterval(this.queuePollingInterval) - this.queuePollingInterval = null + private stopClientStatePolling() { + if (this.pollIntervals.client) { + clearInterval(this.pollIntervals.client) + this.pollIntervals.client = null } } - private async pollQueueInfo(): Promise { + + private startQueueInfoPolling() { + this.pollQueueInfo() + this.pollIntervals.queue = setInterval( + () => this.pollQueueInfo(), + QUEUE_POLLING_INTERVAL + ) as IntervalID + } + + private stopQueueInfoPolling() { + if (this.pollIntervals.queue) { + clearInterval(this.pollIntervals.queue) + this.pollIntervals.queue = null + } + } + + private async pollQueueInfo() { try { const queueInfo = await getUserQueueInfo() - if ("inQueue" in queueInfo && queueInfo.inQueue) { - this.queueState = { - position: queueInfo.position, - count: queueInfo.count, - estimatedTime: queueInfo.position * 60, - error: null - } - } else { - this.queueState = { - position: null, - count: null, - estimatedTime: null, - error: null - } - } + this.updateQueueInfo(queueInfo) } catch (error) { - console.error("Error polling queue info:", error) - this.queueState = { - ...this.queueState, - error: error instanceof Error ? error.message : "Unknown error occurred" - } + console.log("Error polling queue info:", error) + this.setError(error instanceof Error ? error.message : "Unknown error occurred") } } - private startContributionPolling(): void { - if (this.contributionPollingInterval === null) { - this.pollContributionState() - this.contributionPollingInterval = setInterval( - () => this.pollContributionState(), - CONTRIBUTION_POLLING_INTERVAL - ) as unknown as number - } + private startContributionStatePolling() { + this.pollContributionState() + this.pollIntervals.contribution = setInterval( + () => this.pollContributionState(), + CONTRIBUTION_POLLING_INTERVAL + ) as IntervalID } - private stopContributionPolling(): void { - if (this.contributionPollingInterval !== null) { - clearInterval(this.contributionPollingInterval) - this.contributionPollingInterval = null + private stopContributionStatePolling() { + if (this.pollIntervals.contribution) { + clearInterval(this.pollIntervals.contribution) + this.pollIntervals.contribution = null } } - private async pollContributionState(): Promise { + private async pollContributionState() { try { - this.contributionState = await getContributionState() + const state = await getContributionState() + this.updateContributionState(state) } catch (error) { - console.error("Error polling contribution state:", error) - // You might want to handle this error differently + console.log("Error polling contribution state:", error) + this.setError(error instanceof Error ? error.message : "Unknown error occurred") + } + } + + + private updateQueueInfo(queueInfo: QueueInfoResult) { + if (queueInfo.inQueue) { + this.queueState = { + ...this.queueState, + position: queueInfo.position, + count: queueInfo.count, + estimatedTime: queueInfo.position * 60 + } + } else { + this.queueState = { + ...this.queueState, + position: null, + count: null, + estimatedTime: null + } } } - constructor() { - console.log("Creating contributor state") + private updateContributionState(state: ContributionState) { + this.contributionState = state + } + + private setError(message: string) { + this.queueState = { ...this.queueState, error: message } + this.state = "error" } } + +const CONTRIBUTOR_KEY = Symbol("CONTRIBUTOR") + +export function setContributorState() { + return setContext(CONTRIBUTOR_KEY, new Contributor()) +} + +export function getContributorState(): Contributor { + return getContext(CONTRIBUTOR_KEY) +} diff --git a/ceremony/src/lib/state/session.svelte.ts b/ceremony/src/lib/state/session.svelte.ts index 4f37386081..7207f5dcdf 100644 --- a/ceremony/src/lib/state/session.svelte.ts +++ b/ceremony/src/lib/state/session.svelte.ts @@ -1,42 +1,60 @@ -import type { Session } from "@supabase/supabase-js" -import { supabase } from "$lib/supabase/client.ts" -import { err, ok, type Result } from "neverthrow" -import { goto, invalidateAll } from "$app/navigation" -import type { Terminal } from "$lib/state/terminal.svelte.ts" +import type {Session} from "@supabase/supabase-js" +import {supabase} from "$lib/supabase/client.ts" +import {err, ok, type Result} from "neverthrow" +import {invalidateAll} from "$app/navigation" +import type {Terminal} from "$lib/state/terminal.svelte.ts" -export type UserSession = { - session: Session | null | false -} export type SessionError = { message: string } -export let user = $state({ session: false }) +export type UserSession = { + session: Session | null + loading: boolean +} + +export let user = $state({session: null, loading: true}) export async function checkAuth(): Promise> { + user.loading = true; const { - data: { session }, + data: {session}, error } = await supabase.auth.getSession() if (error || !session) { - return err({ message: "User not authenticated" }) - } - if (session) { - user.session = session + user.session = null; + user.loading = false; + return err({message: "User not authenticated"}) } + user.session = session; + user.loading = false; return ok(null) } -export async function logout(terminal: Terminal) { - if (user.session === null || user.session === undefined) return - terminal.updateHistory("user logged out") - const { error } = await supabase.auth.signOut() - if (error) { - terminal.updateHistory("error logging out") - } else { - user.session = null - invalidateAll() - goto("/") +export async function logout(terminal: Terminal): Promise { + if (!user.session) { + console.log('user already logged out'); + return; + } + + terminal.updateHistory("logging out user..."); + + try { + terminal.setHash(undefined); + terminal.setTab(1); + + terminal.updateHistory("user successfully logged out"); + const {error} = await supabase.auth.signOut(); + + user.session = null; + + await invalidateAll(); + } catch (error) { + terminal.updateHistory(`error logging out`); + + terminal.setHash(undefined); + terminal.setTab(1); + user.session = null; } } diff --git a/ceremony/src/lib/state/terminal.svelte.ts b/ceremony/src/lib/state/terminal.svelte.ts index d20b31a2cd..6034f4267e 100644 --- a/ceremony/src/lib/state/terminal.svelte.ts +++ b/ceremony/src/lib/state/terminal.svelte.ts @@ -1,22 +1,66 @@ import { getContext, setContext } from "svelte" +import { readable } from 'svelte/store'; export type AuthProviders = "github" | "google" export type State = "hasRedeemed" | "inQueue" | "inWaitlist" | "join" | undefined +interface UpdateHistoryOptions { + duplicate?: boolean; + replace?: boolean; +} + +export type KeyEvent = { + key: string; + type: 'keydown' | 'keyup'; + shiftKey: boolean; + ctrlKey: boolean; +}; + export class Terminal { state = $state(undefined) history = $state>([]) tab = $state<1 | 2 | 3 | number>(1) hash = $state(undefined) + keys = readable(null, (set) => { + const handleKeyEvent = (event: KeyboardEvent) => { + set({ + key: event.key, + type: event.type as 'keydown' | 'keyup', + shiftKey: event.shiftKey, + ctrlKey: event.ctrlKey + }); + }; + + if (typeof window !== 'undefined') { + window.addEventListener('keydown', handleKeyEvent); + window.addEventListener('keyup', handleKeyEvent); + } + + return () => { + if (typeof window !== 'undefined') { + window.removeEventListener('keydown', handleKeyEvent); + window.removeEventListener('keyup', handleKeyEvent); + } + }; + }); + constructor() { console.log("Creating terminal state") } - updateHistory(text: string) { - if (!this.history.includes(text)) { - this.history.push(text) - return true + updateHistory(text: string, options: UpdateHistoryOptions = {}) { + const { duplicate = false, replace = false } = options; + + const index = this.history.indexOf(text); + + if (duplicate) { + this.history.push(text); + } else if (replace && index !== -1) { + this.history.splice(index, 1); + this.history.push(text); + } else if (!this.history.includes(text)) { + this.history.push(text); } } @@ -24,7 +68,7 @@ export class Terminal { this.tab = tab } - setHash(hash: string) { + setHash(hash: string | undefined) { this.hash = hash } @@ -39,4 +83,4 @@ export function setTerminal() { export function getTerminal(): Terminal { return getContext(TERMINAL_KEY) -} +} \ No newline at end of file diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index f564acc704..edbc7833ff 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -15,7 +15,10 @@ import { supabase } from "$lib/supabase/client.ts" import type { AllowanceState, ContributionState } from "$lib/stores/state.svelte.ts" export const callJoinQueue = async (code: string | null): Promise => { - const userId = user.session?.user.id + if (!user.session) { + throw new Error("User is not logged in") + } + const userId = user.session.user.id if (!userId) { throw new Error("User is not logged in") } @@ -42,10 +45,10 @@ export const checkIfOpen = async (): Promise => { } export const getUserQueueInfo = async () => { - const userId = user.session?.user.id - if (!userId) { + if (!user.session) { throw new Error("User is not logged in") } + const userId = user.session.user.id const { data, error } = await getUserQueuePosition(userId) const { count, error: countError } = await getQueueCount() @@ -70,7 +73,10 @@ export const getUserQueueInfo = async () => { } export const getContributionState = async (): Promise => { - const userId = user.session?.user.id + if (!user.session) { + throw new Error("User is not logged in") + } + const userId = user.session.user.id if (!userId) { throw new Error("User ID is required") } @@ -114,11 +120,11 @@ export const getCurrentUserState = async (userId: string | undefined): Promise { @@ -160,10 +166,10 @@ export const insertWalletData = async (data: WalletData) => { } export const getPublicHash = async () => { - const userId = user.session?.user.id - if (!userId) { - throw new Error("User ID is required") + if (!user.session) { + throw new Error("User is not logged in") } + const userId = user.session.user.id const { data, error } = await queryUserPublicHash(userId) if (error || !data) return undefined diff --git a/ceremony/src/lib/supabase/queries.ts b/ceremony/src/lib/supabase/queries.ts index a198e08ac1..8302477f76 100644 --- a/ceremony/src/lib/supabase/queries.ts +++ b/ceremony/src/lib/supabase/queries.ts @@ -62,7 +62,7 @@ export const queryCurrentUserState = async () => { export const queryContributions = async () => { const { data, error } = await supabase .from("users_contribution") - .select("public_key_hash, user_name, avatar_url, payload_id") + .select("public_key_hash, payload_id") .order("time_verified", { ascending: false }) return { data, error } diff --git a/ceremony/src/lib/utils/Keydown.svelte b/ceremony/src/lib/utils/Keydown.svelte deleted file mode 100644 index b039eb7e6e..0000000000 --- a/ceremony/src/lib/utils/Keydown.svelte +++ /dev/null @@ -1,34 +0,0 @@ - \ No newline at end of file diff --git a/ceremony/src/lib/utils/utils.ts b/ceremony/src/lib/utils/utils.ts index c9db10eb12..47ffa133dc 100644 --- a/ceremony/src/lib/utils/utils.ts +++ b/ceremony/src/lib/utils/utils.ts @@ -31,3 +31,8 @@ export function isSafari(): boolean { const ua = navigator.userAgent.toLowerCase() return ua.indexOf("safari") > -1 && ua.indexOf("chrome") === -1 } + +export function sleep(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); +} + diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index c4aa4864a6..6644ac898d 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -1,30 +1,31 @@ - - - +
- {@render children()} + + {@render children()} +
\ No newline at end of file diff --git a/ceremony/src/routes/+layout.ts b/ceremony/src/routes/+layout.ts index 98eaf2c1a6..3c29a22969 100644 --- a/ceremony/src/routes/+layout.ts +++ b/ceremony/src/routes/+layout.ts @@ -1,27 +1,29 @@ +import {checkAuth, type SessionError} from "$lib/state/session.svelte.ts"; +import type {LayoutLoad} from "../../.svelte-kit/types/src/routes/$types"; +import {redirect} from "@sveltejs/kit"; + export const ssr = false export const prerender = true export const trailingSlash = "ignore" -// export const load: LayoutLoad = async ({ url }) => { -// const pathname = url.pathname -// -// console.log('load') -// -// if (pathname) { -// const segments = pathname.split("/").filter(Boolean) -// if (segments[0] === "terminal") { -// const authCheck = await checkAuth() -// return authCheck.match( -// () => { -// return {} -// }, -// (error: SessionError) => { -// console.error(error.message) -// throw redirect(302, "/") -// } -// ) -// } -// } -// -// return {} -// } +export const load: LayoutLoad = async ({ url }) => { + const pathname = url.pathname + + if (pathname) { + const segments = pathname.split("/").filter(Boolean) + if (segments[0] === "terminal") { + const authCheck = await checkAuth() + return authCheck.match( + () => { + return {} + }, + (error: SessionError) => { + console.error(error.message) + throw redirect(302, "/") + } + ) + } + } + + return {} +} diff --git a/ceremony/src/routes/+page.svelte b/ceremony/src/routes/+page.svelte index ab4f929459..4c3386ca15 100644 --- a/ceremony/src/routes/+page.svelte +++ b/ceremony/src/routes/+page.svelte @@ -1,19 +1,34 @@ - - {terminal.updateHistory("welcome to union ceremony")} +{terminal.updateHistory("Welcome to union ceremony")} +{#if user.loading} + loading... +{:else} {#if user.session} - {terminal.updateHistory(`authenticated user: ${user.session.user.email}`)} - {:else if user.session === null} - - {:else} - Loading... + {terminal.updateHistory(`Authenticated user: ${user.session.user.email}`)} + {#if contributor.currentUserState === "hasRedeemed" || contributor.currentUserState === "inQueue"} + + {:else if contributor.currentUserState === "inWaitlist"} + + {:else if contributor.currentUserState === "join"} + + {/if} + + {:else if user.session === null && terminal.tab === 1} + {/if} - \ No newline at end of file +{/if} diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index 86e2745fec..da7c432c9d 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -1,44 +1,43 @@ @@ -71,26 +70,26 @@ const imagePath = "https://ceremony.union.build/images/ceremony.png" - - {#await getUserContribution(hash)} - Loading - {:then contribution} - {#if contribution} - {hash} - Public key -
{decodeHexString(contribution.public_key)}
- Signature -
{decodeHexString(contribution.signature)}
- - - {/if} - {/await} -
+ +{#await getUserContribution(hash)} + Loading +{:then contribution} + {#if contribution} + {hash} + Public key +
{decodeHexString(contribution.public_key)}
+ Signature +
{decodeHexString(contribution.signature)}
+ + + {/if} +{/await} + + +{queueBar} - {percentageText} diff --git a/ceremony/src/lib/components/TerminalApp/Ceremony.svelte b/ceremony/src/lib/components/TerminalApp/Ceremony.svelte index 4be27a3368..ee3a95339d 100644 --- a/ceremony/src/lib/components/TerminalApp/Ceremony.svelte +++ b/ceremony/src/lib/components/TerminalApp/Ceremony.svelte @@ -37,13 +37,13 @@ {#if !contributor.userWallet} -{:else if contributor.state !== 'contributed'} +{:else if contributor.state === 'contributed'} {:else if contributor.state === 'verifying'} {terminal.updateHistory("Verifying your contribution...")} -{:else if contributor.state === "inQueue"} +{:else if contributor.state !== "inQueue"} {:else if contributor.state === 'contribute'} diff --git a/ceremony/src/lib/components/TerminalApp/Contributors.svelte b/ceremony/src/lib/components/TerminalApp/Contributors.svelte index 5535857b1a..5067b529a1 100644 --- a/ceremony/src/lib/components/TerminalApp/Contributors.svelte +++ b/ceremony/src/lib/components/TerminalApp/Contributors.svelte @@ -2,14 +2,13 @@ import { getState } from "$lib/state/index.svelte.ts" import {onDestroy, onMount} from "svelte" import Print from "$lib/components/TerminalApp/Print.svelte" -import { goto } from "$app/navigation" +import {goto} from "$app/navigation" const { contributions, terminal } = getState() let selectedIndex = $state(0) let buttons: Array = [] - function fireEvent(contributor: any) { console.log("selected contributor:", contributor) goto(`/0____0/${contributor.public_key_hash}`) @@ -21,33 +20,45 @@ onMount(() => { buttons[0].focus() }) -const unsubscribe = terminal.keys.subscribe((event) => { - if (event) { - if (!contributions.data) return - if(event.type !== 'keydown') return; - console.log('dd') - switch (event.key) { - case "ArrowUp": { - selectedIndex = (selectedIndex - 1 + contributions.data.length) % contributions.data.length - buttons[selectedIndex]?.focus() - break - } - case "ArrowDown": { - selectedIndex = (selectedIndex + 1) % contributions.data.length - buttons[selectedIndex]?.focus() - break - } - case "Enter": { - if (buttons[selectedIndex]) { - fireEvent(contributions.data[selectedIndex]) +let unsubscribe: (() => void) | undefined; +let subscriptionTimeout: NodeJS.Timeout | undefined; +onMount(() => { + subscriptionTimeout = setTimeout(() => { + unsubscribe = terminal.keys.subscribe((event) => { + if (event) { + if(event.type === "keydown") { + switch (event.key) { + case "ArrowUp": { + selectedIndex = (selectedIndex - 1 + contributions.data.length) % contributions.data.length + buttons[selectedIndex]?.focus() + break + } + case "ArrowDown": { + selectedIndex = (selectedIndex + 1) % contributions.data.length + buttons[selectedIndex]?.focus() + break + } + case "Enter": { + if (buttons[selectedIndex]) { + fireEvent(contributions.data[selectedIndex]) + } + break + } + } } - break } + }); + }, 200); + return(() => { + if (subscriptionTimeout) { + clearTimeout(subscriptionTimeout); + } + if (unsubscribe) { + unsubscribe(); } - } + }) }); -onDestroy(unsubscribe); @@ -58,7 +69,6 @@ onDestroy(unsubscribe); bind:this={buttons[index]} class="text-start w-full max-w-5xl whitespace-nowrap truncate focus:outline-none" class:text-union-accent-500={index === selectedIndex} - onclick={() => fireEvent(contributor)} > > {contributor.payload_id} diff --git a/ceremony/src/lib/components/TerminalApp/Print.svelte b/ceremony/src/lib/components/TerminalApp/Print.svelte index 5b0c904ec1..43b580a7c0 100644 --- a/ceremony/src/lib/components/TerminalApp/Print.svelte +++ b/ceremony/src/lib/components/TerminalApp/Print.svelte @@ -1,5 +1,11 @@ -

{@render children()}

+

{@render children()}

\ No newline at end of file diff --git a/ceremony/src/lib/components/Thanks.svelte b/ceremony/src/lib/components/Thanks.svelte index 30a19b4f85..5f1d94a104 100644 --- a/ceremony/src/lib/components/Thanks.svelte +++ b/ceremony/src/lib/components/Thanks.svelte @@ -1,76 +1,89 @@ -{#each buttons as btn, index} - -{/each} \ No newline at end of file +{#if showButtons} + {#each buttons as btn, index} + + {/each} +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Warning.svelte b/ceremony/src/lib/components/Warning.svelte index 869f17d44f..9da0a17ccb 100644 --- a/ceremony/src/lib/components/Warning.svelte +++ b/ceremony/src/lib/components/Warning.svelte @@ -14,6 +14,7 @@ let { stupid = true } = $props() Your MPC Client is connected. Do not close this tab or your Terminal. {/if} + Ensure you have a reliable internet connection
and that your computer
does diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index 3d3c7012b6..d8a10fa9b6 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -120,7 +120,7 @@ export const getCurrentUserState = async (userId: string | undefined): Promise{hash} - Public key + Public key
{decodeHexString(contribution.public_key)}
- Signature + Signature
{decodeHexString(contribution.signature)}
-{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Code.svelte b/ceremony/src/lib/components/Code.svelte deleted file mode 100644 index c1ec8262a9..0000000000 --- a/ceremony/src/lib/components/Code.svelte +++ /dev/null @@ -1,71 +0,0 @@ - - -{#if showInput} -
-
- Enter code: -
- -
-{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Contribution.svelte b/ceremony/src/lib/components/Contribution.svelte deleted file mode 100644 index 65c2fcc3c5..0000000000 --- a/ceremony/src/lib/components/Contribution.svelte +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - -{#await getUserContribution(hash)} - -{:then contribution} - {#if contribution} -
-
-

Contributor: {contribution.user_name}

-
- -
-
-

Public key

-
{decodeHexString(contribution.public_key)}
- -
- -
-

Signature

-
{decodeHexString(contribution.signature)}
- -
-
-
- {/if} -{/await} \ No newline at end of file diff --git a/ceremony/src/lib/components/Contributions.svelte b/ceremony/src/lib/components/Contributions.svelte deleted file mode 100644 index 12eb0b4d0f..0000000000 --- a/ceremony/src/lib/components/Contributions.svelte +++ /dev/null @@ -1,46 +0,0 @@ - -{#if contributions} - -
-
-
-
-
- {#each contributions as contribution, index } - - - {(index + 1) * 10}M -
- - {contribution.user_name} -
-
- {#if index !== contributions.length - 1} -
- {/if} - {/each} -
-
-{:else} - -{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Download.svelte b/ceremony/src/lib/components/Download.svelte deleted file mode 100644 index 62e0811b35..0000000000 --- a/ceremony/src/lib/components/Download.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - -{#if !generating} - {#if !generated} - - {:else} - - - {/if} -{/if} diff --git a/ceremony/src/lib/components/Install.svelte b/ceremony/src/lib/components/Install.svelte deleted file mode 100644 index 0ef8705e53..0000000000 --- a/ceremony/src/lib/components/Install.svelte +++ /dev/null @@ -1,90 +0,0 @@ - - -{#if contributor} -
- - Run the MPC client - - You must have docker installed in order to contribute.
On linux, install docker through your package manager, and skip to step 5. -
- On macOS, we highly recommend - OrbStack - because Docker Desktop is too slow. -
- - If you use Docker Desktop it is extremely likely that you will lose your contribution slot. - -
- - 1. Install OrbStack - - - 2. Open OrbStack from the Applications/ folder - - - 3. Click allow on the OrbStack popups - - - 4. Open Terminal from the Applications/Utilities/ folder - - - 5. Paste the following command in Terminal to start the MPC client: - -
- -
- - Once the MPC client is running you can return to this page. - - - If the MPC client is running but you still see this page, ensure that you are using either Chrome, FireFox or Brave. -
- For Brave, disable the shields in the address bar. -
- {#if isSafari()} -
- Safari is not supported -
- {/if} -
-{/if} diff --git a/ceremony/src/lib/components/Live.svelte b/ceremony/src/lib/components/Live.svelte deleted file mode 100644 index 9d80e2c1a6..0000000000 --- a/ceremony/src/lib/components/Live.svelte +++ /dev/null @@ -1,34 +0,0 @@ - - -
- {#each live as item (item.created_at)} -
{JSON.stringify(item)}
- {/each} -
\ No newline at end of file diff --git a/ceremony/src/lib/components/Reward.svelte b/ceremony/src/lib/components/Reward.svelte deleted file mode 100644 index cc847aae6d..0000000000 --- a/ceremony/src/lib/components/Reward.svelte +++ /dev/null @@ -1,30 +0,0 @@ - - -{#if showInput} -
-
- Enter address: -
- -
-{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/SwimLoad.svelte b/ceremony/src/lib/components/SwimLoad.svelte deleted file mode 100644 index 33acb00eea..0000000000 --- a/ceremony/src/lib/components/SwimLoad.svelte +++ /dev/null @@ -1,36 +0,0 @@ - - - -{queueBar} - {percentageText} - diff --git a/ceremony/src/lib/components/TerminalApp/Activity.svelte b/ceremony/src/lib/components/Terminal/Activity.svelte similarity index 95% rename from ceremony/src/lib/components/TerminalApp/Activity.svelte rename to ceremony/src/lib/components/Terminal/Activity.svelte index fe6b812d74..1fb032b4eb 100644 --- a/ceremony/src/lib/components/TerminalApp/Activity.svelte +++ b/ceremony/src/lib/components/Terminal/Activity.svelte @@ -1,6 +1,6 @@ + +{#if !redirecting} + + {#each providers as provider, index} + + {/each} + +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Ceremony.svelte b/ceremony/src/lib/components/Terminal/Ceremony.svelte new file mode 100644 index 0000000000..6f6ca2ee58 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Ceremony.svelte @@ -0,0 +1,54 @@ + + +{#if !contributor.userWallet} + + +{:else if contributor.contributionState === 'contributed'} + + +{:else if contributor.contributionState === 'verifying'} + {terminal.updateHistory("Verifying your contribution...")} + +{:else if contributor.contributionState === 'contribute'} + {terminal.updateHistory("Starting contribution...")} + +{:else if contributor.contributionState === "contribute"} + {terminal.updateHistory("Contributing...")} + +{:else if contributor.state === "inQueue"} + + +{:else if !contributor.downloadedSecret && client.state === "idle"} + + +{:else if client.state === 'noClient'} + + +{:else} + Loading... + +{/if} diff --git a/ceremony/src/lib/components/Terminal/Code.svelte b/ceremony/src/lib/components/Terminal/Code.svelte new file mode 100644 index 0000000000..a13794201c --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Code.svelte @@ -0,0 +1,68 @@ + + +{#if showInput} +
+
+ Enter code: +
+ +
+{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Contributors.svelte b/ceremony/src/lib/components/Terminal/Contributors.svelte similarity index 73% rename from ceremony/src/lib/components/TerminalApp/Contributors.svelte rename to ceremony/src/lib/components/Terminal/Contributors.svelte index 5067b529a1..f858ea0542 100644 --- a/ceremony/src/lib/components/TerminalApp/Contributors.svelte +++ b/ceremony/src/lib/components/Terminal/Contributors.svelte @@ -1,8 +1,8 @@ {#if contributions.data} diff --git a/ceremony/src/lib/components/Terminal/Install/Linux.svelte b/ceremony/src/lib/components/Terminal/Install/Linux.svelte new file mode 100644 index 0000000000..dc59f39c4f --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Install/Linux.svelte @@ -0,0 +1,115 @@ + + +{#if showButtons} + + + +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Install/MacOS.svelte b/ceremony/src/lib/components/Terminal/Install/MacOS.svelte new file mode 100644 index 0000000000..ae1b646011 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Install/MacOS.svelte @@ -0,0 +1,114 @@ + + +{#if showButtons} + + + +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte new file mode 100644 index 0000000000..f0a761fe9a --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte @@ -0,0 +1,61 @@ + + + +{#if showButtons} + {#each selections as os, index} + + {/each} +{/if} diff --git a/ceremony/src/lib/components/Terminal/Install/index.svelte b/ceremony/src/lib/components/Terminal/Install/index.svelte new file mode 100644 index 0000000000..c668a726c4 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Install/index.svelte @@ -0,0 +1,42 @@ + + +{#if !selectedOs} + + {:else if selectedOs === "macOS"} + + {:else if selectedOs === "Linux"} + +{/if} + diff --git a/ceremony/src/lib/components/Terminal/Join.svelte b/ceremony/src/lib/components/Terminal/Join.svelte new file mode 100644 index 0000000000..d69af3159d --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Join.svelte @@ -0,0 +1,98 @@ + + +{terminal.updateHistory("Access the ceremony")} + +{#if !selected} + + {#if code } + + {:else } + {#each buttons as button, index} + + {/each} + {/if} + +{/if} + + diff --git a/ceremony/src/lib/components/Terminal/LoadingBar.svelte b/ceremony/src/lib/components/Terminal/LoadingBar.svelte new file mode 100644 index 0000000000..5d5fc07521 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/LoadingBar.svelte @@ -0,0 +1,30 @@ + + + +{queueBar} - {percentageText} + diff --git a/ceremony/src/lib/components/Terminal/Print.svelte b/ceremony/src/lib/components/Terminal/Print.svelte new file mode 100644 index 0000000000..a339ac9f9e --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Print.svelte @@ -0,0 +1,11 @@ + + +

{@render children()}

\ No newline at end of file diff --git a/ceremony/src/lib/components/Queue.svelte b/ceremony/src/lib/components/Terminal/Queue.svelte similarity index 54% rename from ceremony/src/lib/components/Queue.svelte rename to ceremony/src/lib/components/Terminal/Queue.svelte index 650b12aa58..df14c7f3d5 100644 --- a/ceremony/src/lib/components/Queue.svelte +++ b/ceremony/src/lib/components/Terminal/Queue.svelte @@ -1,22 +1,17 @@ ------- Your position: {contributor.queueState.position ?? 33} Queue length: {contributor.queueState.count ?? 347} Estimated waiting time: {contributor.queueState.estimatedTime ?? 990} minutes diff --git a/ceremony/src/lib/components/Terminal/Reward.svelte b/ceremony/src/lib/components/Terminal/Reward.svelte new file mode 100644 index 0000000000..99cd6671a3 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Reward.svelte @@ -0,0 +1,28 @@ + + +{#if showInput} +
+
+ Enter address: +
+ +
+{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Secret.svelte b/ceremony/src/lib/components/Terminal/Secret.svelte new file mode 100644 index 0000000000..e8b30f7b36 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Secret.svelte @@ -0,0 +1,60 @@ + + +{#if !generating} + {#if !generated} + + {:else} + + + {/if} +{/if} diff --git a/ceremony/src/lib/components/Terminal/Thanks.svelte b/ceremony/src/lib/components/Terminal/Thanks.svelte new file mode 100644 index 0000000000..b6e39f1a03 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Thanks.svelte @@ -0,0 +1,90 @@ + + +{#if showButtons} + {#each buttons as btn, index} + + {/each} +{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Waitlist.svelte b/ceremony/src/lib/components/Terminal/Waitlist.svelte similarity index 68% rename from ceremony/src/lib/components/TerminalApp/Waitlist.svelte rename to ceremony/src/lib/components/Terminal/Waitlist.svelte index 1ab681a10d..b8f6fb3186 100644 --- a/ceremony/src/lib/components/TerminalApp/Waitlist.svelte +++ b/ceremony/src/lib/components/Terminal/Waitlist.svelte @@ -1,10 +1,9 @@ {terminal.updateHistory("You're on the waitlist")} diff --git a/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte b/ceremony/src/lib/components/Terminal/index.svelte similarity index 53% rename from ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte rename to ceremony/src/lib/components/Terminal/index.svelte index 585bce02a7..93ad428c94 100644 --- a/ceremony/src/lib/components/TerminalApp/TerminalWindow.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -1,73 +1,73 @@
diff --git a/ceremony/src/lib/components/TerminalApp/Authenticate.svelte b/ceremony/src/lib/components/TerminalApp/Authenticate.svelte deleted file mode 100644 index 84804c49ed..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Authenticate.svelte +++ /dev/null @@ -1,67 +0,0 @@ - - -{#if !redirecting} - - {#each providers as provider, index} - - {/each} - -{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Ceremony.svelte b/ceremony/src/lib/components/TerminalApp/Ceremony.svelte deleted file mode 100644 index ee3a95339d..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Ceremony.svelte +++ /dev/null @@ -1,64 +0,0 @@ - - -{#if !contributor.userWallet} - - -{:else if contributor.state === 'contributed'} - - -{:else if contributor.state === 'verifying'} - {terminal.updateHistory("Verifying your contribution...")} - -{:else if contributor.state !== "inQueue"} - - -{:else if contributor.state === 'contribute'} - {terminal.updateHistory("Starting contribution...")} - -{:else if contributor.state === 'contributing'} - {terminal.updateHistory("Contributing...")} - -{:else if !contributor.downloadedSecret && client.state === "idle"} - - -{:else if client.state === 'noClient'} - - -{:else} - Loading... - -{/if} diff --git a/ceremony/src/lib/components/TerminalApp/Install/Linux.svelte b/ceremony/src/lib/components/TerminalApp/Install/Linux.svelte deleted file mode 100644 index 1a1cccd8fa..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Install/Linux.svelte +++ /dev/null @@ -1,106 +0,0 @@ - - -{#if showButtons} - - - -{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Install/MacOS.svelte b/ceremony/src/lib/components/TerminalApp/Install/MacOS.svelte deleted file mode 100644 index b1f7f1ff6c..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Install/MacOS.svelte +++ /dev/null @@ -1,105 +0,0 @@ - - -{#if showButtons} - - - -{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/TerminalApp/Install/SelectOS.svelte b/ceremony/src/lib/components/TerminalApp/Install/SelectOS.svelte deleted file mode 100644 index 7751b1e8ef..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Install/SelectOS.svelte +++ /dev/null @@ -1,60 +0,0 @@ - - - -{#if showButtons} - {#each selections as os, index} - - {/each} -{/if} diff --git a/ceremony/src/lib/components/TerminalApp/Install/index.svelte b/ceremony/src/lib/components/TerminalApp/Install/index.svelte deleted file mode 100644 index 930d981d60..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Install/index.svelte +++ /dev/null @@ -1,43 +0,0 @@ - - -{#if !selectedOs} - - {:else if selectedOs === "macOS"} - - {:else if selectedOs === "Linux"} - -{/if} - diff --git a/ceremony/src/lib/components/TerminalApp/Join.svelte b/ceremony/src/lib/components/TerminalApp/Join.svelte deleted file mode 100644 index 3503b8ce90..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Join.svelte +++ /dev/null @@ -1,100 +0,0 @@ - - -{terminal.updateHistory("Access the ceremony")} - -{#if !selected} - - {#if code } - - {:else } - {#each buttons as button, index} - - {/each} - {/if} - -{/if} - - diff --git a/ceremony/src/lib/components/TerminalApp/Print.svelte b/ceremony/src/lib/components/TerminalApp/Print.svelte deleted file mode 100644 index 43b580a7c0..0000000000 --- a/ceremony/src/lib/components/TerminalApp/Print.svelte +++ /dev/null @@ -1,11 +0,0 @@ - - -

{@render children()}

\ No newline at end of file diff --git a/ceremony/src/lib/components/Thanks.svelte b/ceremony/src/lib/components/Thanks.svelte deleted file mode 100644 index 5f1d94a104..0000000000 --- a/ceremony/src/lib/components/Thanks.svelte +++ /dev/null @@ -1,89 +0,0 @@ - - -{#if showButtons} - {#each buttons as btn, index} - - {/each} -{/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Tweet.svelte b/ceremony/src/lib/components/Tweet.svelte deleted file mode 100644 index b7c2893d86..0000000000 --- a/ceremony/src/lib/components/Tweet.svelte +++ /dev/null @@ -1,26 +0,0 @@ - - - \ No newline at end of file diff --git a/ceremony/src/lib/components/Waitlist.svelte b/ceremony/src/lib/components/Waitlist.svelte deleted file mode 100644 index 60f7ab59f2..0000000000 --- a/ceremony/src/lib/components/Waitlist.svelte +++ /dev/null @@ -1,21 +0,0 @@ - - -You're on the waitlist -When the ceremony opens to the public, you will be {contributor.waitListPosition}{getNumberSuffix(contributor.waitListPosition)} in the public queue. -You will receive an email 12-18 hours before the public phase begins. -Received an invite? -You can skip the waitlist and join now. -
- - \ No newline at end of file diff --git a/ceremony/src/lib/components/Warning.svelte b/ceremony/src/lib/components/Warning.svelte deleted file mode 100644 index 9da0a17ccb..0000000000 --- a/ceremony/src/lib/components/Warning.svelte +++ /dev/null @@ -1,23 +0,0 @@ - - -
- {#if stupid} - Your MPC Client is connected. - Do not close this tab or your Terminal. - {/if} - - Ensure you have a reliable internet connection
and that your computer does - not go to sleep. -
-
\ No newline at end of file diff --git a/ceremony/src/lib/components/address/AddressForm.svelte b/ceremony/src/lib/components/address/AddressForm.svelte index 9efd15926a..2856195bf9 100644 --- a/ceremony/src/lib/components/address/AddressForm.svelte +++ b/ceremony/src/lib/components/address/AddressForm.svelte @@ -1,98 +1,97 @@
diff --git a/ceremony/src/lib/state/client.svelte.ts b/ceremony/src/lib/state/client.svelte.ts index 7a5d9afc77..b3247326e6 100644 --- a/ceremony/src/lib/state/client.svelte.ts +++ b/ceremony/src/lib/state/client.svelte.ts @@ -1,5 +1,5 @@ import { checkState, start } from "$lib/client" -import type {ClientStatus} from "$lib/client/types.ts"; +import type { ClientStatus } from "$lib/client/types.ts" type ClientState = undefined | "contributing" | "error" | "noClient" | "successful" | "idle" @@ -32,10 +32,7 @@ export class Client { startPolling(): void { if (!this.isPolling) { - this.pollingInterval = setInterval( - () => this.checkStatus(), - CLIENT_POLLING_INTERVAL - ) + this.pollingInterval = setInterval(() => this.checkStatus(), CLIENT_POLLING_INTERVAL) this.isPolling = true } } @@ -74,5 +71,4 @@ export class Client { break } } - -} \ No newline at end of file +} diff --git a/ceremony/src/lib/state/contributor.svelte.ts b/ceremony/src/lib/state/contributor.svelte.ts index 187f12dc26..979a53e098 100644 --- a/ceremony/src/lib/state/contributor.svelte.ts +++ b/ceremony/src/lib/state/contributor.svelte.ts @@ -4,7 +4,8 @@ import { getUserQueueInfo, getContributionState, getUserWallet, - getWaitListPosition, checkIfOpen + getWaitListPosition, + checkIfOpen } from "$lib/supabase" type IntervalID = NodeJS.Timeout | number @@ -161,7 +162,6 @@ export class Contributor { } } - private startQueueInfoPolling() { this.pollQueueInfo() this.pollIntervals.queue = setInterval( @@ -212,7 +212,6 @@ export class Contributor { } } - private updateQueueInfo(queueInfo: QueueInfoResult) { if (queueInfo.inQueue) { this.queueState = { diff --git a/ceremony/src/lib/state/session.svelte.ts b/ceremony/src/lib/state/session.svelte.ts index 49a025633a..14a1f3c7ae 100644 --- a/ceremony/src/lib/state/session.svelte.ts +++ b/ceremony/src/lib/state/session.svelte.ts @@ -1,9 +1,8 @@ -import type {Session} from "@supabase/supabase-js" -import {supabase} from "$lib/supabase/client.ts" -import {err, ok, type Result} from "neverthrow" -import {invalidateAll} from "$app/navigation" -import type {Terminal} from "$lib/state/terminal.svelte.ts" - +import type { Session } from "@supabase/supabase-js" +import { supabase } from "$lib/supabase/client.ts" +import { err, ok, type Result } from "neverthrow" +import { invalidateAll } from "$app/navigation" +import type { Terminal } from "$lib/state/terminal.svelte.ts" export type SessionError = { message: string @@ -14,46 +13,46 @@ export type UserSession = { loading: boolean } -export let user = $state({session: null, loading: true}) +export let user = $state({ session: null, loading: true }) export async function checkAuth(): Promise> { const { - data: {session}, + data: { session }, error } = await supabase.auth.getSession() if (error || !session) { - user.session = null; - user.loading = false; - return err({message: "User not authenticated"}) + user.session = null + user.loading = false + return err({ message: "User not authenticated" }) } - user.session = session; - user.loading = false; + user.session = session + user.loading = false return ok(null) } export async function logout(terminal: Terminal): Promise { if (!user.session) { - console.log('user already logged out'); - return; + console.log("user already logged out") + return } - terminal.updateHistory("logging out user..."); + terminal.updateHistory("logging out user...") try { - terminal.setHash(undefined); - terminal.setTab(1); + terminal.setHash(undefined) + terminal.setTab(1) - terminal.updateHistory("user successfully logged out"); - const {error} = await supabase.auth.signOut(); + terminal.updateHistory("user successfully logged out") + const { error } = await supabase.auth.signOut() - user.session = null; + user.session = null - await invalidateAll(); + await invalidateAll() } catch (error) { - terminal.updateHistory(`error logging out`); + terminal.updateHistory(`error logging out`) - terminal.setHash(undefined); - terminal.setTab(1); - user.session = null; + terminal.setHash(undefined) + terminal.setTab(1) + user.session = null } } diff --git a/ceremony/src/lib/state/terminal.svelte.ts b/ceremony/src/lib/state/terminal.svelte.ts index 6034f4267e..c4a71c68f6 100644 --- a/ceremony/src/lib/state/terminal.svelte.ts +++ b/ceremony/src/lib/state/terminal.svelte.ts @@ -1,66 +1,67 @@ import { getContext, setContext } from "svelte" -import { readable } from 'svelte/store'; +import { readable } from "svelte/store" export type AuthProviders = "github" | "google" export type State = "hasRedeemed" | "inQueue" | "inWaitlist" | "join" | undefined interface UpdateHistoryOptions { - duplicate?: boolean; - replace?: boolean; + duplicate?: boolean + replace?: boolean } export type KeyEvent = { - key: string; - type: 'keydown' | 'keyup'; - shiftKey: boolean; - ctrlKey: boolean; -}; + key: string + type: "keydown" | "keyup" + shiftKey: boolean + ctrlKey: boolean +} export class Terminal { state = $state(undefined) history = $state>([]) tab = $state<1 | 2 | 3 | number>(1) hash = $state(undefined) + contribution = $state(undefined) - keys = readable(null, (set) => { + keys = readable(null, set => { const handleKeyEvent = (event: KeyboardEvent) => { set({ key: event.key, - type: event.type as 'keydown' | 'keyup', + type: event.type as "keydown" | "keyup", shiftKey: event.shiftKey, ctrlKey: event.ctrlKey - }); - }; + }) + } - if (typeof window !== 'undefined') { - window.addEventListener('keydown', handleKeyEvent); - window.addEventListener('keyup', handleKeyEvent); + if (typeof window !== "undefined") { + window.addEventListener("keydown", handleKeyEvent) + window.addEventListener("keyup", handleKeyEvent) } return () => { - if (typeof window !== 'undefined') { - window.removeEventListener('keydown', handleKeyEvent); - window.removeEventListener('keyup', handleKeyEvent); + if (typeof window !== "undefined") { + window.removeEventListener("keydown", handleKeyEvent) + window.removeEventListener("keyup", handleKeyEvent) } - }; - }); + } + }) constructor() { console.log("Creating terminal state") } updateHistory(text: string, options: UpdateHistoryOptions = {}) { - const { duplicate = false, replace = false } = options; + const { duplicate = false, replace = false } = options - const index = this.history.indexOf(text); + const index = this.history.indexOf(text) if (duplicate) { - this.history.push(text); + this.history.push(text) } else if (replace && index !== -1) { - this.history.splice(index, 1); - this.history.push(text); + this.history.splice(index, 1) + this.history.push(text) } else if (!this.history.includes(text)) { - this.history.push(text); + this.history.push(text) } } @@ -72,6 +73,10 @@ export class Terminal { this.hash = hash } + setContribution(contribution: any) { + this.contribution = contribution + } + private updateState() {} } @@ -83,4 +88,4 @@ export function setTerminal() { export function getTerminal(): Terminal { return getContext(TERMINAL_KEY) -} \ No newline at end of file +} diff --git a/ceremony/src/lib/stores/auth.svelte.ts b/ceremony/src/lib/stores/auth.svelte.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index d8a10fa9b6..346d97fd99 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -13,6 +13,7 @@ import { } from "$lib/supabase/queries.ts" import { supabase } from "$lib/supabase/client.ts" import type { AllowanceState, ContributionState } from "$lib/stores/state.svelte.ts" +import { sleep } from "$lib/utils/utils.ts" export const callJoinQueue = async (code: string | null): Promise => { if (!user.session) { @@ -120,12 +121,11 @@ export const getCurrentUserState = async (userId: string | undefined): Promise { @@ -136,6 +136,7 @@ export const getContributions = async () => { } export const getUserContribution = async (hash: string) => { + await sleep(500) const { data, error } = await queryUserContribution(hash) if (error || !data) return undefined diff --git a/ceremony/src/lib/utils/utils.ts b/ceremony/src/lib/utils/utils.ts index 1c1c118403..c31ca54b35 100644 --- a/ceremony/src/lib/utils/utils.ts +++ b/ceremony/src/lib/utils/utils.ts @@ -33,7 +33,7 @@ export function isSafari(): boolean { } export function sleep(ms: number): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise(resolve => setTimeout(resolve, ms)) } export async function detectOS(): Promise { @@ -73,4 +73,4 @@ export async function detectOS(): Promise { return "Unknown" } -export type DetectedOS = "Linux" | "macOS" | "Windows" | "Unknown" \ No newline at end of file +export type DetectedOS = "Linux" | "macOS" | "Windows" | "Unknown" diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index cdade9ec74..cb6ba23f28 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -1,15 +1,15 @@
- + {@render children()} - +
\ No newline at end of file diff --git a/ceremony/src/routes/+layout.ts b/ceremony/src/routes/+layout.ts index 3c29a22969..1d17ade893 100644 --- a/ceremony/src/routes/+layout.ts +++ b/ceremony/src/routes/+layout.ts @@ -1,6 +1,6 @@ -import {checkAuth, type SessionError} from "$lib/state/session.svelte.ts"; -import type {LayoutLoad} from "../../.svelte-kit/types/src/routes/$types"; -import {redirect} from "@sveltejs/kit"; +import { checkAuth, type SessionError } from "$lib/state/session.svelte.ts" +import type { LayoutLoad } from "../../.svelte-kit/types/src/routes/$types.ts" +import { redirect } from "@sveltejs/kit" export const ssr = false export const prerender = true diff --git a/ceremony/src/routes/+page.svelte b/ceremony/src/routes/+page.svelte index 6d33312394..610621e773 100644 --- a/ceremony/src/routes/+page.svelte +++ b/ceremony/src/routes/+page.svelte @@ -1,21 +1,20 @@ -{terminal.updateHistory("Welcome to union ceremony")} - {#if user.loading} loading... {:else} diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index f7c6b62bc0..321924d41b 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -1,43 +1,43 @@ @@ -75,17 +75,13 @@ Loading {:then contribution} {#if contribution} - {hash} - Public key
{decodeHexString(contribution.public_key)}
- Signature
{decodeHexString(contribution.signature)}
{/if} {/await} From 8cab55a37cd1675aea530540e5e138d313c4b7a1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 01:24:30 +0200 Subject: [PATCH 06/40] feat(ceremony): save progress --- ceremony/src/lib/components/Blink.svelte | 4 +- ceremony/src/lib/components/Circles.svelte | 68 ++++++++ .../src/lib/components/Terminal/Print.svelte | 2 +- .../src/lib/components/Terminal/index.svelte | 158 ++++++++++-------- ceremony/src/routes/+layout.svelte | 6 +- 5 files changed, 164 insertions(+), 74 deletions(-) create mode 100644 ceremony/src/lib/components/Circles.svelte diff --git a/ceremony/src/lib/components/Blink.svelte b/ceremony/src/lib/components/Blink.svelte index 07fbb95079..e5ddf48cc7 100644 --- a/ceremony/src/lib/components/Blink.svelte +++ b/ceremony/src/lib/components/Blink.svelte @@ -21,7 +21,7 @@ function blinkEye() { function startRandomBlinking() { blinkInterval = setInterval(() => { - if (!(sleep || love) && Math.random() < 0.05) { + if (!(sleep || love) && Math.random() < 0.08) { blinkEye() } }, 200) @@ -45,7 +45,7 @@ $effect(() => { }) - + {eye}_______{eye} diff --git a/ceremony/src/lib/components/Circles.svelte b/ceremony/src/lib/components/Circles.svelte new file mode 100644 index 0000000000..d5e70eb5b6 --- /dev/null +++ b/ceremony/src/lib/components/Circles.svelte @@ -0,0 +1,68 @@ +
+
+ + + + + + +
+
+ + \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Print.svelte b/ceremony/src/lib/components/Terminal/Print.svelte index a339ac9f9e..0973913c54 100644 --- a/ceremony/src/lib/components/Terminal/Print.svelte +++ b/ceremony/src/lib/components/Terminal/Print.svelte @@ -8,4 +8,4 @@ type Props = HTMLAttributes & { let { children, class: className = "", ...rest }: Props = $props() -

{@render children()}

\ No newline at end of file +

{@render children()}

\ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 93ad428c94..8210863118 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -1,91 +1,111 @@ -
-
-
-
- - - {#if terminal.hash !== undefined} - {/if}
- +
-
+
{#if terminal.tab === 1}
diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index cb6ba23f28..f4c58e2267 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -6,6 +6,7 @@ import "../styles/tailwind.css" import { watch } from "runed" import { checkAuth } from "$lib/state/session.svelte.ts" import Terminal from "$lib/components/Terminal/index.svelte" +import Circles from "$lib/components/Circles.svelte"; let { children } = $props() @@ -30,8 +31,9 @@ watch( ) -
+
{@render children()} -
\ No newline at end of file +
+ \ No newline at end of file From 96ce1b2f692866a35a46a89cdd1e8cfdcacc1a77 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 01:29:43 +0200 Subject: [PATCH 07/40] feat(ceremony): save progress --- ceremony/src/lib/components/Terminal/index.svelte | 13 +++++++------ ceremony/src/routes/+layout.svelte | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 8210863118..746c49a7e2 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -71,9 +71,11 @@ } -
-
-
+
+ +
+ +
logout(terminal)}>Log out
-
- +
{#if terminal.tab === 1}
{#each terminal.history as text} @@ -133,8 +134,8 @@ {:else if terminal.tab === 4 && terminal.hash} {@render children()} {/if} -
+
diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index f4c58e2267..744839c2ae 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -36,4 +36,3 @@ watch( {@render children()}
- \ No newline at end of file From 5046293d52dc4b718e29a28ad21c831dcb1ce8c1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 01:37:22 +0200 Subject: [PATCH 08/40] feat(ceremony): save terminal progress --- .../src/lib/components/Terminal/index.svelte | 112 +++++++++--------- ceremony/src/lib/state/contributor.svelte.ts | 32 +++-- ceremony/src/lib/supabase/index.ts | 2 +- ceremony/src/routes/+layout.svelte | 2 +- 4 files changed, 79 insertions(+), 69 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 746c49a7e2..98c2eba61d 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -1,74 +1,74 @@
diff --git a/ceremony/src/lib/state/contributor.svelte.ts b/ceremony/src/lib/state/contributor.svelte.ts index 979a53e098..2067022c03 100644 --- a/ceremony/src/lib/state/contributor.svelte.ts +++ b/ceremony/src/lib/state/contributor.svelte.ts @@ -4,8 +4,7 @@ import { getUserQueueInfo, getContributionState, getUserWallet, - getWaitListPosition, - checkIfOpen + getWaitListPosition } from "$lib/supabase" type IntervalID = NodeJS.Timeout | number @@ -22,6 +21,7 @@ type State = | "noClient" export type AllowanceState = "hasRedeemed" | "inWaitlist" | "inQueue" | "join" | undefined + export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed" interface UserContext { @@ -45,6 +45,7 @@ interface QueueInfoError { type QueueInfoResult = QueueInfoSuccess | QueueInfoError const second = 1000 +const CLIENT_POLING_INTERVAL = second const CONTRIBUTION_POLLING_INTERVAL = second * 5 const QUEUE_POLLING_INTERVAL = second * 5 @@ -55,12 +56,10 @@ export class Contributor { pollingState = $state<"stopped" | "polling">("stopped") state = $state("loading") - openToPublic = $state(false) contributionState = $state("notContributed") userWallet = $state("") waitListPosition = $state(undefined) downloadedSecret = $state(localStorage.getItem("downloaded-secret") === "true") - queueState = $state({ position: null, count: null, @@ -69,11 +68,9 @@ export class Contributor { }) private pollIntervals: { - client: IntervalID | null queue: IntervalID | null contribution: IntervalID | null } = { - client: null, queue: null, contribution: null } @@ -83,7 +80,6 @@ export class Contributor { this.userId = userId this.loggedIn = true this.checkCurrentUserState(userId) - this.checkIfOpen() this.startPolling() } onDestroy(() => { @@ -102,10 +98,6 @@ export class Contributor { } } - async checkIfOpen() { - this.openToPublic = await checkIfOpen() - } - async checkWaitListPosition(_userId: string | undefined): Promise { this.waitListPosition = await getWaitListPosition() return this.waitListPosition @@ -155,6 +147,7 @@ export class Contributor { this.stopContributionStatePolling() } + private stopClientStatePolling() { if (this.pollIntervals.client) { clearInterval(this.pollIntervals.client) @@ -162,6 +155,7 @@ export class Contributor { } } + private startQueueInfoPolling() { this.pollQueueInfo() this.pollIntervals.queue = setInterval( @@ -212,6 +206,7 @@ export class Contributor { } } + private updateQueueInfo(queueInfo: QueueInfoResult) { if (queueInfo.inQueue) { this.queueState = { @@ -228,16 +223,31 @@ export class Contributor { estimatedTime: null } } + this.updateState() } private updateContributionState(state: ContributionState) { this.contributionState = state + this.updateState() } private setError(message: string) { this.queueState = { ...this.queueState, error: message } this.state = "error" } + + private updateState() { + if (this.contributionState === "contribute") { + } else if (this.queueState.position !== null) { + this.state = "inQueue" + } else if (this.contributionState === "contributed") { + this.state = "contributed" + } else if (this.contributionState === "verifying") { + this.state = "verifying" + } else { + this.state = "loading" + } + } } const CONTRIBUTOR_KEY = Symbol("CONTRIBUTOR") diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index 346d97fd99..fc0295fe2f 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -121,11 +121,11 @@ export const getCurrentUserState = async (userId: string | undefined): Promise { diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index 744839c2ae..45e84b51d1 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -6,7 +6,7 @@ import "../styles/tailwind.css" import { watch } from "runed" import { checkAuth } from "$lib/state/session.svelte.ts" import Terminal from "$lib/components/Terminal/index.svelte" -import Circles from "$lib/components/Circles.svelte"; +import Circles from "$lib/components/Circles.svelte" let { children } = $props() From de496ae751701fddb3640e63cfb5f37c31309983 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 01:48:16 +0200 Subject: [PATCH 09/40] feat(ceremony): save terminal progress --- .../components/Terminal/Contributors.svelte | 27 ++++++---------- .../Terminal/Install/SelectOS.svelte | 19 +++++------- .../src/lib/components/Terminal/Thanks.svelte | 16 ++++------ .../src/lib/components/Terminal/index.svelte | 31 ++++++------------- ceremony/src/lib/state/contributor.svelte.ts | 12 +------ ceremony/src/lib/state/terminal.svelte.ts | 2 -- ceremony/src/lib/supabase/index.ts | 2 +- .../src/routes/0____0/[hash]/+page.svelte | 2 +- 8 files changed, 36 insertions(+), 75 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/Contributors.svelte b/ceremony/src/lib/components/Terminal/Contributors.svelte index f858ea0542..dac9439e79 100644 --- a/ceremony/src/lib/components/Terminal/Contributors.svelte +++ b/ceremony/src/lib/components/Terminal/Contributors.svelte @@ -27,23 +27,16 @@ onMount(() => { unsubscribe = terminal.keys.subscribe(event => { if (event) { if (event.type === "keydown") { - switch (event.key) { - case "ArrowUp": { - selectedIndex = - (selectedIndex - 1 + contributions.data.length) % contributions.data.length - buttons[selectedIndex]?.focus() - break - } - case "ArrowDown": { - selectedIndex = (selectedIndex + 1) % contributions.data.length - buttons[selectedIndex]?.focus() - break - } - case "Enter": { - if (buttons[selectedIndex]) { - fireEvent(contributions.data[selectedIndex]) - } - break + if (event.key === "ArrowUp") { + selectedIndex = + (selectedIndex - 1 + contributions.data.length) % contributions.data.length + buttons[selectedIndex]?.focus() + } else if (event.key === "ArrowDown") { + selectedIndex = (selectedIndex + 1) % contributions.data.length + buttons[selectedIndex]?.focus() + } else if (event.key === "Enter") { + if (buttons[selectedIndex]) { + fireEvent(contributions.data[selectedIndex]) } } } diff --git a/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte index f0a761fe9a..a567f55f3c 100644 --- a/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte +++ b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte @@ -22,18 +22,13 @@ onMount(() => { function handleKeyDown(event: KeyEvent) { if (event.type === "keydown") { - switch (event.key) { - case "ArrowUp": - currentFocusIndex = (currentFocusIndex - 1 + selections.length) % selections.length - break - case "ArrowDown": - currentFocusIndex = (currentFocusIndex + 1) % selections.length - break - case "Enter": { - showButtons = false - select(selections[currentFocusIndex]) - break - } + if (event.key === "ArrowUp") { + currentFocusIndex = (currentFocusIndex - 1 + selections.length) % selections.length + } else if (event.key === "ArrowDown") { + currentFocusIndex = (currentFocusIndex + 1) % selections.length + } else if (event.key === "Enter") { + showButtons = false + select(selections[currentFocusIndex]) } } } diff --git a/ceremony/src/lib/components/Terminal/Thanks.svelte b/ceremony/src/lib/components/Terminal/Thanks.svelte index b6e39f1a03..47cdb4399e 100644 --- a/ceremony/src/lib/components/Terminal/Thanks.svelte +++ b/ceremony/src/lib/components/Terminal/Thanks.svelte @@ -28,16 +28,12 @@ onMount(() => { unsubscribe = terminal.keys.subscribe(event => { if (event) { if (event.type === "keydown" && terminal.tab === 1) { - switch (event.key) { - case "ArrowUp": - selectedButton = (selectedButton - 1 + buttons.length) % buttons.length - break - case "ArrowDown": - selectedButton = (selectedButton + 1) % buttons.length - break - case "Enter": - triggerAction(selectedButton) - break + if (event.key === "ArrowUp") { + selectedButton = (selectedButton - 1 + buttons.length) % buttons.length + } else if (event.key === "ArrowDown") { + selectedButton = (selectedButton + 1) % buttons.length + } else if (event.key === "Enter") { + triggerAction(selectedButton) } } } diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 98c2eba61d..344d91a7d8 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -27,27 +27,16 @@ const changeTab = async (tab: number) => { const unsubscribe = terminal.keys.subscribe(event => { if (event) { if (event.type === "keydown" && (event.shiftKey || event.ctrlKey)) { - switch (event.key) { - case "!": { - changeTab(1) - break - } - case "@": { - changeTab(2) - break - } - case "#": { - changeTab(3) - break - } - case "$": { - changeTab(4) - break - } - case "X": { - logout(terminal) - break - } + if (event.key === "!") { + changeTab(1) + } else if (event.key === "@") { + changeTab(2) + } else if (event.key === "#") { + changeTab(3) + } else if (event.key === "$") { + changeTab(4) + } else if (event.key === "X") { + logout(terminal) } } } diff --git a/ceremony/src/lib/state/contributor.svelte.ts b/ceremony/src/lib/state/contributor.svelte.ts index 2067022c03..81aa265370 100644 --- a/ceremony/src/lib/state/contributor.svelte.ts +++ b/ceremony/src/lib/state/contributor.svelte.ts @@ -142,20 +142,10 @@ export class Contributor { } this.pollingState = "stopped" - this.stopClientStatePolling() this.stopQueueInfoPolling() this.stopContributionStatePolling() } - - private stopClientStatePolling() { - if (this.pollIntervals.client) { - clearInterval(this.pollIntervals.client) - this.pollIntervals.client = null - } - } - - private startQueueInfoPolling() { this.pollQueueInfo() this.pollIntervals.queue = setInterval( @@ -206,7 +196,6 @@ export class Contributor { } } - private updateQueueInfo(queueInfo: QueueInfoResult) { if (queueInfo.inQueue) { this.queueState = { @@ -238,6 +227,7 @@ export class Contributor { private updateState() { if (this.contributionState === "contribute") { + this.state = "contribute" } else if (this.queueState.position !== null) { this.state = "inQueue" } else if (this.contributionState === "contributed") { diff --git a/ceremony/src/lib/state/terminal.svelte.ts b/ceremony/src/lib/state/terminal.svelte.ts index c4a71c68f6..dd126dfe6d 100644 --- a/ceremony/src/lib/state/terminal.svelte.ts +++ b/ceremony/src/lib/state/terminal.svelte.ts @@ -76,8 +76,6 @@ export class Terminal { setContribution(contribution: any) { this.contribution = contribution } - - private updateState() {} } const TERMINAL_KEY = Symbol("TERMINAL") diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index fc0295fe2f..346d97fd99 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -121,11 +121,11 @@ export const getCurrentUserState = async (userId: string | undefined): Promise { diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index 321924d41b..22d108b5a9 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -10,7 +10,7 @@ const { terminal } = getState() let hash = $derived($page.params.hash) -onMount(async () => { +onMount(() => { terminal.setTab(4) terminal.setHash(hash) }) From e38365655f92eb0e69bceb42cb842c144046890d Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 11:39:12 +0200 Subject: [PATCH 10/40] feat(ceremony): save terminal progress --- .../components/Terminal/Authenticate.svelte | 12 +- .../src/lib/components/Terminal/Button.svelte | 10 + .../lib/components/Terminal/Ceremony.svelte | 2 + .../components/Terminal/Contributors.svelte | 18 +- .../components/Terminal/Install/Linux.svelte | 175 +++++++++--------- .../components/Terminal/Install/MacOS.svelte | 21 +-- .../Terminal/Install/SelectOS.svelte | 10 +- .../src/lib/components/Terminal/Join.svelte | 12 +- .../src/lib/components/Terminal/Print.svelte | 2 +- .../src/lib/components/Terminal/Secret.svelte | 9 +- .../src/lib/components/Terminal/Thanks.svelte | 10 +- .../lib/components/Terminal/Waitlist.svelte | 12 +- .../src/lib/components/Terminal/index.svelte | 174 ++++++++--------- ceremony/src/lib/utils/utils.ts | 3 + .../src/routes/0____0/[hash]/+page.svelte | 4 +- 15 files changed, 242 insertions(+), 232 deletions(-) create mode 100644 ceremony/src/lib/components/Terminal/Button.svelte diff --git a/ceremony/src/lib/components/Terminal/Authenticate.svelte b/ceremony/src/lib/components/Terminal/Authenticate.svelte index 4a4770b843..c9015e9e23 100644 --- a/ceremony/src/lib/components/Terminal/Authenticate.svelte +++ b/ceremony/src/lib/components/Terminal/Authenticate.svelte @@ -2,6 +2,9 @@ import { type AuthProviders, type KeyEvent, Terminal } from "$lib/state/terminal.svelte.ts" import { supabase } from "$lib/supabase/client.ts" import { onDestroy, onMount } from "svelte" +import Button from "$lib/components/Terminal/Button.svelte"; +import clsx from "clsx"; +import {cn} from "$lib/utils/utils.ts"; type Props = { terminal: Terminal @@ -53,14 +56,13 @@ onDestroy(unsubscribe) {#if !redirecting} {#each providers as provider, index} - + {/each} {/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Button.svelte b/ceremony/src/lib/components/Terminal/Button.svelte new file mode 100644 index 0000000000..a8fc0dd760 --- /dev/null +++ b/ceremony/src/lib/components/Terminal/Button.svelte @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Ceremony.svelte b/ceremony/src/lib/components/Terminal/Ceremony.svelte index 6f6ca2ee58..cd9a4031b0 100644 --- a/ceremony/src/lib/components/Terminal/Ceremony.svelte +++ b/ceremony/src/lib/components/Terminal/Ceremony.svelte @@ -35,6 +35,8 @@ $effect(() => { {:else if contributor.contributionState === 'contribute'} {terminal.updateHistory("Starting contribution...")} + Not starting? + {:else if contributor.contributionState === "contribute"} {terminal.updateHistory("Contributing...")} diff --git a/ceremony/src/lib/components/Terminal/Contributors.svelte b/ceremony/src/lib/components/Terminal/Contributors.svelte index dac9439e79..f5d9102129 100644 --- a/ceremony/src/lib/components/Terminal/Contributors.svelte +++ b/ceremony/src/lib/components/Terminal/Contributors.svelte @@ -3,20 +3,22 @@ import { getState } from "$lib/state/index.svelte.ts" import { onMount } from "svelte" import { goto } from "$app/navigation" import Print from "$lib/components/Terminal/Print.svelte" +import {cn} from "$lib/utils/utils.ts"; +import Button from "$lib/components/Terminal/Button.svelte"; const { contributions, terminal } = getState() let selectedIndex = $state(0) let buttons: Array = [] -function fireEvent(contributor: any) { +function handleClick(contributor: any) { console.log("selected contributor:", contributor) goto(`/0____0/${contributor.public_key_hash}`) terminal.setTab(4) terminal.setHash(contributor.public_key_hash) } -onMount(() => { +$effect(() => { buttons[0].focus() }) @@ -36,7 +38,7 @@ onMount(() => { buttons[selectedIndex]?.focus() } else if (event.key === "Enter") { if (buttons[selectedIndex]) { - fireEvent(contributions.data[selectedIndex]) + handleClick(contributions.data[selectedIndex]) } } } @@ -57,12 +59,12 @@ onMount(() => { {#if contributions.data} ceremony contributors {#each contributions.data as contributor, index} - + {/each} {/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Install/Linux.svelte b/ceremony/src/lib/components/Terminal/Install/Linux.svelte index dc59f39c4f..7cfde65351 100644 --- a/ceremony/src/lib/components/Terminal/Install/Linux.svelte +++ b/ceremony/src/lib/components/Terminal/Install/Linux.svelte @@ -1,115 +1,114 @@ {#if showButtons} - - + {/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Install/MacOS.svelte b/ceremony/src/lib/components/Terminal/Install/MacOS.svelte index ae1b646011..e3219438f9 100644 --- a/ceremony/src/lib/components/Terminal/Install/MacOS.svelte +++ b/ceremony/src/lib/components/Terminal/Install/MacOS.svelte @@ -1,7 +1,8 @@ {#if showButtons} - - + {/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte index a567f55f3c..07ee91e214 100644 --- a/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte +++ b/ceremony/src/lib/components/Terminal/Install/SelectOS.svelte @@ -1,8 +1,9 @@ -

{@render children()}

\ No newline at end of file +

{@render children()}

\ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Secret.svelte b/ceremony/src/lib/components/Terminal/Secret.svelte index e8b30f7b36..4445366708 100644 --- a/ceremony/src/lib/components/Terminal/Secret.svelte +++ b/ceremony/src/lib/components/Terminal/Secret.svelte @@ -2,6 +2,7 @@ import { getState } from "$lib/state/index.svelte.ts" import { sleep } from "$lib/utils/utils.ts" import { generateSecret, start } from "$lib/client" +import Button from "$lib/components/Terminal/Button.svelte"; const { client, contributor, terminal, user } = getState() @@ -50,11 +51,11 @@ $effect(() => { {#if !generating} {#if !generated} - + {:else} - - + + {/if} {/if} diff --git a/ceremony/src/lib/components/Terminal/Thanks.svelte b/ceremony/src/lib/components/Terminal/Thanks.svelte index 47cdb4399e..2319a88b56 100644 --- a/ceremony/src/lib/components/Terminal/Thanks.svelte +++ b/ceremony/src/lib/components/Terminal/Thanks.svelte @@ -2,9 +2,10 @@ import { getPublicHash } from "$lib/supabase" import { getState } from "$lib/state/index.svelte.ts" import type { KeyEvent } from "$lib/state/terminal.svelte.ts" -import { sleep } from "$lib/utils/utils.ts" +import {cn, sleep} from "$lib/utils/utils.ts" import { onMount } from "svelte" import { beforeNavigate } from "$app/navigation" +import Button from "$lib/components/Terminal/Button.svelte"; const { terminal } = getState() @@ -75,12 +76,11 @@ function triggerAction(index: number) { {#if showButtons} {#each buttons as btn, index} - + {/each} {/if} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Waitlist.svelte b/ceremony/src/lib/components/Terminal/Waitlist.svelte index b8f6fb3186..b654b213d9 100644 --- a/ceremony/src/lib/components/Terminal/Waitlist.svelte +++ b/ceremony/src/lib/components/Terminal/Waitlist.svelte @@ -2,12 +2,16 @@ import { getNumberSuffix } from "$lib/utils/utils.ts" import { getState } from "$lib/state/index.svelte.ts" import Code from "$lib/components/Terminal/Code.svelte" +import {onMount} from "svelte"; const { contributor, terminal } = getState() + +onMount(() => { + terminal.updateHistory("You're on the waitlist") + terminal.updateHistory(`When the ceremony opens to the public, you will be ${contributor.waitListPosition}${getNumberSuffix(contributor.waitListPosition)} in the public queue.`) + terminal.updateHistory("You will receive an email 12-18 hours before the public phase begins.") + terminal.updateHistory("Received an invite? You can skip the waitlist and join now.") +}) -{terminal.updateHistory("You're on the waitlist")} -{terminal.updateHistory(`When the ceremony opens to the public, you will be ${contributor.waitListPosition}${getNumberSuffix(contributor.waitListPosition)} in the public queue.`)} -{terminal.updateHistory("You will receive an email 12-18 hours before the public phase begins.")} -{terminal.updateHistory("Received an invite? You can skip the waitlist and join now.")} diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 344d91a7d8..b0889ec2fd 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -1,114 +1,103 @@ -
-
+
+
+
+ + + + + + -
-
- - - - - - - - - - - {#if terminal.hash !== undefined} - - {/if} -
- + + + + {#if terminal.hash !== undefined} + + {/if}
+ +
-
+
+
{#if terminal.tab === 1}
{#each terminal.history as text} @@ -124,7 +113,6 @@ function autoScroll(node: HTMLElement) { {@render children()} {/if}
-
+
-
diff --git a/ceremony/src/lib/utils/utils.ts b/ceremony/src/lib/utils/utils.ts index c31ca54b35..6ef677ee1c 100644 --- a/ceremony/src/lib/utils/utils.ts +++ b/ceremony/src/lib/utils/utils.ts @@ -1,5 +1,8 @@ import { browser } from "$app/environment" +import { twMerge } from "tailwind-merge" +import { type ClassValue, clsx } from "clsx" +export const cn = (...inputs: Array) => twMerge(clsx(inputs)) export function getNumberSuffix(n: number | null): string { if (n == null) return "" diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index 22d108b5a9..471ea974ce 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -75,8 +75,8 @@ const imagePath = "https://ceremony.union.build/images/ceremony.png" Loading {:then contribution} {#if contribution} -
{decodeHexString(contribution.public_key)}
-
{decodeHexString(contribution.signature)}
+
{decodeHexString(contribution.public_key)}
+
{decodeHexString(contribution.signature)}
From 16f78d9811462d3d19e575a4df8f8184001365e5 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 11:52:05 +0200 Subject: [PATCH 11/40] feat(ceremony): save terminal progress --- .../components/Terminal/Authenticate.svelte | 12 +- .../src/lib/components/Terminal/Button.svelte | 2 +- .../components/Terminal/Contributors.svelte | 4 +- .../components/Terminal/Install/Linux.svelte | 158 +++++++++--------- .../components/Terminal/Install/MacOS.svelte | 4 +- .../Terminal/Install/SelectOS.svelte | 4 +- .../src/lib/components/Terminal/Join.svelte | 4 +- .../src/lib/components/Terminal/Print.svelte | 2 +- .../src/lib/components/Terminal/Secret.svelte | 4 +- .../src/lib/components/Terminal/Thanks.svelte | 10 +- .../lib/components/Terminal/Waitlist.svelte | 6 +- .../src/lib/components/Terminal/index.svelte | 95 ++++++----- 12 files changed, 155 insertions(+), 150 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/Authenticate.svelte b/ceremony/src/lib/components/Terminal/Authenticate.svelte index c9015e9e23..9055f02f01 100644 --- a/ceremony/src/lib/components/Terminal/Authenticate.svelte +++ b/ceremony/src/lib/components/Terminal/Authenticate.svelte @@ -1,10 +1,9 @@ - {/each} -{/if} \ No newline at end of file + {/each} \ No newline at end of file diff --git a/ceremony/src/lib/state/session.svelte.ts b/ceremony/src/lib/state/session.svelte.ts index 14a1f3c7ae..36eb33ec7d 100644 --- a/ceremony/src/lib/state/session.svelte.ts +++ b/ceremony/src/lib/state/session.svelte.ts @@ -1,8 +1,9 @@ import type { Session } from "@supabase/supabase-js" import { supabase } from "$lib/supabase/client.ts" import { err, ok, type Result } from "neverthrow" -import { invalidateAll } from "$app/navigation" +import { goto, invalidateAll } from "$app/navigation" import type { Terminal } from "$lib/state/terminal.svelte.ts" +import { sleep } from "$lib/utils/utils.ts" export type SessionError = { message: string @@ -31,22 +32,21 @@ export async function checkAuth(): Promise> { } export async function logout(terminal: Terminal): Promise { + terminal.setTab(1) + await goto("/") + if (!user.session) { - console.log("user already logged out") + terminal.updateHistory("User already logged out", { duplicate: true }) return } - terminal.updateHistory("logging out user...") + terminal.updateHistory("Logging out user...") + await sleep(1000) try { - terminal.setHash(undefined) - terminal.setTab(1) - - terminal.updateHistory("user successfully logged out") const { error } = await supabase.auth.signOut() - user.session = null - + terminal.setHash(undefined) await invalidateAll() } catch (error) { terminal.updateHistory(`error logging out`) diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index 471ea974ce..350d5f7b8e 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -1,18 +1,52 @@ {#if !contributor.userWallet} - + -{:else if contributor.contributionState === 'contributed'} - +{:else if contributor.state === "contributed"} + -{:else if contributor.contributionState === 'verifying'} - {terminal.updateHistory("Verifying your contribution...")} +{:else if !contributor.downloadedSecret && contributor.clientState === "idle"} + -{:else if contributor.contributionState === 'contribute'} - {terminal.updateHistory("Starting contribution...")} - Not starting? - +{:else if contributor.state === "verifying"} + {terminal.updateHistory("Verifying your contribution...", {replace: true})} -{:else if contributor.contributionState === "contribute"} - {terminal.updateHistory("Contributing...")} +{:else if contributor.clientState === "offline" || contributor.clientState === undefined} + {:else if contributor.state === "inQueue"} - + -{:else if !contributor.downloadedSecret && client.state === "idle"} - +{:else if contributor.state === 'contribute'} + {terminal.updateHistory("Starting contribution...", {replace: true})} -{:else if client.state === 'noClient'} - +{:else if contributor.state === "contributing"} + {terminal.updateHistory("Contributing...", {replace: true})} {:else} Loading... diff --git a/ceremony/src/lib/components/Terminal/Code.svelte b/ceremony/src/lib/components/Terminal/Code.svelte index a13794201c..c278fb16b0 100644 --- a/ceremony/src/lib/components/Terminal/Code.svelte +++ b/ceremony/src/lib/components/Terminal/Code.svelte @@ -26,7 +26,7 @@ async function handleCodeJoin() { try { showInput = false terminal.updateHistory("Checking code...", { duplicate: true }) - console.log(normalizedCode) + console.log("code: ", normalizedCode) await sleep(1000) const codeOk = await callJoinQueue(normalizedCode) if (codeOk) { diff --git a/ceremony/src/lib/components/Terminal/LoadingBar.svelte b/ceremony/src/lib/components/Terminal/LoadingBar.svelte index 5d5fc07521..44e933d66f 100644 --- a/ceremony/src/lib/components/Terminal/LoadingBar.svelte +++ b/ceremony/src/lib/components/Terminal/LoadingBar.svelte @@ -9,7 +9,13 @@ type Props = { let { min = 1, max, current }: Props = $props() -let progress = $derived(current != null && max != null ? ((max - current) / (max - min)) * 100 : 0) +let progress = $derived( + current != null && max != null + ? max === min + ? 99.99 + : Math.min(((max - current) / (max - min)) * 100, 99.99) + : 0 +) const TOTAL_SYMBOLS = 30 @@ -22,9 +28,7 @@ function generateQueueBar(progress: number): string { let queueBar = $derived(generateQueueBar(progress)) -let percentageText = $derived(`${progress.toFixed(1)}%`) +let percentageText = $derived(`${progress.toFixed(2)}%`) - -{queueBar} - {percentageText} - +{queueBar} - {percentageText} \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Queue.svelte b/ceremony/src/lib/components/Terminal/Queue.svelte index df14c7f3d5..72a4475133 100644 --- a/ceremony/src/lib/components/Terminal/Queue.svelte +++ b/ceremony/src/lib/components/Terminal/Queue.svelte @@ -7,15 +7,14 @@ import LoadingBar from "$lib/components/Terminal/LoadingBar.svelte" const { contributor, terminal } = getState() onMount(() => { - terminal.updateHistory("---", { duplicate: true }) terminal.updateHistory("You are in queue") }) -Your position: {contributor.queueState.position ?? 33} -Queue length: {contributor.queueState.count ?? 347} -Estimated waiting time: {contributor.queueState.estimatedTime ?? 990} minutes - +Your position: {contributor.queueState.position} +Queue length: {contributor.queueState.count} +Estimated waiting time: {contributor.queueState.estimatedTime} minutes + Your MPC Client is connected. Do not close this tab or your Terminal. Ensure you have a reliable internet connection and that your computer does not go to sleep. diff --git a/ceremony/src/lib/components/Terminal/Secret.svelte b/ceremony/src/lib/components/Terminal/Secret.svelte index 857b06c566..645cc5b059 100644 --- a/ceremony/src/lib/components/Terminal/Secret.svelte +++ b/ceremony/src/lib/components/Terminal/Secret.svelte @@ -4,7 +4,7 @@ import { sleep } from "$lib/utils/utils.ts" import { generateSecret } from "$lib/client" import Button from "$lib/components/Terminal/Button.svelte" -const { client, contributor, terminal, user } = getState() +const { contributor, terminal, user } = getState() let generated = $state(false) let generating = $state(false) @@ -20,7 +20,7 @@ function setDownloadedSecret() { } async function generate() { - if (client.state !== "noClient") { + if (contributor.state !== "noClient") { generating = true terminal.updateHistory("Generating secret...") await sleep(3000) @@ -55,7 +55,7 @@ $effect(() => { onclick={generate} autofocus>> Generate secret {:else} - - + + {/if} {/if} diff --git a/ceremony/src/lib/components/Terminal/Thanks.svelte b/ceremony/src/lib/components/Terminal/Thanks.svelte index f268b7bb7e..5d494b4f0c 100644 --- a/ceremony/src/lib/components/Terminal/Thanks.svelte +++ b/ceremony/src/lib/components/Terminal/Thanks.svelte @@ -24,10 +24,11 @@ beforeNavigate(() => { let unsubscribe: (() => void) | undefined let subscriptionTimeout: NodeJS.Timeout | undefined -$effect(() => { - terminal.updateHistory("Thank you!") +onMount(() => { + terminal.updateHistory("Thank you!", { replace: true }) terminal.updateHistory( - "Your contribution is complete. Thank you for securing the Union network. Tweet your cryptographic attestation for extra transparency." + "Your contribution is complete. Thank you for securing the Union network. Tweet your cryptographic attestation for extra transparency.", + { replace: true } ) subscriptionTimeout = setTimeout(() => { diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 59ba568932..0457c8b7ce 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -60,56 +60,59 @@ function autoScroll(node: HTMLElement) { -
-
-
- - - - - - +
+
+
+
+ + + + + + - - - - {#if terminal.hash !== undefined} - - {/if} + + + {#if terminal.hash !== undefined} + + {/if} +
+
- -
-
-
- {#if terminal.tab === 1} -
- {#each terminal.history as text} - {text} - {/each} -
- {@render children()} - {:else if terminal.tab === 2} - - {:else if terminal.tab === 3} - - {:else if terminal.tab === 4 && terminal.hash} - {@render children()} - {/if} +
+
+ {#if terminal.tab === 1} +
+ {#each terminal.history as text} + {text} + {/each} +
+ {@render children()} + {:else if terminal.tab === 2} + + {:else if terminal.tab === 3} + + {:else if terminal.tab === 4 && terminal.hash} + {@render children()} + {/if} +
-
+
+ diff --git a/ceremony/src/lib/state/client.svelte.ts b/ceremony/src/lib/state/client.svelte.ts deleted file mode 100644 index b3247326e6..0000000000 --- a/ceremony/src/lib/state/client.svelte.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { checkState, start } from "$lib/client" -import type { ClientStatus } from "$lib/client/types.ts" - -type ClientState = undefined | "contributing" | "error" | "noClient" | "successful" | "idle" - -const CLIENT_POLLING_INTERVAL = 1000 // 1 second - -export class Client { - status = $state() - state = $state(undefined) - isPolling = $state(false) - private pollingInterval: NodeJS.Timeout | null = null - - constructor() { - console.log("Creating client state") - this.startPolling() - } - - async checkStatus(): Promise { - const status = await checkState() - console.log(status) - this.updateState(status) - } - - private updateStatus(newStatus: ClientStatus): void { - this.status = newStatus - } - - contribute() { - start() - } - - startPolling(): void { - if (!this.isPolling) { - this.pollingInterval = setInterval(() => this.checkStatus(), CLIENT_POLLING_INTERVAL) - this.isPolling = true - } - } - - stopPolling(): void { - if (this.isPolling && this.pollingInterval !== null) { - clearInterval(this.pollingInterval) - this.pollingInterval = null - this.isPolling = false - } - } - - updateState(status: ClientStatus) { - switch (status) { - case "initializing": - case "downloadStarted": - case "downloading": - case "downloadEnded": - case "contributionStarted": - case "contributionEnded": - case "uploadStarted": - case "uploadEnded": - this.state = "contributing" - break - case "successful": - this.state = "successful" - break - case "failed": - this.state = "error" - break - case "offline": - this.state = "noClient" - break - default: - this.state = "idle" - break - } - } -} diff --git a/ceremony/src/lib/state/contributor.svelte.ts b/ceremony/src/lib/state/contributor.svelte.ts index 81aa265370..fa1d40a335 100644 --- a/ceremony/src/lib/state/contributor.svelte.ts +++ b/ceremony/src/lib/state/contributor.svelte.ts @@ -1,4 +1,5 @@ import { getContext, onDestroy, setContext } from "svelte" +import { checkState } from "$lib/client" import { getCurrentUserState, getUserQueueInfo, @@ -24,6 +25,21 @@ export type AllowanceState = "hasRedeemed" | "inWaitlist" | "inQueue" | "join" | export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed" +export type ClientState = + | "idle" + | "initializing" + | "downloadStarted" + | "downloading" + | "downloadEnded" + | "contributionStarted" + | "contributionEnded" + | "uploadStarted" + | "uploadEnded" + | "failed" + | "successful" + | "offline" + | undefined + interface UserContext { position: number | null count: number | null @@ -55,7 +71,7 @@ export class Contributor { currentUserState = $state(undefined) pollingState = $state<"stopped" | "polling">("stopped") state = $state("loading") - + clientState = $state("offline") contributionState = $state("notContributed") userWallet = $state("") waitListPosition = $state(undefined) @@ -68,9 +84,11 @@ export class Contributor { }) private pollIntervals: { + client: IntervalID | null queue: IntervalID | null contribution: IntervalID | null } = { + client: null, queue: null, contribution: null } @@ -131,6 +149,7 @@ export class Contributor { } this.pollingState = "polling" + this.startClientStatePolling() this.startQueueInfoPolling() this.startContributionStatePolling() } @@ -142,10 +161,31 @@ export class Contributor { } this.pollingState = "stopped" + this.stopClientStatePolling() this.stopQueueInfoPolling() this.stopContributionStatePolling() } + private startClientStatePolling() { + this.pollClientState() + this.pollIntervals.client = setInterval( + () => this.pollClientState(), + CLIENT_POLING_INTERVAL + ) as IntervalID + } + + private stopClientStatePolling() { + if (this.pollIntervals.client) { + clearInterval(this.pollIntervals.client) + this.pollIntervals.client = null + } + } + + private async pollClientState() { + const state = await checkState() + this.updateClientState(state) + } + private startQueueInfoPolling() { this.pollQueueInfo() this.pollIntervals.queue = setInterval( @@ -196,6 +236,11 @@ export class Contributor { } } + private updateClientState(state: ClientState) { + this.clientState = state + this.updateState() + } + private updateQueueInfo(queueInfo: QueueInfoResult) { if (queueInfo.inQueue) { this.queueState = { @@ -227,13 +272,36 @@ export class Contributor { private updateState() { if (this.contributionState === "contribute") { - this.state = "contribute" + switch (this.clientState) { + case "initializing": + case "downloadStarted": + case "downloading": + case "downloadEnded": + case "contributionStarted": + case "contributionEnded": + case "uploadStarted": + case "uploadEnded": + case "successful": + this.state = "contributing" + break + case "failed": + this.state = "error" + break + case "offline": + this.state = "noClient" + break + default: + this.state = "contribute" + break + } } else if (this.queueState.position !== null) { this.state = "inQueue" } else if (this.contributionState === "contributed") { this.state = "contributed" } else if (this.contributionState === "verifying") { this.state = "verifying" + } else if (this.clientState === "offline") { + this.state = "offline" } else { this.state = "loading" } diff --git a/ceremony/src/lib/state/index.svelte.ts b/ceremony/src/lib/state/index.svelte.ts index 3c2bbb6e77..c7fd82458a 100644 --- a/ceremony/src/lib/state/index.svelte.ts +++ b/ceremony/src/lib/state/index.svelte.ts @@ -1,5 +1,4 @@ import { getContext, setContext } from "svelte" -import { Client } from "./client.svelte.ts" import { Contributor } from "./contributor.svelte.ts" import { Terminal } from "./terminal.svelte.ts" import { user, type UserSession } from "$lib/state/session.svelte.ts" @@ -7,7 +6,6 @@ import { Activity } from "$lib/state/live.svelte.ts" import { Contributions } from "$lib/state/contributions.svelte.ts" export interface AppState { - client: Client contributor: Contributor terminal: Terminal activity: Activity @@ -20,7 +18,6 @@ const STATE_KEY = Symbol("STATE") export function createState() { console.log("Creating state") const state: AppState = { - client: new Client(), contributor: new Contributor(), terminal: new Terminal(), activity: new Activity(), diff --git a/ceremony/src/lib/stores/state.svelte.ts b/ceremony/src/lib/stores/state.svelte.ts index d6e708816f..7c46629541 100644 --- a/ceremony/src/lib/stores/state.svelte.ts +++ b/ceremony/src/lib/stores/state.svelte.ts @@ -1,319 +1,319 @@ -import { getContext, onDestroy, setContext } from "svelte" -import { checkState } from "$lib/client" -import { - getCurrentUserState, - getUserQueueInfo, - getContributionState, - getUserWallet, - getWaitListPosition -} from "$lib/supabase" - -type IntervalID = NodeJS.Timeout | number - -type State = - | "loading" - | "inQueue" - | "contribute" - | "contributing" - | "verifying" - | "contributed" - | "error" - | "offline" - | "noClient" - -export type AllowanceState = "hasRedeemed" | "inWaitlist" | "inQueue" | "join" | undefined - -export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed" - -export type ClientState = - | "idle" - | "initializing" - | "downloadStarted" - | "downloading" - | "downloadEnded" - | "contributionStarted" - | "contributionEnded" - | "uploadStarted" - | "uploadEnded" - | "failed" - | "successful" - | "offline" - | undefined - -interface UserContext { - position: number | null - count: number | null - estimatedTime: number | null - error: string | null -} - -interface QueueInfoSuccess { - inQueue: true - position: number - count: number -} - -interface QueueInfoError { - inQueue: false - message: string -} - -type QueueInfoResult = QueueInfoSuccess | QueueInfoError - -const second = 1000 -const CLIENT_POLING_INTERVAL = second -const CONTRIBUTION_POLLING_INTERVAL = second * 5 -const QUEUE_POLLING_INTERVAL = second * 5 - -export class ContributorState { - userId = $state(undefined) - loggedIn = $state(false) - currentUserState = $state(undefined) - pollingState = $state<"stopped" | "polling">("stopped") - state = $state("loading") - clientState = $state("offline") - contributionState = $state("notContributed") - userWallet = $state("") - waitListPosition = $state(undefined) - downloadedSecret = $state(localStorage.getItem("downloaded-secret") === "true") - queueState = $state({ - position: null, - count: null, - estimatedTime: null, - error: null - }) - - private pollIntervals: { - client: IntervalID | null - queue: IntervalID | null - contribution: IntervalID | null - } = { - client: null, - queue: null, - contribution: null - } - - constructor(userId?: string) { - if (userId) { - this.userId = userId - this.loggedIn = true - this.checkCurrentUserState(userId) - this.startPolling() - } - onDestroy(() => { - this.stopPolling() - }) - } - - setUserId(userId: string | undefined) { - if (this.userId === undefined && userId) { - this.userId = userId - this.loggedIn = true - this.checkWaitListPosition(userId) - this.checkUserWallet(userId) - this.checkCurrentUserState(userId) - this.startPolling() - } - } - - async checkWaitListPosition(_userId: string | undefined): Promise { - this.waitListPosition = await getWaitListPosition() - return this.waitListPosition - } - - async checkCurrentUserState(userId: string | undefined): Promise { - this.currentUserState = await getCurrentUserState(userId) - return this.currentUserState - } - - async checkUserWallet(userId: string | undefined): Promise { - this.userWallet = await getUserWallet(userId) - return this.userWallet - } - - setAllowanceState(state: AllowanceState) { - this.currentUserState = state - this.pollQueueInfo() - this.pollContributionState() - } - - startPolling() { - if (this.pollingState === "polling") { - console.log("Polling is already running.") - return - } - - if (!this.userId) { - console.log("Cannot start polling without userId.") - return - } - - this.pollingState = "polling" - this.startClientStatePolling() - this.startQueueInfoPolling() - this.startContributionStatePolling() - } - - stopPolling() { - if (this.pollingState === "stopped") { - console.log("Polling is already stopped.") - return - } - - this.pollingState = "stopped" - this.stopClientStatePolling() - this.stopQueueInfoPolling() - this.stopContributionStatePolling() - } - - private startClientStatePolling() { - this.pollClientState() - this.pollIntervals.client = setInterval( - () => this.pollClientState(), - CLIENT_POLING_INTERVAL - ) as IntervalID - } - - private stopClientStatePolling() { - if (this.pollIntervals.client) { - clearInterval(this.pollIntervals.client) - this.pollIntervals.client = null - } - } - - private async pollClientState() { - const state = await checkState() - this.updateClientState(state) - } - - private startQueueInfoPolling() { - this.pollQueueInfo() - this.pollIntervals.queue = setInterval( - () => this.pollQueueInfo(), - QUEUE_POLLING_INTERVAL - ) as IntervalID - } - - private stopQueueInfoPolling() { - if (this.pollIntervals.queue) { - clearInterval(this.pollIntervals.queue) - this.pollIntervals.queue = null - } - } - - private async pollQueueInfo() { - try { - const queueInfo = await getUserQueueInfo() - this.updateQueueInfo(queueInfo) - } catch (error) { - console.log("Error polling queue info:", error) - this.setError(error instanceof Error ? error.message : "Unknown error occurred") - } - } - - private startContributionStatePolling() { - this.pollContributionState() - this.pollIntervals.contribution = setInterval( - () => this.pollContributionState(), - CONTRIBUTION_POLLING_INTERVAL - ) as IntervalID - } - - private stopContributionStatePolling() { - if (this.pollIntervals.contribution) { - clearInterval(this.pollIntervals.contribution) - this.pollIntervals.contribution = null - } - } - - private async pollContributionState() { - try { - const state = await getContributionState() - this.updateContributionState(state) - } catch (error) { - console.log("Error polling contribution state:", error) - this.setError(error instanceof Error ? error.message : "Unknown error occurred") - } - } - - private updateClientState(state: ClientState) { - this.clientState = state - this.updateState() - } - - private updateQueueInfo(queueInfo: QueueInfoResult) { - if (queueInfo.inQueue) { - this.queueState = { - ...this.queueState, - position: queueInfo.position, - count: queueInfo.count, - estimatedTime: queueInfo.position * 60 - } - } else { - this.queueState = { - ...this.queueState, - position: null, - count: null, - estimatedTime: null - } - } - this.updateState() - } - - private updateContributionState(state: ContributionState) { - this.contributionState = state - this.updateState() - } - - private setError(message: string) { - this.queueState = { ...this.queueState, error: message } - this.state = "error" - } - - private updateState() { - if (this.contributionState === "contribute") { - switch (this.clientState) { - case "initializing": - case "downloadStarted": - case "downloading": - case "downloadEnded": - case "contributionStarted": - case "contributionEnded": - case "uploadStarted": - case "uploadEnded": - case "successful": - this.state = "contributing" - break - case "failed": - this.state = "error" - break - case "offline": - this.state = "noClient" - break - default: - this.state = "contribute" - break - } - } else if (this.queueState.position !== null) { - this.state = "inQueue" - } else if (this.contributionState === "contributed") { - this.state = "contributed" - } else if (this.contributionState === "verifying") { - this.state = "verifying" - } else if (this.clientState === "offline") { - this.state = "offline" - } else { - this.state = "loading" - } - } -} - -const CONTRIBUTOR_KEY = Symbol("CONTRIBUTOR") - -export function setContributorState() { - return setContext(CONTRIBUTOR_KEY, new ContributorState()) -} - -export function getContributorState(): ContributorState { - return getContext(CONTRIBUTOR_KEY) -} +// import { getContext, onDestroy, setContext } from "svelte" +// import { checkState } from "$lib/client" +// import { +// getCurrentUserState, +// getUserQueueInfo, +// getContributionState, +// getUserWallet, +// getWaitListPosition +// } from "$lib/supabase" +// +// type IntervalID = NodeJS.Timeout | number +// +// type State = +// | "loading" +// | "inQueue" +// | "contribute" +// | "contributing" +// | "verifying" +// | "contributed" +// | "error" +// | "offline" +// | "noClient" +// +// export type AllowanceState = "hasRedeemed" | "inWaitlist" | "inQueue" | "join" | undefined +// +// export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed" +// +// export type ClientState = +// | "idle" +// | "initializing" +// | "downloadStarted" +// | "downloading" +// | "downloadEnded" +// | "contributionStarted" +// | "contributionEnded" +// | "uploadStarted" +// | "uploadEnded" +// | "failed" +// | "successful" +// | "offline" +// | undefined +// +// interface UserContext { +// position: number | null +// count: number | null +// estimatedTime: number | null +// error: string | null +// } +// +// interface QueueInfoSuccess { +// inQueue: true +// position: number +// count: number +// } +// +// interface QueueInfoError { +// inQueue: false +// message: string +// } +// +// type QueueInfoResult = QueueInfoSuccess | QueueInfoError +// +// const second = 1000 +// const CLIENT_POLING_INTERVAL = second +// const CONTRIBUTION_POLLING_INTERVAL = second * 5 +// const QUEUE_POLLING_INTERVAL = second * 5 +// +// export class ContributorState { +// userId = $state(undefined) +// loggedIn = $state(false) +// currentUserState = $state(undefined) +// pollingState = $state<"stopped" | "polling">("stopped") +// state = $state("loading") +// clientState = $state("offline") +// contributionState = $state("notContributed") +// userWallet = $state("") +// waitListPosition = $state(undefined) +// downloadedSecret = $state(localStorage.getItem("downloaded-secret") === "true") +// queueState = $state({ +// position: null, +// count: null, +// estimatedTime: null, +// error: null +// }) +// +// private pollIntervals: { +// client: IntervalID | null +// queue: IntervalID | null +// contribution: IntervalID | null +// } = { +// client: null, +// queue: null, +// contribution: null +// } +// +// constructor(userId?: string) { +// if (userId) { +// this.userId = userId +// this.loggedIn = true +// this.checkCurrentUserState(userId) +// this.startPolling() +// } +// onDestroy(() => { +// this.stopPolling() +// }) +// } +// +// setUserId(userId: string | undefined) { +// if (this.userId === undefined && userId) { +// this.userId = userId +// this.loggedIn = true +// this.checkWaitListPosition(userId) +// this.checkUserWallet(userId) +// this.checkCurrentUserState(userId) +// this.startPolling() +// } +// } +// +// async checkWaitListPosition(_userId: string | undefined): Promise { +// this.waitListPosition = await getWaitListPosition() +// return this.waitListPosition +// } +// +// async checkCurrentUserState(userId: string | undefined): Promise { +// this.currentUserState = await getCurrentUserState(userId) +// return this.currentUserState +// } +// +// async checkUserWallet(userId: string | undefined): Promise { +// this.userWallet = await getUserWallet(userId) +// return this.userWallet +// } +// +// setAllowanceState(state: AllowanceState) { +// this.currentUserState = state +// this.pollQueueInfo() +// this.pollContributionState() +// } +// +// startPolling() { +// if (this.pollingState === "polling") { +// console.log("Polling is already running.") +// return +// } +// +// if (!this.userId) { +// console.log("Cannot start polling without userId.") +// return +// } +// +// this.pollingState = "polling" +// this.startClientStatePolling() +// this.startQueueInfoPolling() +// this.startContributionStatePolling() +// } +// +// stopPolling() { +// if (this.pollingState === "stopped") { +// console.log("Polling is already stopped.") +// return +// } +// +// this.pollingState = "stopped" +// this.stopClientStatePolling() +// this.stopQueueInfoPolling() +// this.stopContributionStatePolling() +// } +// +// private startClientStatePolling() { +// this.pollClientState() +// this.pollIntervals.client = setInterval( +// () => this.pollClientState(), +// CLIENT_POLING_INTERVAL +// ) as IntervalID +// } +// +// private stopClientStatePolling() { +// if (this.pollIntervals.client) { +// clearInterval(this.pollIntervals.client) +// this.pollIntervals.client = null +// } +// } +// +// private async pollClientState() { +// const state = await checkState() +// this.updateClientState(state) +// } +// +// private startQueueInfoPolling() { +// this.pollQueueInfo() +// this.pollIntervals.queue = setInterval( +// () => this.pollQueueInfo(), +// QUEUE_POLLING_INTERVAL +// ) as IntervalID +// } +// +// private stopQueueInfoPolling() { +// if (this.pollIntervals.queue) { +// clearInterval(this.pollIntervals.queue) +// this.pollIntervals.queue = null +// } +// } +// +// private async pollQueueInfo() { +// try { +// const queueInfo = await getUserQueueInfo() +// this.updateQueueInfo(queueInfo) +// } catch (error) { +// console.log("Error polling queue info:", error) +// this.setError(error instanceof Error ? error.message : "Unknown error occurred") +// } +// } +// +// private startContributionStatePolling() { +// this.pollContributionState() +// this.pollIntervals.contribution = setInterval( +// () => this.pollContributionState(), +// CONTRIBUTION_POLLING_INTERVAL +// ) as IntervalID +// } +// +// private stopContributionStatePolling() { +// if (this.pollIntervals.contribution) { +// clearInterval(this.pollIntervals.contribution) +// this.pollIntervals.contribution = null +// } +// } +// +// private async pollContributionState() { +// try { +// const state = await getContributionState() +// this.updateContributionState(state) +// } catch (error) { +// console.log("Error polling contribution state:", error) +// this.setError(error instanceof Error ? error.message : "Unknown error occurred") +// } +// } +// +// private updateClientState(state: ClientState) { +// this.clientState = state +// this.updateState() +// } +// +// private updateQueueInfo(queueInfo: QueueInfoResult) { +// if (queueInfo.inQueue) { +// this.queueState = { +// ...this.queueState, +// position: queueInfo.position, +// count: queueInfo.count, +// estimatedTime: queueInfo.position * 60 +// } +// } else { +// this.queueState = { +// ...this.queueState, +// position: null, +// count: null, +// estimatedTime: null +// } +// } +// this.updateState() +// } +// +// private updateContributionState(state: ContributionState) { +// this.contributionState = state +// this.updateState() +// } +// +// private setError(message: string) { +// this.queueState = { ...this.queueState, error: message } +// this.state = "error" +// } +// +// private updateState() { +// if (this.contributionState === "contribute") { +// switch (this.clientState) { +// case "initializing": +// case "downloadStarted": +// case "downloading": +// case "downloadEnded": +// case "contributionStarted": +// case "contributionEnded": +// case "uploadStarted": +// case "uploadEnded": +// case "successful": +// this.state = "contributing" +// break +// case "failed": +// this.state = "error" +// break +// case "offline": +// this.state = "noClient" +// break +// default: +// this.state = "contribute" +// break +// } +// } else if (this.queueState.position !== null) { +// this.state = "inQueue" +// } else if (this.contributionState === "contributed") { +// this.state = "contributed" +// } else if (this.contributionState === "verifying") { +// this.state = "verifying" +// } else if (this.clientState === "offline") { +// this.state = "offline" +// } else { +// this.state = "loading" +// } +// } +// } +// +// const CONTRIBUTOR_KEY = Symbol("CONTRIBUTOR") +// +// export function setContributorState() { +// return setContext(CONTRIBUTOR_KEY, new ContributorState()) +// } +// +// export function getContributorState(): ContributorState { +// return getContext(CONTRIBUTOR_KEY) +// } diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index 346d97fd99..77bd6ff117 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -12,8 +12,8 @@ import { queryUserWallet } from "$lib/supabase/queries.ts" import { supabase } from "$lib/supabase/client.ts" -import type { AllowanceState, ContributionState } from "$lib/stores/state.svelte.ts" import { sleep } from "$lib/utils/utils.ts" +import type { AllowanceState, ContributionState } from "$lib/state/contributor.svelte.ts" export const callJoinQueue = async (code: string | null): Promise => { if (!user.session) { @@ -121,11 +121,10 @@ export const getCurrentUserState = async (userId: string | undefined): Promise
{ diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index 45e84b51d1..763de4d17a 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -6,7 +6,7 @@ import "../styles/tailwind.css" import { watch } from "runed" import { checkAuth } from "$lib/state/session.svelte.ts" import Terminal from "$lib/components/Terminal/index.svelte" -import Circles from "$lib/components/Circles.svelte" +import { start } from "$lib/client" let { children } = $props() @@ -23,6 +23,12 @@ $effect(() => { } }) +$effect(() => { + if (contributor.contributionState === "contribute" && contributor.state !== "contributing") { + start() + } +}) + watch( () => user.session?.user.id, () => { From 0174bcfd1d8ba4803061fb23d8464d2597514b17 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 20:45:29 +0200 Subject: [PATCH 17/40] feat(ceremony): save progress terminal --- .../components/Terminal/Authenticate.svelte | 8 ++- .../src/lib/components/Terminal/Button.svelte | 8 ++- .../lib/components/Terminal/Ceremony.svelte | 8 ++- .../src/lib/components/Terminal/Code.svelte | 6 +- .../components/Terminal/Contributors.svelte | 22 ++++---- .../components/Terminal/Install/Linux.svelte | 17 ++++-- .../components/Terminal/Install/MacOS.svelte | 24 +++++--- .../Terminal/Install/SelectOS.svelte | 11 ++-- .../components/Terminal/Install/index.svelte | 10 +++- .../src/lib/components/Terminal/Join.svelte | 11 ++-- .../lib/components/Terminal/LoadingBar.svelte | 2 +- .../src/lib/components/Terminal/Queue.svelte | 6 +- .../src/lib/components/Terminal/Reward.svelte | 6 +- .../src/lib/components/Terminal/Secret.svelte | 55 +++++++++++++++++-- .../src/lib/components/Terminal/Thanks.svelte | 17 ++++-- .../lib/components/Terminal/Waitlist.svelte | 6 +- ceremony/src/lib/state/terminal.svelte.ts | 4 ++ ceremony/src/lib/supabase/index.ts | 3 +- ceremony/src/routes/+layout.svelte | 6 +- ceremony/src/routes/+page.svelte | 3 - .../src/routes/0____0/[hash]/+page.svelte | 20 ++++--- 21 files changed, 178 insertions(+), 75 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/Authenticate.svelte b/ceremony/src/lib/components/Terminal/Authenticate.svelte index ff1263db19..de0375d73c 100644 --- a/ceremony/src/lib/components/Terminal/Authenticate.svelte +++ b/ceremony/src/lib/components/Terminal/Authenticate.svelte @@ -59,15 +59,19 @@ onMount(() => { } } }) + +onDestroy(() => { + terminal.clearHistory() +}) {#if !redirecting} {#each providers as provider, index} diff --git a/ceremony/src/lib/components/Terminal/Button.svelte b/ceremony/src/lib/components/Terminal/Button.svelte index 331dd80404..56ae3f3347 100644 --- a/ceremony/src/lib/components/Terminal/Button.svelte +++ b/ceremony/src/lib/components/Terminal/Button.svelte @@ -4,7 +4,11 @@ let { children, class: className = "", value = $bindable(), ...rest } = $props() \ No newline at end of file + + + \ No newline at end of file diff --git a/ceremony/src/lib/components/Terminal/Ceremony.svelte b/ceremony/src/lib/components/Terminal/Ceremony.svelte index 14d31f3219..4cd4f7ea22 100644 --- a/ceremony/src/lib/components/Terminal/Ceremony.svelte +++ b/ceremony/src/lib/components/Terminal/Ceremony.svelte @@ -6,9 +6,13 @@ import Queue from "$lib/components/Terminal/Queue.svelte" import Install from "$lib/components/Terminal/Install/index.svelte" import Print from "$lib/components/Terminal/Print.svelte" import Secret from "$lib/components/Terminal/Secret.svelte" -import { start } from "$lib/client" +import { onDestroy } from "svelte" const { contributor, terminal } = getState() + +onDestroy(() => { + terminal.clearHistory() +}) {#if !contributor.userWallet} @@ -36,6 +40,6 @@ const { contributor, terminal } = getState() {terminal.updateHistory("Contributing...", {replace: true})} {:else} - Loading... + Not able to contribute at this time {/if} diff --git a/ceremony/src/lib/components/Terminal/Code.svelte b/ceremony/src/lib/components/Terminal/Code.svelte index c278fb16b0..b26606f5ff 100644 --- a/ceremony/src/lib/components/Terminal/Code.svelte +++ b/ceremony/src/lib/components/Terminal/Code.svelte @@ -1,7 +1,7 @@ {#if showInput} diff --git a/ceremony/src/lib/components/Terminal/Contributors.svelte b/ceremony/src/lib/components/Terminal/Contributors.svelte index 9c91592f6a..e771758926 100644 --- a/ceremony/src/lib/components/Terminal/Contributors.svelte +++ b/ceremony/src/lib/components/Terminal/Contributors.svelte @@ -4,10 +4,11 @@ import { goto } from "$app/navigation" import Print from "$lib/components/Terminal/Print.svelte" import { cn } from "$lib/utils/utils.ts" import Button from "$lib/components/Terminal/Button.svelte" +import { onMount } from "svelte" const { contributions, terminal } = getState() -let selectedIndex = $state(0) +let focusedIndex = $state(0) let buttons: Array = [] function handleClick(contributor: any) { @@ -18,21 +19,21 @@ function handleClick(contributor: any) { let unsubscribe: (() => void) | undefined let subscriptionTimeout: NodeJS.Timeout | undefined -$effect(() => { +onMount(() => { subscriptionTimeout = setTimeout(() => { unsubscribe = terminal.keys.subscribe(event => { if (event) { if (event.type === "keydown") { if (event.key === "ArrowUp") { - selectedIndex = - (selectedIndex - 1 + contributions.data.length) % contributions.data.length - buttons[selectedIndex]?.focus() + focusedIndex = + (focusedIndex - 1 + contributions.data.length) % contributions.data.length + buttons[focusedIndex]?.focus() } else if (event.key === "ArrowDown") { - selectedIndex = (selectedIndex + 1) % contributions.data.length - buttons[selectedIndex]?.focus() + focusedIndex = (focusedIndex + 1) % contributions.data.length + buttons[focusedIndex]?.focus() } else if (event.key === "Enter") { - if (buttons[selectedIndex]) { - handleClick(contributions.data[selectedIndex]) + if (buttons[focusedIndex]) { + handleClick(contributions.data[focusedIndex]) } } } @@ -54,7 +55,8 @@ $effect(() => { {#each contributions.data as contributor, index} diff --git a/ceremony/src/lib/components/Terminal/LoadingBar.svelte b/ceremony/src/lib/components/Terminal/LoadingBar.svelte index 44e933d66f..e238c317a3 100644 --- a/ceremony/src/lib/components/Terminal/LoadingBar.svelte +++ b/ceremony/src/lib/components/Terminal/LoadingBar.svelte @@ -23,7 +23,7 @@ function generateQueueBar(progress: number): string { const filledSymbols = Math.round((progress / 100) * TOTAL_SYMBOLS) const emptySymbols = TOTAL_SYMBOLS - filledSymbols - return `[${"=".repeat(filledSymbols)}${"-".repeat(emptySymbols)}]` + return `[${"#".repeat(filledSymbols)}${"-".repeat(emptySymbols)}]` } let queueBar = $derived(generateQueueBar(progress)) diff --git a/ceremony/src/lib/components/Terminal/Queue.svelte b/ceremony/src/lib/components/Terminal/Queue.svelte index 72a4475133..b44e3ee705 100644 --- a/ceremony/src/lib/components/Terminal/Queue.svelte +++ b/ceremony/src/lib/components/Terminal/Queue.svelte @@ -1,5 +1,5 @@ Your position: {contributor.queueState.position} diff --git a/ceremony/src/lib/components/Terminal/Reward.svelte b/ceremony/src/lib/components/Terminal/Reward.svelte index 99cd6671a3..2b69f52861 100644 --- a/ceremony/src/lib/components/Terminal/Reward.svelte +++ b/ceremony/src/lib/components/Terminal/Reward.svelte @@ -1,7 +1,7 @@ {#if showInput} diff --git a/ceremony/src/lib/components/Terminal/Secret.svelte b/ceremony/src/lib/components/Terminal/Secret.svelte index 645cc5b059..6e0a94280e 100644 --- a/ceremony/src/lib/components/Terminal/Secret.svelte +++ b/ceremony/src/lib/components/Terminal/Secret.svelte @@ -1,13 +1,16 @@ {#if !generating} {#if !generated} - {:else} - - + + {/if} {/if} diff --git a/ceremony/src/lib/components/Terminal/Thanks.svelte b/ceremony/src/lib/components/Terminal/Thanks.svelte index 5d494b4f0c..61695a716e 100644 --- a/ceremony/src/lib/components/Terminal/Thanks.svelte +++ b/ceremony/src/lib/components/Terminal/Thanks.svelte @@ -2,13 +2,13 @@ import { getPublicHash } from "$lib/supabase" import { getState } from "$lib/state/index.svelte.ts" import { cn, sleep } from "$lib/utils/utils.ts" -import { onMount } from "svelte" +import { onDestroy, onMount } from "svelte" import Button from "$lib/components/Terminal/Button.svelte" import { beforeNavigate } from "$app/navigation" const { terminal } = getState() -let selectedButton = $state(0) +let focusedIndex = $state(0) let showButtons = $state(true) const buttons = $state([ @@ -36,11 +36,11 @@ onMount(() => { if (event) { if (event.type === "keydown" && terminal.tab === 1) { if (event.key === "ArrowUp") { - selectedButton = (selectedButton - 1 + buttons.length) % buttons.length + focusedIndex = (focusedIndex - 1 + buttons.length) % buttons.length } else if (event.key === "ArrowDown") { - selectedButton = (selectedButton + 1) % buttons.length + focusedIndex = (focusedIndex + 1) % buttons.length } else if (event.key === "Enter") { - triggerAction(selectedButton) + triggerAction(focusedIndex) } } } @@ -78,12 +78,17 @@ function triggerAction(index: number) { terminal.setTab(3) } } + +onDestroy(() => { + terminal.clearHistory() +}) {#if showButtons} {#each buttons as btn, index} From 8db460ef5255dc9cb5eadf53b59d415dd5917166 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 20:56:48 +0200 Subject: [PATCH 18/40] fix(ceremony): fix build --- ceremony/src/lib/components/Terminal/Print.svelte | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/Print.svelte b/ceremony/src/lib/components/Terminal/Print.svelte index 28604e2f31..a579ea06a5 100644 --- a/ceremony/src/lib/components/Terminal/Print.svelte +++ b/ceremony/src/lib/components/Terminal/Print.svelte @@ -1,11 +1,5 @@

{@render children()}

\ No newline at end of file From 7ac9881af4f64c8968ac9ee224b09b8307e380a8 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 21:20:31 +0200 Subject: [PATCH 19/40] feat(ceremony): save progress --- ceremony/src/lib/components/Terminal/index.svelte | 1 + ceremony/src/routes/0____0/[hash]/+page.svelte | 1 + 2 files changed, 2 insertions(+) diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 0457c8b7ce..a3bd7162fe 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -102,6 +102,7 @@ function autoScroll(node: HTMLElement) { {text} {/each}
+
{@render children()} {:else if terminal.tab === 2} diff --git a/ceremony/src/routes/0____0/[hash]/+page.svelte b/ceremony/src/routes/0____0/[hash]/+page.svelte index 00cee8bc66..6b645ac1db 100644 --- a/ceremony/src/routes/0____0/[hash]/+page.svelte +++ b/ceremony/src/routes/0____0/[hash]/+page.svelte @@ -114,6 +114,7 @@ const imagePath = "https://ceremony.union.build/images/ceremony.png" {print} {/each} {#if showButtons} +
- - + {#if terminal.hash !== undefined}
+
{#if terminal.tab === 1} @@ -113,6 +121,9 @@ function autoScroll(node: HTMLElement) { {/if}
+ + +
diff --git a/ceremony/src/lib/state/terminal.svelte.ts b/ceremony/src/lib/state/terminal.svelte.ts index 46a775d5b1..0b9625ab71 100644 --- a/ceremony/src/lib/state/terminal.svelte.ts +++ b/ceremony/src/lib/state/terminal.svelte.ts @@ -21,7 +21,8 @@ export class Terminal { history = $state>([]) tab = $state<1 | 2 | 3 | number>(1) hash = $state(undefined) - contribution = $state(undefined) + currentStep = $state(0) + maxStep = $state(10) keys = readable(null, set => { const handleKeyEvent = (event: KeyboardEvent) => { @@ -77,8 +78,8 @@ export class Terminal { this.hash = hash } - setContribution(contribution: any) { - this.contribution = contribution + setStep(step: number) { + this.currentStep = step } } diff --git a/ceremony/src/routes/+page.svelte b/ceremony/src/routes/+page.svelte index bf5262c692..be2065a484 100644 --- a/ceremony/src/routes/+page.svelte +++ b/ceremony/src/routes/+page.svelte @@ -21,7 +21,7 @@ onMount(() => { {#if contributor.currentUserState === "hasRedeemed" || contributor.currentUserState === "inQueue"} {:else if contributor.currentUserState === "inWaitlist"} - + {:else if contributor.currentUserState === "join"} {/if} From 3cdf48b5786451d9ca8d89c465e2f2446b7a5057 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 22:16:55 +0200 Subject: [PATCH 21/40] feat(ceremony): save progress --- .../src/lib/components/Terminal/index.svelte | 117 +++++++++--------- ceremony/src/routes/+layout.svelte | 4 +- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/ceremony/src/lib/components/Terminal/index.svelte b/ceremony/src/lib/components/Terminal/index.svelte index 84616890df..1ec92c8196 100644 --- a/ceremony/src/lib/components/Terminal/index.svelte +++ b/ceremony/src/lib/components/Terminal/index.svelte @@ -61,70 +61,69 @@ -
-
- - -
-
- - - - - - - - + + + {#if terminal.hash !== undefined} + - - - {#if terminal.hash !== undefined} - - {/if} -
- + {/if}
+ +
- -
-
- {#if terminal.tab === 1} -
- {#each terminal.history as text} - {text} - {/each} -
-
- {@render children()} - {:else if terminal.tab === 2} - - {:else if terminal.tab === 3} - - {:else if terminal.tab === 4 && terminal.hash} - {@render children()} - {/if} -
+ +
+
+ {#if terminal.tab === 1} +
+ {#each terminal.history as text} + {text} + {/each} +
+
+ {@render children()} + {:else if terminal.tab === 2} + + {:else if terminal.tab === 3} + + {:else if terminal.tab === 4 && terminal.hash} + {@render children()} + {/if}
+
- + + +
- -
diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index 546ca0fd55..b7d86a0543 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -7,6 +7,7 @@ import Terminal from "$lib/components/Terminal/index.svelte" import { start } from "$lib/client" import "../styles/tailwind.css" +import Print from "$lib/components/Terminal/Print.svelte"; let { children } = $props() @@ -37,8 +38,9 @@ watch( ) -
+
{@render children()} + 1:00:00
From 7ce9e669f495c76c385e638aa6f511516b0282d8 Mon Sep 17 00:00:00 2001 From: o-az Date: Thu, 26 Sep 2024 13:23:10 -0700 Subject: [PATCH 22/40] feat: video background --- ceremony/src/routes/+layout.svelte | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ceremony/src/routes/+layout.svelte b/ceremony/src/routes/+layout.svelte index b7d86a0543..735293ffe0 100644 --- a/ceremony/src/routes/+layout.svelte +++ b/ceremony/src/routes/+layout.svelte @@ -7,7 +7,6 @@ import Terminal from "$lib/components/Terminal/index.svelte" import { start } from "$lib/client" import "../styles/tailwind.css" -import Print from "$lib/components/Terminal/Print.svelte"; let { children } = $props() @@ -38,9 +37,26 @@ watch( ) -
+ + +
{@render children()} - 1:00:00
+ + From 6f938c6fc08d954cd3eac4f6faf3aac17dbf09f2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 26 Sep 2024 22:46:15 +0200 Subject: [PATCH 23/40] feat(ceremony): save progress --- .../lib/components/Terminal/Activity.svelte | 2 +- .../components/Terminal/Authenticate.svelte | 1 - .../lib/components/Terminal/Ceremony.svelte | 1 - .../components/Terminal/Contributors.svelte | 4 +- .../src/lib/components/Terminal/Join.svelte | 2 +- .../src/lib/components/Terminal/Print.svelte | 2 +- .../lib/components/Terminal/TaskBar.svelte | 12 +- .../src/lib/components/Terminal/Thanks.svelte | 3 +- .../src/lib/components/Terminal/Timer.svelte | 5 + .../src/lib/components/Terminal/index.svelte | 113 +++++++++--------- ceremony/src/routes/+layout.svelte | 5 +- 11 files changed, 78 insertions(+), 72 deletions(-) create mode 100644 ceremony/src/lib/components/Terminal/Timer.svelte diff --git a/ceremony/src/lib/components/Terminal/Activity.svelte b/ceremony/src/lib/components/Terminal/Activity.svelte index 1fb032b4eb..0854f357f9 100644 --- a/ceremony/src/lib/components/Terminal/Activity.svelte +++ b/ceremony/src/lib/components/Terminal/Activity.svelte @@ -21,7 +21,7 @@ function formatTimestamp(timestamp: string): string { {#if activity.data} - ceremony activity + Ceremony activity {#each activity.data as item, i (item)} {@const type = item.message.type} {@const user = item.message.user} diff --git a/ceremony/src/lib/components/Terminal/Authenticate.svelte b/ceremony/src/lib/components/Terminal/Authenticate.svelte index af4806cda0..22080e0cf6 100644 --- a/ceremony/src/lib/components/Terminal/Authenticate.svelte +++ b/ceremony/src/lib/components/Terminal/Authenticate.svelte @@ -67,7 +67,6 @@ onDestroy(() => { {#if !redirecting} - {#each providers as provider, index} - - {#if terminal.hash !== undefined}