From 7ef6b5d16855f30cc24e647f7dee1f3be6d0575b Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 14:13:14 +0200 Subject: [PATCH 01/17] feat(ceremony): contributors --- ceremony/src/lib/client/index.ts | 15 +- ceremony/src/lib/supabase/index.ts | 32 ++- ceremony/src/lib/supabase/queries.ts | 20 ++ ceremony/src/routes/auth/dive/+page.svelte | 4 +- .../src/routes/contributions/+page.svelte | 249 ++++++++++++++++++ .../routes/contributions/[hash]/+page.svelte | 62 +++++ dictionary.txt | 1 + 7 files changed, 376 insertions(+), 7 deletions(-) create mode 100644 ceremony/src/routes/contributions/+page.svelte create mode 100644 ceremony/src/routes/contributions/[hash]/+page.svelte diff --git a/ceremony/src/lib/client/index.ts b/ceremony/src/lib/client/index.ts index b299f579f1..927eda7901 100644 --- a/ceremony/src/lib/client/index.ts +++ b/ceremony/src/lib/client/index.ts @@ -1,11 +1,18 @@ import { get, post } from "$lib/client/http.ts" -import { user } from "$lib/stores/user.svelte.ts" import { getQueuePayloadId } from "$lib/supabase/queries.ts" import type { ClientState, ContributeBody } from "$lib/client/types.ts" +import { supabase } from "$lib/supabase/client.ts" export const start = async (): Promise => { - const userId = user?.session?.user.id - const email = user?.session?.user?.email + const { data: session, error: sessionError } = await supabase.auth.refreshSession() + + if (sessionError) { + console.error("Error refreshing session:", sessionError) + return + } + + const userId = session.session?.user.id + const email = session.session?.user?.email if (!userId) { console.log("User not logged in") @@ -27,7 +34,7 @@ export const start = async (): Promise => { const contributeBody: Partial = { payloadId: data.payload_id, contributorId: userId, - jwt: user?.session?.access_token, + jwt: session.session?.access_token, supabaseProject: import.meta.env.VITE_SUPABASE_URL, apiKey: import.meta.env.VITE_SUPABASE_ANON_KEY, bucket: import.meta.env.VITE_BUCKET_ID, diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index 04f8839ca4..b524cf7d30 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -5,7 +5,9 @@ import { getQueueCount, getSubmittedContribution, getUserQueuePosition, - queryAllowance + queryAllowance, + queryContributions, + queryUserContribution } from "$lib/supabase/queries.ts" import { supabase } from "$lib/supabase/client.ts" import type { AllowanceState, ContributionState } from "$lib/stores/state.svelte.ts" @@ -116,3 +118,31 @@ export const getAllowanceState = async (userId: string | undefined): Promise { + const { data, error } = await queryContributions() + if (error || !data) return undefined + + console.log(data) + + return data +} + +export const getUserContribution = async (hash: string) => { + const { data, error } = await queryUserContribution(hash) + if (error || !data) + return { + id: "5515a415-a96e-4ec6-9cca-05d7cac203f0", + user_name: "Lukas", + avatar_url: "https://avatars.githubusercontent.com/u/36674091?v=4", + seq: 12, + payload_id: "d6533ce0-17e3-48d1-b738-f915d009d5c9", + public_key: + "2d2d2d2d2d424547494e20504750205055424c4943204b455920424c4f434b2d2d2d2d2d0a0a786a4d455a7572793268594a4b7759424241486152773842415164416b544d3875744d6b6562554d653173666a5a4c5877367054446d4d7457665259526d4c560a3849504f50464c4e466d78316132467a4c6d3535596d56795a30426e625746706243356a6232334367775151466767414b77495a415155435a7572327a5149620a4167494c4351495641414557466945452b486957756b356a46307a412b6c477158726b2f61467831412f554143676b5158726b2f61467831412f58597867442b0a4a4170655675726872596676615659754170545550354e68666238732b616a796353517967365953417863412f32313163634a555477632f5251525a62582b750a62344b6f4e496465786f346a6b5262306b59716c2b3441480a3d3171504d0a2d2d2d2d2d454e4420504750205055424c4943204b455920424c4f434b2d2d2d2d2d0a", + signature: + "2d2d2d2d2d424547494e20504750205349474e4544204d4553534147452d2d2d2d2d0a486173683a205348413235360a0a305f5f5f5f5f5f30202d2030303030303030302d303030302d303030302d303030302d303030303030303030303030202d2064363533336365302d313765332d343864312d623733382d663931356430303964356339202d20383562323331323233363138633665343830373963393365356335623439373366383030623733323530313337326564333231383139316464356434366138300a2d2d2d2d2d424547494e20504750205349474e41545552452d2d2d2d2d0a0a776e5545415259494142305749515434654a6136546d4d58544d4436556170657554396f58485544395155435a7572327a51414b435242657554396f584855440a39555737415143654943472f76686534483674556775476d416135683248444d4252356a776b6c59715647596e2f5375346744384474536f2f634f77426768360a485657726f393842526e324d317952704d684279745839513847767876676b3d0a3d4d4235480a2d2d2d2d2d454e4420504750205349474e41545552452d2d2d2d2d0a", + public_key_hash: "174874cebccadc3e169c8826b00171268200050e428427d0757937d2cf407d36" + } + + return data +} diff --git a/ceremony/src/lib/supabase/queries.ts b/ceremony/src/lib/supabase/queries.ts index 98abb0b185..163c50bb6b 100644 --- a/ceremony/src/lib/supabase/queries.ts +++ b/ceremony/src/lib/supabase/queries.ts @@ -66,3 +66,23 @@ export const queryAllowance = async () => { return { data, error } } + +export const queryContributions = async () => { + const { data, error } = await supabase + .from("users_contribution") + .select("public_key_hash, user_name, avatar_url") + + return { data, error } +} + +export const queryUserContribution = async (hash: string) => { + const { data, error } = await supabase + .from("users_contribution") + .select("*") + .eq("public_key_hash", hash) + .single() + + console.log(data) + + return { data, error } +} diff --git a/ceremony/src/routes/auth/dive/+page.svelte b/ceremony/src/routes/auth/dive/+page.svelte index 8c1b7c7b3f..d78488d3f4 100644 --- a/ceremony/src/routes/auth/dive/+page.svelte +++ b/ceremony/src/routes/auth/dive/+page.svelte @@ -5,8 +5,8 @@ import { supabase } from "$lib/supabase/client.ts" import H1 from "$lib/components/typography/H1.svelte" // import Spinner from "$lib/components/Spinner.svelte" -type AuthProviders = "github" | "google" | "twitter" -const providers: Array = ["github", "google", "twitter"] +type AuthProviders = "github" | "google" +const providers: Array = ["github", "google"] async function diveIn(provider: AuthProviders) { const { data, error } = await supabase.auth.signInWithOAuth({ diff --git a/ceremony/src/routes/contributions/+page.svelte b/ceremony/src/routes/contributions/+page.svelte new file mode 100644 index 0000000000..9b70a60e69 --- /dev/null +++ b/ceremony/src/routes/contributions/+page.svelte @@ -0,0 +1,249 @@ + + +{#if contributions} +
+
+
+ {#each contributions as contribution, index } + {#if index !== 0} +
+ {/if} + + + {contribution.user_name} + + {/each} +
+
+ + Next contribution... +
+

+ +

+
+
+{:else} + +{/if} \ No newline at end of file diff --git a/ceremony/src/routes/contributions/[hash]/+page.svelte b/ceremony/src/routes/contributions/[hash]/+page.svelte new file mode 100644 index 0000000000..be02749564 --- /dev/null +++ b/ceremony/src/routes/contributions/[hash]/+page.svelte @@ -0,0 +1,62 @@ + + +
+ {#await getUserContribution($page.params.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/dictionary.txt b/dictionary.txt index 5be2925591..e8bec2a048 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -116,6 +116,7 @@ Lahcen Layerzero Lightshift Livenesses +Lukas MARKETCAP Mathjax Maxblocks From c08a073c0b7616e1b93e616d25cfd9391e96d12b Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 14:21:40 +0200 Subject: [PATCH 02/17] chore(ceremony): add word --- dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dictionary.txt b/dictionary.txt index e8bec2a048..34e39d44c8 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -107,6 +107,7 @@ Jemalloc Joye KEYPAIR Karel +Kaylei Keplr Keybase Kubat From 06d81501d22ac220d856878f94711b502f4f46e2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 14:31:28 +0200 Subject: [PATCH 03/17] fix(ceremony): add guard --- .../routes/contributions/[hash]/+page.svelte | 101 +++++++++--------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/ceremony/src/routes/contributions/[hash]/+page.svelte b/ceremony/src/routes/contributions/[hash]/+page.svelte index be02749564..edc183d05f 100644 --- a/ceremony/src/routes/contributions/[hash]/+page.svelte +++ b/ceremony/src/routes/contributions/[hash]/+page.svelte @@ -1,62 +1,65 @@ -
- {#await getUserContribution($page.params.hash)} - - {:then contribution} - {#if contribution} -
-
-

Contributor: {contribution.user_name}

-
- -
+{#if $page.params.hash} +
+ {#await getUserContribution($page.params.hash)} + + {:then contribution} + {#if contribution} +
-

Public key

-
{decodeHexString(contribution.public_key)}
- +

Contributor: {contribution.user_name}

-
-

Signature

-
{decodeHexString(contribution.signature)}
- +
+
+

Public key

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

Signature

+
{decodeHexString(contribution.signature)}
+ +
-
- {/if} - {/await} -
\ No newline at end of file + {/if} + {/await} +
+{/if} \ No newline at end of file From 6897ab91bcf2c2506e2a537fc0cd13ba70093f1e Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 14:46:56 +0200 Subject: [PATCH 04/17] fix(ceremony): can't use dynamic route due to prerender --- ceremony/src/lib/supabase/index.ts | 15 +- ceremony/src/lib/supabase/queries.ts | 2 - .../src/routes/contributions/+page.svelte | 318 +++++------------- .../routes/contributions/[hash]/+page.svelte | 65 ---- .../routes/contributions/hash/+page.svelte | 30 ++ 5 files changed, 122 insertions(+), 308 deletions(-) delete mode 100644 ceremony/src/routes/contributions/[hash]/+page.svelte create mode 100644 ceremony/src/routes/contributions/hash/+page.svelte diff --git a/ceremony/src/lib/supabase/index.ts b/ceremony/src/lib/supabase/index.ts index b524cf7d30..dfb23267ad 100644 --- a/ceremony/src/lib/supabase/index.ts +++ b/ceremony/src/lib/supabase/index.ts @@ -129,20 +129,9 @@ export const getContributions = async () => { } export const getUserContribution = async (hash: string) => { + console.log(hash) const { data, error } = await queryUserContribution(hash) - if (error || !data) - return { - id: "5515a415-a96e-4ec6-9cca-05d7cac203f0", - user_name: "Lukas", - avatar_url: "https://avatars.githubusercontent.com/u/36674091?v=4", - seq: 12, - payload_id: "d6533ce0-17e3-48d1-b738-f915d009d5c9", - public_key: - "2d2d2d2d2d424547494e20504750205055424c4943204b455920424c4f434b2d2d2d2d2d0a0a786a4d455a7572793268594a4b7759424241486152773842415164416b544d3875744d6b6562554d653173666a5a4c5877367054446d4d7457665259526d4c560a3849504f50464c4e466d78316132467a4c6d3535596d56795a30426e625746706243356a6232334367775151466767414b77495a415155435a7572327a5149620a4167494c4351495641414557466945452b486957756b356a46307a412b6c477158726b2f61467831412f554143676b5158726b2f61467831412f58597867442b0a4a4170655675726872596676615659754170545550354e68666238732b616a796353517967365953417863412f32313163634a555477632f5251525a62582b750a62344b6f4e496465786f346a6b5262306b59716c2b3441480a3d3171504d0a2d2d2d2d2d454e4420504750205055424c4943204b455920424c4f434b2d2d2d2d2d0a", - signature: - "2d2d2d2d2d424547494e20504750205349474e4544204d4553534147452d2d2d2d2d0a486173683a205348413235360a0a305f5f5f5f5f5f30202d2030303030303030302d303030302d303030302d303030302d303030303030303030303030202d2064363533336365302d313765332d343864312d623733382d663931356430303964356339202d20383562323331323233363138633665343830373963393365356335623439373366383030623733323530313337326564333231383139316464356434366138300a2d2d2d2d2d424547494e20504750205349474e41545552452d2d2d2d2d0a0a776e5545415259494142305749515434654a6136546d4d58544d4436556170657554396f58485544395155435a7572327a51414b435242657554396f584855440a39555737415143654943472f76686534483674556775476d416135683248444d4252356a776b6c59715647596e2f5375346744384474536f2f634f77426768360a485657726f393842526e324d317952704d684279745839513847767876676b3d0a3d4d4235480a2d2d2d2d2d454e4420504750205349474e41545552452d2d2d2d2d0a", - public_key_hash: "174874cebccadc3e169c8826b00171268200050e428427d0757937d2cf407d36" - } + if (error || !data) return undefined return data } diff --git a/ceremony/src/lib/supabase/queries.ts b/ceremony/src/lib/supabase/queries.ts index 163c50bb6b..d87f7f3f91 100644 --- a/ceremony/src/lib/supabase/queries.ts +++ b/ceremony/src/lib/supabase/queries.ts @@ -82,7 +82,5 @@ export const queryUserContribution = async (hash: string) => { .eq("public_key_hash", hash) .single() - console.log(data) - return { data, error } } diff --git a/ceremony/src/routes/contributions/+page.svelte b/ceremony/src/routes/contributions/+page.svelte index 9b70a60e69..d42302f8d5 100644 --- a/ceremony/src/routes/contributions/+page.svelte +++ b/ceremony/src/routes/contributions/+page.svelte @@ -1,217 +1,46 @@ -{#if contributions} -
-
-
- {#each contributions as contribution, index } - {#if index !== 0} -
- {/if} - - - {contribution.user_name} - - {/each} -
-
- - Next contribution... +{#if hash} + {#await getUserContribution(hash)} + + {:then contribution} + {#if contribution} +
+
+

Contributor: {contribution.user_name}

+
+ +
+
+

Public key

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

Signature

+
{decodeHexString(contribution.signature)}
+ +
+
+
+ {/if} + {/await} + {:else} + {#if contributions} +
+
+
+ {#each contributions as contribution, index } + {#if index !== 0} +
+ {/if} + + + {contribution.user_name} + + {/each} +
+
+ + Next contribution... +
+

+ +

-

- -

-
-{:else} - -{/if} \ No newline at end of file + {:else} + + {/if} +{/if} diff --git a/ceremony/src/routes/contributions/[hash]/+page.svelte b/ceremony/src/routes/contributions/[hash]/+page.svelte deleted file mode 100644 index edc183d05f..0000000000 --- a/ceremony/src/routes/contributions/[hash]/+page.svelte +++ /dev/null @@ -1,65 +0,0 @@ - - -{#if $page.params.hash} -
- {#await getUserContribution($page.params.hash)} - - {:then contribution} - {#if contribution} -
-
-

Contributor: {contribution.user_name}

-
- -
-
-

Public key

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

Signature

-
{decodeHexString(contribution.signature)}
- -
-
-
- {/if} - {/await} -
-{/if} \ No newline at end of file diff --git a/ceremony/src/routes/contributions/hash/+page.svelte b/ceremony/src/routes/contributions/hash/+page.svelte new file mode 100644 index 0000000000..48c34efa8f --- /dev/null +++ b/ceremony/src/routes/contributions/hash/+page.svelte @@ -0,0 +1,30 @@ + From e8b9711dbd3ed95e5ec0f1d4718efda2b0ed0235 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 14:49:33 +0200 Subject: [PATCH 05/17] fix(ceremony): add toast import and remove old route --- .../src/routes/contributions/+page.svelte | 1 + .../routes/contributions/hash/+page.svelte | 30 ------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 ceremony/src/routes/contributions/hash/+page.svelte diff --git a/ceremony/src/routes/contributions/+page.svelte b/ceremony/src/routes/contributions/+page.svelte index d42302f8d5..b353603e33 100644 --- a/ceremony/src/routes/contributions/+page.svelte +++ b/ceremony/src/routes/contributions/+page.svelte @@ -7,6 +7,7 @@ import H4 from "$lib/components/typography/H4.svelte" import { page } from "$app/stores" import H2 from "$lib/components/typography/H2.svelte" import Button from "$lib/components/Button.svelte" +import { toast } from "svelte-sonner" let hash = $derived($page.url.searchParams.get("hash")) diff --git a/ceremony/src/routes/contributions/hash/+page.svelte b/ceremony/src/routes/contributions/hash/+page.svelte deleted file mode 100644 index 48c34efa8f..0000000000 --- a/ceremony/src/routes/contributions/hash/+page.svelte +++ /dev/null @@ -1,30 +0,0 @@ - From 6417a61393896b0b7f00728490980d0f75eb5ef1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 19 Sep 2024 16:14:38 +0200 Subject: [PATCH 06/17] feat(ceremony): save progress --- .../src/lib/components/Contribution.svelte | 85 ++++++++++++++ .../src/lib/components/Contributions.svelte | 48 ++++++++ ceremony/src/lib/layout/Navbar/index.svelte | 4 + ceremony/src/lib/supabase/queries.ts | 1 + .../src/routes/contributions/+page.svelte | 109 +----------------- ceremony/static/images/ceremony.png | 3 + 6 files changed, 146 insertions(+), 104 deletions(-) create mode 100644 ceremony/src/lib/components/Contribution.svelte create mode 100644 ceremony/src/lib/components/Contributions.svelte create mode 100644 ceremony/static/images/ceremony.png diff --git a/ceremony/src/lib/components/Contribution.svelte b/ceremony/src/lib/components/Contribution.svelte new file mode 100644 index 0000000000..65c2fcc3c5 --- /dev/null +++ b/ceremony/src/lib/components/Contribution.svelte @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + +{#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 new file mode 100644 index 0000000000..ef688e5f3a --- /dev/null +++ b/ceremony/src/lib/components/Contributions.svelte @@ -0,0 +1,48 @@ + +{#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/layout/Navbar/index.svelte b/ceremony/src/lib/layout/Navbar/index.svelte index 19dd503b55..d38d1f9ab2 100644 --- a/ceremony/src/lib/layout/Navbar/index.svelte +++ b/ceremony/src/lib/layout/Navbar/index.svelte @@ -54,10 +54,12 @@ let loggedIn = $derived(!!user.session?.user.id)