-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ceremony): contributors (#2980)
- Loading branch information
Showing
26 changed files
with
590 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<script lang="ts"> | ||
import { callJoinQueue } from "$lib/supabase" | ||
import { toast } from "svelte-sonner" | ||
import type { ContributorState } from "$lib/stores/state.svelte.ts" | ||
import Button from "$lib/components/Button.svelte" | ||
type Props = { | ||
contributor: ContributorState | ||
} | ||
let { contributor }: Props = $props() | ||
let words: Array<string> = $state(new Array(6).fill("")) | ||
let code = $derived(normalizeString(words)) | ||
let codeLoading = $state(false) | ||
function handlePaste(e: ClipboardEvent): void { | ||
e.preventDefault() | ||
const pastedText: string = e.clipboardData?.getData("text") || "" | ||
const pastedWords: Array<string> = pastedText.split(/\s+/).slice(0, 6) | ||
words = [...pastedWords, ...new Array(6 - pastedWords.length).fill("")] | ||
} | ||
function normalizeString(words: Array<string>): string { | ||
return words | ||
.map(word => word.trim().toLowerCase()) | ||
.join("") | ||
.replace(/[^a-z0-9]/gi, "") | ||
} | ||
async function handleCodeJoin() { | ||
codeLoading = true | ||
try { | ||
console.log(code) | ||
const codeOk = await callJoinQueue(code) | ||
if (codeOk) { | ||
contributor.setAllowanceState("hasRedeemed") | ||
toast.success("Code successfully redeemed") | ||
} else { | ||
toast.error("The code is not valid") | ||
} | ||
} catch (error) { | ||
console.error("Error redeeming code:", error) | ||
toast.error("An error occurred while redeeming the code") | ||
} finally { | ||
codeLoading = false | ||
words = new Array(6).fill("") | ||
} | ||
} | ||
</script> | ||
|
||
|
||
<div class="flex gap-2 max-w-4xl flex-wrap justify-center mb-8"> | ||
{#each words as word, index} | ||
<input | ||
bind:value={words[index]} | ||
onpaste={handlePaste} | ||
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" | ||
style="--tw-ring-color: transparent;" | ||
/> | ||
{#if index !== words.length - 1} | ||
<div class="text-union-accent-500"><p>-</p></div> | ||
{/if} | ||
{/each} | ||
</div> | ||
<Button loading={codeLoading} type="button" onclick={handleCodeJoin}> | ||
USE CODE | ||
</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<script lang="ts"> | ||
import { getUserContribution } from "$lib/supabase" | ||
import Spinner from "$lib/components/Spinner.svelte" | ||
import H2 from "$lib/components/typography/H2.svelte" | ||
import Button from "$lib/components/Button.svelte" | ||
import { toast } from "svelte-sonner" | ||
import { page } from "$app/stores" | ||
type Props = { | ||
hash: string | ||
} | ||
let { hash }: Props = $props() | ||
function hexToUint8Array(hexString: string) { | ||
return new Uint8Array(hexString.match(/.{1,2}/g)?.map(byte => Number.parseInt(byte, 16)) || []) | ||
} | ||
function uint8ArrayToUtf8(bytes: Uint8Array) { | ||
return new TextDecoder().decode(bytes) | ||
} | ||
function decodeHexString(hexString: string) { | ||
return uint8ArrayToUtf8(hexToUint8Array(hexString)) | ||
} | ||
async function copyToClipboard(text: string, label: string) { | ||
try { | ||
await navigator.clipboard.writeText(text) | ||
toast.success(`Copied ${label}!`) | ||
} catch (err) { | ||
console.error("Failed to copy text: ", err) | ||
toast.error(`Failed to copy ${label} to clipboard.`) | ||
} | ||
} | ||
const imagePath = "/images/ceremony.png" | ||
let imageUrl = $derived(new URL(imagePath, $page.url.origin).href) | ||
</script> | ||
|
||
<svelte:head> | ||
<meta property="og:type" content="Website"/> | ||
<meta property="og:site_name" content="Union Ceremony"/> | ||
<meta property="og:locale" content="en"/> | ||
<meta property="og:image:type" content="image/png"/> | ||
<meta property="og:image:width" content="1200"/> | ||
<meta property="og:image:height" content="675"/> | ||
<meta name="twitter:card" content="summary_large_image"/> | ||
<meta name="twitter:site" content="@union_build"/> | ||
<meta name="twitter:creator" content="@union_build"/> | ||
<meta property="og:image" content={imageUrl}/> | ||
<meta property="og:image:secure_url" content={imageUrl}/> | ||
<meta name="twitter:image" content={imageUrl}/> | ||
</svelte:head> | ||
|
||
{#await getUserContribution(hash)} | ||
<Spinner class="size-5 text-union-accent-500"/> | ||
{:then contribution} | ||
{#if contribution} | ||
<div class="flex flex-col items-start gap-1 px-3 py-2"> | ||
<div> | ||
<H2>Contributor: <span class="!text-union-accent-500">{contribution.user_name}</span></H2> | ||
</div> | ||
|
||
<div class="flex flex-col gap-4"> | ||
<div> | ||
<H2 class="mb-2">Public key</H2> | ||
<pre class="text-white whitespace-pre-wrap bg-neutral-800 p-4 mb-4">{decodeHexString(contribution.public_key)}</pre> | ||
<Button onclick={() => copyToClipboard(decodeHexString(contribution.public_key), "public key")}>Copy | ||
Public | ||
key | ||
</Button> | ||
</div> | ||
|
||
<div> | ||
<H2 class="mb-2">Signature</H2> | ||
<pre class="text-white whitespace-pre-wrap bg-neutral-800 p-4 mb-4">{decodeHexString(contribution.signature)}</pre> | ||
<Button onclick={() => copyToClipboard(decodeHexString(contribution.signature), "signature")}>Copy | ||
Signature | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
{/if} | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts"> | ||
import Spinner from "$lib/components/Spinner.svelte" | ||
import Text from "$lib/components/typography/Text.svelte" | ||
import { getContributions } from "$lib/supabase" | ||
let intervalId: NodeJS.Timeout | number | ||
let contributions = $state() | ||
async function loadContributions() { | ||
contributions = await getContributions() | ||
} | ||
$effect(() => { | ||
loadContributions() | ||
intervalId = setInterval(loadContributions, 1000 * 5) | ||
return () => { | ||
if (intervalId) clearInterval(intervalId) | ||
} | ||
}) | ||
</script> | ||
{#if contributions} | ||
|
||
<div class="flex flex-col items-center h-svh overflow-y-auto pb-24 pt-36 w-full"> | ||
<div class="w-full h-48 bg-gradient-to-b via-black from-black to-transparent absolute top-0"></div> | ||
<div class="flex flex-col items-center max-w-md"> | ||
<div class="rounded-full border-[2px] h-8 w-8"></div> | ||
<div class="h-24 w-[2px] bg-white"></div> | ||
{#each contributions as contribution, index } | ||
<a href="/contributions?hash={contribution.public_key_hash}" class="flex items-center gap-4 w-full"> | ||
|
||
<Text>{(index + 1) * 10}M</Text> | ||
<div class="text-white flex gap-1 items-center border-white border px-3 py-2 w-full"> | ||
<img class="size-7" src={contribution.avatar_url} alt=""> | ||
<Text class="uppercase max-w-48 truncate">{contribution.user_name}</Text> | ||
</div> | ||
</a> | ||
{#if index !== contributions.length - 1} | ||
<div class="h-12 w-[2px] bg-white"></div> | ||
{/if} | ||
{/each} | ||
</div> | ||
</div> | ||
{:else} | ||
<Spinner class="size-5 text-union-accent-500"/> | ||
{/if} |
Oops, something went wrong.