diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/About.svelte | 14 | ||||
| -rw-r--r-- | src/components/Account.svelte | 58 | ||||
| -rw-r--r-- | src/components/AppHeader.svelte | 60 | ||||
| -rw-r--r-- | src/components/Avatar.svelte | 16 | ||||
| -rw-r--r-- | src/components/Balance.svelte | 22 | ||||
| -rw-r--r-- | src/components/Event.svelte | 12 | ||||
| -rw-r--r-- | src/components/Footer.svelte | 5 | ||||
| -rw-r--r-- | src/components/Invoice.svelte | 4 | ||||
| -rw-r--r-- | src/components/Items.svelte | 246 | ||||
| -rw-r--r-- | src/components/LandingHeader.svelte | 16 | ||||
| -rw-r--r-- | src/components/LandingHero.svelte | 2 | ||||
| -rw-r--r-- | src/components/Lnurlp.svelte | 17 | ||||
| -rw-r--r-- | src/components/Lnurlw.svelte | 19 | ||||
| -rw-r--r-- | src/components/LocationsMap.svelte | 206 | ||||
| -rw-r--r-- | src/components/Mnemonic.svelte | 16 | ||||
| -rw-r--r-- | src/components/Numpad.svelte | 17 | ||||
| -rw-r--r-- | src/components/Pinpad.svelte | 5 | ||||
| -rw-r--r-- | src/components/Request.svelte | 39 | ||||
| -rw-r--r-- | src/components/WalletPass.svelte | 65 |
19 files changed, 649 insertions, 190 deletions
diff --git a/src/components/About.svelte b/src/components/About.svelte index 0087e350..01ff4c7c 100644 --- a/src/components/About.svelte +++ b/src/components/About.svelte @@ -90,6 +90,18 @@ > {@html $t("about.locations.description")} </p> - <LocationsMap {locations} /> + <!-- <LocationsMap {locations} /> --> + + <a href="/map"> + <div class="relative"> + <img src="/map.png" class="mx-auto" /> + + <button + class="bg-black text-white border border-4 rounded-full px-6 py-2 font-bold hover:bg-secondary absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2 text-2xl" + > + {$t("about.locations.viewMap")} + </button> + </div> + </a> </div> {/if} diff --git a/src/components/Account.svelte b/src/components/Account.svelte new file mode 100644 index 00000000..96aa1964 --- /dev/null +++ b/src/components/Account.svelte @@ -0,0 +1,58 @@ +<script> + import Icon from "$comp/Icon.svelte"; + import Balance from "$comp/Balance.svelte"; + import { t } from "$lib/translations"; + + export let user, rate, account, last; + let { name, seed, balance, id } = account; + $: type = seed ? "Savings" : "Cash"; + + $: refresh(account); + let refresh = (a) => ({ seed, balance, id } = a); + + let setAccount = () => (document.cookie = `aid=${id}; path=/; max-age=86400`); +</script> + +<a + href={`/payments`} + class="block space-y-2 border-black py-4" + class:border-b-8={!last} + on:click={setAccount} +> + <div class="flex"> + <Balance {balance} {user} {rate} /> + <a href={`/payments`} class="contents" on:click={setAccount}> + <button class="ml-auto flex gap-1 mb-auto pb-4 pl-4"> + <Icon icon="clock" style="w-8 my-auto" /> + </button> + </a> + <a href={`/account/${id}`} class="contents"> + <button class="flex gap-1 mb-auto pb-4 pl-4"> + <Icon icon="settings" style="w-8 my-auto" /> + </button> + </a> + </div> + + <div class="flex justify-center w-full text-xl gap-2"> + <a href={`/invoice`} class="contents" on:click={setAccount}> + <button class="py-5 px-6 hover:opacity-80 flex grow rounded-2xl"> + <div class="mx-auto flex gap-2"> + <Icon icon="receive" style="w-8" /> + <div class="my-auto">{$t("user.dashboard.receive")}</div> + </div> + </button> + </a> + + <a href={`/send`} class="contents grow" on:click={setAccount}> + <button + type="button" + class="py-5 px-6 hover:opacity-80 flex grow rounded-2xl" + > + <div class="mx-auto flex gap-1"> + <Icon icon="send" style="w-8" /> + <div class="my-auto">{$t("user.dashboard.send")}</div> + </div> + </button> + </a> + </div> +</a> diff --git a/src/components/AppHeader.svelte b/src/components/AppHeader.svelte index 731f0260..9dd37d7e 100644 --- a/src/components/AppHeader.svelte +++ b/src/components/AppHeader.svelte @@ -7,11 +7,9 @@ import { loading, t } from "$lib/translations"; import { page } from "$app/stores"; - export let data; + export let user, subject; - let { subject, user } = data; - $: update(data); - let update = (data) => ({ subject, user } = data); + $: if (!subject) subject = user; let menuButtons; $: if (user) @@ -19,15 +17,15 @@ { key: "nav.settings", icon: "settings", - href: `/${user.username}/settings`, + href: `/settings`, }, { key: "nav.support", icon: "support", href: `/support` }, - { key: "nav.map", icon: "map", href: `/${user.username}/map` }, - { - key: "nav.messages", - icon: "message", - href: `/${user.username}/messages`, - }, + { key: "nav.map", icon: "map", href: `/map` }, + // { + // key: "nav.messages", + // icon: "message", + // href: `/messages`, + // }, { key: "nav.merch", icon: "shop", href: `https://coinosmerch.com` }, { key: "nav.signOut", icon: "logout", href: `/logout` }, ]; @@ -38,8 +36,10 @@ $banner?.id && $banner.id === subject.id ? `url(${$banner.src})` : subject?.banner - ? `url(/api/public/${subject.banner}.webp)` - : undefined; + ? subject.banner.includes(":") + ? `url(${subject.banner})` + : `url(/api/public/${subject.banner}.webp)` + : undefined; $: $page && (showMenu = false); </script> @@ -51,7 +51,7 @@ > <nav class="flex justify-end items-center space-x-4 p-5"> {#if user} - <a href={`/${user.username}`}> + <a href={`/${user.username}`} data-sveltekit-preload-code="eager"> <button class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page .url.pathname === `/${user.username}` @@ -62,17 +62,18 @@ </a> <a href={`/${user.username}/receive`}> <button - class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page - .url.pathname === `/${user.username}/receive` + class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page.url.pathname.includes( + 'invoice', + ) ? 'opacity-100' : 'opacity-70 hover:opacity-80'}" - ><Icon icon="numpad" style="mx-auto w-6 sm:w-8" /> + ><Icon icon="receive" style="mx-auto w-6 sm:w-8" /> </button> </a> - <a href={`/${user.username}/payments`}> + <a href={`/payments`} data-sveltekit-preload-code="eager"> <button class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page - .url.pathname === `/${user.username}/payments` + .url.pathname === `/payments` ? 'opacity-100' : 'opacity-70 hover:opacity-80'} relative" ><Icon icon="clock" style="mx-auto w-6 sm:w-8" /> @@ -90,7 +91,7 @@ {/if} </button> </a> - <a href={`/send`}> + <a href={`/send`} data-sveltekit-preload-code="eager"> <button class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page .url.pathname === `/send` @@ -103,8 +104,7 @@ <OutClick on:outclick={() => (showMenu = false)}> <button class="bg-white p-2 rounded-full w-12 h-12 sm:w-16 sm:h-16 drop-shadow-xl border border-black/10 {$page - .url.pathname === `/${user.username}` || - $page.url.pathname === `/${user.username}/settings` || + .url.pathname === `/settings` || $page.url.pathname === `/support` ? 'opacity-100' : `opacity-70 hover:opacity-80 ${ @@ -122,7 +122,7 @@ <ul class="space-y-5 w-48"> {#each menuButtons as { href, icon, key }} <li> - <a {href} data-sveltekit-prefetch="off"> + <a {href} data-sveltekit-preload-code="eager"> <button class="flex justify-center items-center font-semibold hover:opacity-80" ><Icon {icon} style="mr-2 w-6 sm:w-8" /> {$t(key)} @@ -132,7 +132,7 @@ {/each} </ul> <hr class="my-4" /> - <a href="/" + <a href="/?stay=true" ><img src="/images/logo.svg" alt="Coinos" class="w-32" /></a > </div> @@ -146,11 +146,13 @@ </a> {/if} </nav> - <div - class="absolute md:w-[64px] md:mx-auto lg:left-[154px] xl:left-[194px] left-[calc(50vw-64px)] -bottom-[64px] z-30" - > - <Avatar user={subject} /> - </div> + {#if subject} + <div + class="absolute md:w-[64px] md:mx-auto lg:left-[154px] xl:left-[194px] left-[calc(50vw-64px)] -bottom-[64px] z-30" + > + <Avatar user={subject} /> + </div> + {/if} </header> {/if} diff --git a/src/components/Avatar.svelte b/src/components/Avatar.svelte index 227200d7..e91285da 100644 --- a/src/components/Avatar.svelte +++ b/src/components/Avatar.svelte @@ -8,14 +8,15 @@ export let disabled = false; $: s = size.toString(); - $: link = user.anon ? `/${user.pubkey}` : `/${user.username}`; + $: link = user?.anon ? `/${user.pubkey}` : `/${user.username}`; - $: src = - ($avatar?.id && $avatar.id === user.id && $avatar.src) || - "/api/public/" + - (user.profile - ? user.profile + ".webp" - : "punks/" + punk(user.pubkey || user.id || "aa")); + let base = "/api/public"; + $: profile = user?.profile ? `${base}/${user.profile}.webp` : user?.picture; + $: fallback = `${base}/punks/` + punk(user.pubkey || user.id || "aa"); + $: tmp = $avatar?.id && $avatar.id === user.id && $avatar.src; + $: src = tmp || profile || fallback; + + let handle = () => (src = fallback); </script> <a href={link} class:pointer-events-none={disabled}> @@ -26,6 +27,7 @@ {src} class="w-full h-full object-cover object-center overflow-hidden" alt={user.username} + on:error={handle} /> </div> </a> diff --git a/src/components/Balance.svelte b/src/components/Balance.svelte index 4d5ac6bd..0cc27068 100644 --- a/src/components/Balance.svelte +++ b/src/components/Balance.svelte @@ -6,33 +6,33 @@ import { t } from "$lib/translations"; let show; - export let user, rate; + export let user, rate, balance; </script> {#if show && user.haspin && $pin?.length !== 6} <Pin cancel={() => (show = false)} /> {/if} -<div class="space-y-2"> +<div> {#if user.haspin && !$pin} <button - class="flex gap-2 text-xl rounded-2xl border py-5 px-6 hover:opacity-80 bg-black text-white font-bold" - on:click={() => (show = true)} - > - <Icon icon="eye" style="w-8 invert my-auto" /> - <div class="my-auto">{$t("user.showBalance")}</div></button + on:click|preventDefault={() => (show = true)} + class="flex gap-2 text-xl" > + <Icon icon="eye-off" style="w-8 my-auto" /> + <div class="my-auto">{$t("user.showBalance")}</div> + </button> {:else} - <div class="text-5xl font-bold tabular-nums"> + <div class="text-4xl font-bold tabular-nums"> {#if isNaN(rate)} <div class="text-gray-200">—</div> {:else} - {f((user.balance * rate) / sats, user.currency)} + {f((balance * rate) / sats, user.currency)} {/if} </div> - <div class="text-secondary text-2xl"> - ⚡️{s(user.balance)} + <div class="text-secondary text-xl"> + ⚡️{s(balance)} </div> {/if} </div> diff --git a/src/components/Event.svelte b/src/components/Event.svelte index d3a6c0af..640b9e68 100644 --- a/src/components/Event.svelte +++ b/src/components/Event.svelte @@ -14,12 +14,12 @@ return diff > d ? Math.round(diff / d) + "d" : diff > h - ? Math.round(diff / h) + "h" - : diff > m - ? Math.round(diff / m) + "m" - : diff > 2 - ? diff + "s" - : "now"; + ? Math.round(diff / h) + "h" + : diff > m + ? Math.round(diff / m) + "m" + : diff > 2 + ? diff + "s" + : "now"; }; let w; diff --git a/src/components/Footer.svelte b/src/components/Footer.svelte index d70c013c..ca711d7f 100644 --- a/src/components/Footer.svelte +++ b/src/components/Footer.svelte @@ -4,7 +4,10 @@ import { t } from "$lib/translations"; const followLinks = [ - { url: "https://twitter.com/coinoswallet", titleID: "twitter" }, + { + url: "nostr:nprofile1qqst4qyeqenw7zm0fwjsty68h6cnys5jre2xd8ngqpjv5a2j26s78fspz4mhxue69uhhyetvv9ujucm0d9hx7uewd9hsgwx239", + titleID: "nostr", + }, { url: "https://t.me/coinoswallet", titleID: "telegram" }, { url: "https://linktr.ee/coinos.io", titleID: "linktree" }, ]; diff --git a/src/components/Invoice.svelte b/src/components/Invoice.svelte index ba436649..3298dfe5 100644 --- a/src/components/Invoice.svelte +++ b/src/components/Invoice.svelte @@ -19,7 +19,7 @@ <b >{f( ($invoice.amount * $invoice.rate) / sats, - $invoice.currency + $invoice.currency, )}</b > {sat($invoice.amount)} @@ -27,7 +27,7 @@ </div> </div> <div class="mx-auto my-auto flex gap-2"> - <a href={`/${invoice.user.username}/invoice/${$invoice.id}/tip`}> + <a href={`/invoice/${$invoice.id}/tip`}> <button class="rounded-full border py-2 px-4 font-bold hover:opacity-80 w-32" > diff --git a/src/components/Items.svelte b/src/components/Items.svelte new file mode 100644 index 00000000..2916721d --- /dev/null +++ b/src/components/Items.svelte @@ -0,0 +1,246 @@ +<script> + import { t } from "$lib/translations"; + import { btc, f, sat, post } from "$lib/utils"; + import { browser } from "$app/environment"; + import { goto, invalidate } from "$app/navigation"; + import { fade } from "svelte/transition"; + import { cubicIn } from "svelte/easing"; + import { flip } from "svelte/animate"; + import { + dndzone, + SHADOW_ITEM_MARKER_PROPERTY_NAME, + SOURCES, + TRIGGERS, + } from "svelte-dnd-action"; + import DeleteItem from "$comp/DeleteItem.svelte"; + import Icon from "$comp/Icon.svelte"; + + export let subject, user, items, rate, currency, total; + + let flipDurationMs = 200; + let dropTargetStyle = {}; + + let dragDisabled = + subject?.id !== user?.id || (browser && window.innerWidth < 768); + + let deleting; + let del = (item) => { + deleting = item; + }; + + function handleConsider(e) { + const { + items: newItems, + info: { source, trigger }, + } = e.detail; + items = newItems; + if (source === SOURCES.KEYBOARD && trigger === TRIGGERS.DRAG_STOPPED) + reset(); + } + + async function handleFinalize(e) { + const { + items: newItems, + info: { source }, + } = e.detail; + items = newItems; + if (source === SOURCES.POINTER) reset(); + + if (subject?.id === user?.id) { + await post("/api/items/sort", { items }); + invalidate("app:items"); + } + } + + function startDrag(e) { + e.preventDefault(); + dragDisabled = false; + } + + function handleKeyDown(e) { + if ((e.key === "Enter" || e.key === " ") && dragDisabled) + dragDisabled = false; + } + + $: if (total > 0 && browser) { + let payButton = document.querySelector("#payButton"); + if (payButton) payButton.addEventListener("click", checkout); + } + + let checkout = async () => { + let invoice = { + type: "lightning", + amount: btc(total, rate), + currency, + items: items.filter((i) => i.quantity > 0), + prompt: subject.prompt, + memoPrompt: subject.memoPrompt, + rate, + }; + + let { id } = await post(`/invoice`, { + invoice, + user: { username: subject.username }, + }); + + if (invoice.memoPrompt) { + return goto(`/invoice/${id}/memo`); + } + goto(`/invoice/${id}`); + }; + + let reset = () => + (dragDisabled = + user?.username !== subject?.username || window.innerWidth < 768); +</script> + +<svelte:window on:resize={reset} /> + +{#if deleting} + <DeleteItem bind:item={deleting} /> +{/if} + +{#if items.length} + <h2 class="text-2xl font-bold">Select items</h2> +{/if} +<div + class="grid sm:grid-cols-2 gap-4 pb-20" + use:dndzone={{ items, flipDurationMs, dropTargetStyle, dragDisabled }} + on:consider={handleConsider} + on:finalize={handleFinalize} +> + {#each items as i (i.id)} + <button + type="button" + class="w-full text-center cursor-pointer hover:opacity-80 mb-auto" + on:click={() => i.quantity++} + > + <div class="relative w-full h-64 overflow-hidden rounded-xl"> + {#if i[SHADOW_ITEM_MARKER_PROPERTY_NAME]} + <div + in:fade={{ duration: 200, easing: cubicIn }} + class="custom-shadow-item" + /> + {:else if i.image} + <img + src={`/api/public/${i.image}.webp`} + alt={i.name} + class="mx-auto object-cover h-full w-full" + /> + {:else} + <div + class="bg-gradient-to-r from-primary to-gradient mb-4 cursor-pointer hover:opacity-80 w-full h-full" + alt="Banner" + /> + {/if} + {#if user?.username === subject.username} + <div class="flex gap-2 justify-center absolute top-2 right-2"> + <button type="button" on:click|stopPropagation={() => {}}> + <a href={`/items/${i.id}`}> + <button + class="bg-black rounded-full w-12 h-12 bg-opacity-40 hover:bg-opacity-100" + > + <Icon icon="edit" style="w-8 mx-auto invert" /> + </button> + </a> + </button> + <button + class="bg-black rounded-full w-12 h-12 bg-opacity-40 hover:bg-opacity-100" + on:click|stopPropagation={() => del(i)} + > + <Icon icon="trash" style="w-8 mx-auto invert" /> + </button> + <button + type="button" + on:click|stopPropagation={() => {}} + class="sm:hidden" + on:mousedown={startDrag} + on:touchstart={startDrag} + on:keydown={handleKeyDown} + > + <a href={`/items/${i.id}`}> + <button + class="bg-black rounded-full w-12 h-12 bg-opacity-40 hover:bg-opacity-100" + > + <Icon icon="move" style="w-8 mx-auto invert" /> + </button> + </a> + </button> + </div> + {/if} + </div> + <div class="bg-white rounded-xl py-2"> + <div class="flex text-left gap-2"> + <div class="overflow-hidden space-y-1"> + <div class="text-2xl break-words">{i.name}</div> + <div class="flex gap-2"> + <div class="font-semibold text-lg"> + {f(i.price, currency)} + </div> + <div class="text-secondary my-auto"> + {sat(btc(i.price, rate))} + </div> + </div> + </div> + <div class="flex gap-1 ml-auto mb-auto justify-around tabular-nums"> + {#if i.quantity} + <button + type="button" + on:click|stopPropagation={() => i.quantity > 0 && i.quantity--} + > + <Icon icon="minus" style="w-10 min-w-10" /> + </button> + {/if} + <div class="text-2xl my-auto text-center"> + {#if i.quantity}{i.quantity}{:else}—{/if} + </div> + {#if i.quantity} + <button + type="button" + on:click|stopPropagation={() => i.quantity++} + > + <Icon icon="plus" style="w-10 min-w-10" /> + </button> + {/if} + </div> + </div> + </div> + </button> + {/each} +</div> + +<div + class="fixed inset-x-0 mx-auto flex bottom-16" + class:static={!items.length} +> + {#if total > 0} + <button + class="rounded-2xl py-5 px-6 font-bold hover:bg-neutral-700 flex bg-black text-white mx-auto" + on:click={checkout} + > + <div class="mx-auto flex"> + <div class="my-auto text-2xl"> + {$t("user.dashboard.checkout")} + {f(total, currency)} + <span class="text-base"> + {sat(btc(total, rate), currency)} + </span> + </div> + </div> + </button> + {/if} +</div> + +<style> + .custom-shadow-item { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + visibility: visible; + background: #333; + opacity: 0.5; + margin: 0; + } +</style> diff --git a/src/components/LandingHeader.svelte b/src/components/LandingHeader.svelte index d1094a1d..72913999 100644 --- a/src/components/LandingHeader.svelte +++ b/src/components/LandingHeader.svelte @@ -19,22 +19,22 @@ </script> <header - class="w-full lg:w-5/6 py-5 mx-auto fixed md:sticky z-10 top-0 bg-white/90" + class="w-full lg:w-5/6 py-5 mx-auto fixed sticky z-10 top-0 bg-white/90" bind:this={header} > - <nav class="block xl:flex flex-wrap justify-between items-center"> + <nav class="block lg:flex justify-between items-center"> <div - class="flex justify-start md:justify-center items-center md:space-x-10" + class="flex justify-start lg:justify-center items-center lg:space-x-10" > <a href="/" on:click={() => scroll(header)}> - <Icon icon="logo" style="hidden md:block mb-5 xl:mb-0" /> - <Icon icon="logo" style="block md:hidden ml-5 w-48" /> + <Icon icon="logo" style="hidden lg:block mb-5 xl:mb-0" /> + <Icon icon="logo" style="block lg:hidden ml-5 w-48" /> </a> </div> <!-- desktop nav --> <div - class="hidden space-x-10 md:flex flex-wrap justify-center items-center font-bold" + class="hidden space-x-10 lg:flex justify-center items-center font-bold" > {#if $page.url.pathname === "/"} <button class="hover:opacity-80" on:click={() => scroll(howItWorks)} @@ -76,13 +76,13 @@ <!-- mobile nav --> <button - class="block md:hidden absolute top-[34.5px] right-10 z" + class="block lg:hidden absolute top-[34.5px] right-10 z" on:click={() => (showMobileMenu = !showMobileMenu)} ><Icon icon={!showMobileMenu ? "menu" : "close"} /> </button> <div - class="container w-full px-10 md:hidden absolute top-0 {showMobileMenu + class="container w-full px-10 lg:hidden absolute top-0 {showMobileMenu ? 'right-0' : 'right-[-100%]'} transition-all ease-in-out duration-300 h-[100vh] w-full bg-white" > diff --git a/src/components/LandingHero.svelte b/src/components/LandingHero.svelte index 43223499..154944fa 100644 --- a/src/components/LandingHero.svelte +++ b/src/components/LandingHero.svelte @@ -1,4 +1,5 @@ <script> + import { focus } from "$lib/utils"; import { goto } from "$app/navigation"; import Icon from "$comp/Icon.svelte"; import Image from "$comp/Image.svelte"; @@ -29,6 +30,7 @@ <div class="flex justify-center"> <a href="/register"> <button + use:focus class="bg-black text-white border rounded-full px-6 py-2 font-bold hover:opacity-80" > {$t("nav.startInSeconds")} diff --git a/src/components/Lnurlp.svelte b/src/components/Lnurlp.svelte index 6785061a..5f075607 100644 --- a/src/components/Lnurlp.svelte +++ b/src/components/Lnurlp.svelte @@ -5,9 +5,10 @@ import Spinner from "$comp/Spinner.svelte"; import { pin } from "$lib/store"; - export let data, form, send; + export let data, form, send, comment; let { currency } = data.user; - let { minSendable, maxSendable, callback, metadata, rates } = data; + let { minSendable, maxSendable, commentAllowed, callback, metadata, rates } = + data; $: rate = rates[currency]; @@ -16,7 +17,7 @@ let submit = () => (loading = true); </script> -<div class="container px-4 mt-20 max-w-xl mx-auto"> +<div class="container px-4 mt-20 max-w-xl mx-auto space-y-2"> <div class="text-center mb-8"> {#each JSON.parse(metadata) as m} <div> @@ -45,6 +46,16 @@ <input name="callback" value={callback} type="hidden" /> <input name="pin" value={$pin} type="hidden" /> + {#if commentAllowed} + <textarea + name="comment" + placeholder={$t("payments.message")} + class="w-full p-4 border rounded-xl h-32 text-xl" + bind:value={comment} + autocapitalize="none" + /> + {/if} + <div class="flex w-full"> <button bind:this={send} diff --git a/src/components/Lnurlw.svelte b/src/components/Lnurlw.svelte index b83e648f..2062c849 100644 --- a/src/components/Lnurlw.svelte +++ b/src/components/Lnurlw.svelte @@ -1,4 +1,5 @@ <script> + import { sats, f, s } from "$lib/utils"; import { t } from "$lib/translations"; import { enhance } from "$app/forms"; import Numpad from "$comp/Numpad.svelte"; @@ -18,10 +19,11 @@ } = data; $: rate = rates[currency]; - let amount = Math.round(maxWithdrawable / 1000), + let amount = Math.round(minWithdrawable / 1000), loading; let submit = () => (loading = true); + $: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2)); </script> <div class="container px-4 mt-20 max-w-xl mx-auto"> @@ -39,7 +41,20 @@ </div> {/if} - <Numpad bind:amount {currency} bind:rate /> + {#if minWithdrawable === maxWithdrawable} + <div class="text-center font-bold text-2xl mb-4"> + <div> + {f(amountFiat, currency)} + </div> + <div> + <span class="text-secondary font-normal text-xl" + >⚡️{`${s(amount)}`}</span + > + </div> + </div> + {:else} + <Numpad bind:amount {currency} bind:rate /> + {/if} <form action="?/withdraw" method="POST" use:enhance on:submit={submit}> <input name="amount" value={amount} type="hidden" /> diff --git a/src/components/LocationsMap.svelte b/src/components/LocationsMap.svelte index b41b1a73..4c3532b3 100644 --- a/src/components/LocationsMap.svelte +++ b/src/components/LocationsMap.svelte @@ -3,7 +3,7 @@ import { browser } from "$app/environment"; import Icon from "$comp/Icon.svelte"; import Popup from "$comp/Popup.svelte"; - import { shuffleArray } from "$lib/utils"; + import { back } from "$lib/utils"; import "maplibre-gl/dist/maplibre-gl.css"; @@ -11,6 +11,8 @@ let map; let mapContainer, mapWrapper; let markers = []; + let search; + let clearSearch = (e) => (search = ""); let currentIndex = -1; let timeout; @@ -47,13 +49,32 @@ } }; + $: list = search + ? markers.filter((m) => + m.tags.name.toLowerCase().includes(search.toLowerCase()), + ) + : inview; + + let scroll = () => { + const el = document.querySelector(".selected"); + if (el) + el.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "nearest", + }); + }; + + let selected; function select(m) { + selected = m; stopFlying(); currentIndex = inview.indexOf(m); - flyToMarker(m); + flyToMarker(m, 500); } - async function flyToMarker(marker) { + async function flyToMarker(marker, duration = 1500) { + if (!marker) return; map.flyTo({ zoom: 12, center: marker.getLngLat(), @@ -61,24 +82,25 @@ easing: function (t) { return 1 - Math.pow(1 - t, 3); }, - duration: 3000, + duration, }); - await new Promise((r) => setTimeout(r, 3000)); + await new Promise((r) => setTimeout(r, duration)); marker.getElement().click(); - await new Promise((r) => setTimeout(r, 1500)); + updateLabelVisibility(); + await new Promise((r) => setTimeout(r, 2500)); if (!timeout) return; - - map.flyTo({ - zoom: 10.5, - center: marker.getLngLat(), - essential: true, - easing: function (t) { - return 1 - Math.pow(1 - t, 3); - }, - duration: 1500, - }); + // + // map.flyTo({ + // zoom: 10.5, + // center: marker.getLngLat(), + // essential: true, + // easing: function (t) { + // return 1 - Math.pow(1 - t, 3); + // }, + // duration: 1000, + // }); } let toggle = () => { @@ -86,6 +108,9 @@ else startFlying(); }; + let toggleList = () => (showList = !showList); + let showList; + let currentPopup; function startFlying() { currentIndex++; @@ -94,10 +119,31 @@ if (currentIndex >= inview.length) currentIndex = 0; flyToMarker(inview[currentIndex]); - timeout = setTimeout(startFlying, 6000); + timeout = setTimeout(startFlying, 4000); + } + + function debounce(func, delay) { + let timeout; + let immediate = true; + + return function (...args) { + const context = this; + + if (immediate) { + func.apply(context, args); + immediate = false; + } + + clearTimeout(timeout); + + timeout = setTimeout(() => { + immediate = true; + }, delay); + }; } function stopFlying() { + updateLabelVisibility(); if (!timeout) return; timeout = clearTimeout(timeout); @@ -106,12 +152,12 @@ } map.jumpTo({ center: map.getCenter(), zoom: map.getZoom() }); - map.off("moveend"); // Remove moveend listener if set + map.off("moveend"); } let inview = []; - function updateLabelVisibility() { + let updateLabelVisibility = debounce(() => { inview = []; if (!map) return; let zoom = map.getZoom(); @@ -127,9 +173,9 @@ } inview = inview.sort((a, b) => a.tags.name.localeCompare(b.tags.name)); - shuffleArray(inview); - } + }, 200); + let locationMarkers = {}; let popups = {}; let counter = 0; @@ -155,12 +201,12 @@ let popupContainer = document.createElement("div"); - let popup = new Popup({ + new Popup({ target: popupContainer, props: { tags }, }); - let marker = new maplibre.Marker({ color: "#F7931A" }) + let marker = new maplibre.Marker({ color: "#F7931A", scale: 0.65 }) .setLngLat([lon, lat]) .setPopup(new maplibre.Popup().setDOMContent(popupContainer)) .addTo(map); @@ -171,29 +217,23 @@ let p = marker.getPopup(); popups[marker.id] = p; p.setDOMContent(popupContainer); + setTimeout(() => { + selected = marker; + setTimeout(scroll, 10); + }, 50); p.on("close", () => { + selected = undefined; delete popups[marker.id]; }); }); marker.tags = tags; + locationMarkers[location.id] = marker; markers.push(marker); }); updateLabelVisibility(); - - let observer = new IntersectionObserver( - (entries, observer) => { - entries.forEach((entry) => { - if (entry.isIntersecting) startFlying(); - else stopFlying(); - }); - }, - { threshold: 0.5 } - ); - - observer.observe(mapContainer); }); map.on("mousedown", stopFlying); @@ -214,45 +254,69 @@ onDestroy(() => map && map.remove()); </script> -<div class="container mx-auto p-2 space-y-5"> - <div class="flex w-full h-[60vh]" id="map" bind:this={mapWrapper}> - <div - id="map-container" - class="mx-auto h-full w-full z-0" - bind:this={mapContainer} - /> - <div class="relative"> - <div class="flex absolute flex top-2 right-2 gap-2"> - <button - class="rounded-full border-2 border-black bg-white w-10 h-10" - on:click={toggle} - > - {#if timeout} - <Icon icon="pause" style="w-4 m-auto" /> - {:else} - <Icon icon="play" style="w-4 m-auto" /> - {/if} - </button> - <button - class="rounded-full border-2 border-black bg-white w-10 h-10" - on:click={full} - > - <Icon icon="full" style="w-4 m-auto" /> - </button> +<div class="w-screen h-dvh flex" id="map" bind:this={mapWrapper}> + <div + id="map-container" + class="mx-auto h-full w-full z-0" + bind:this={mapContainer} + /> + <div class="absolute flex top-2 left-2 gap-2"> + <button + class="rounded-full border-2 border-black bg-white w-10 h-10" + on:click={back} + > + <Icon icon="arrow-left" style="w-4 m-auto" /> + </button> + </div> + <div class="relative"> + {#if !showList} + <div + class="space-y-1 text-sm w-[300px] max-w-[calc(100vw*0.5)] h-[300px] max-h-[calc(100vh*0.4)] overflow-y-scroll p-4 bg-opacity-90 bg-primary absolute right-4 bottom-8 rounded-2xl shadow text-ellipsis overflow-x-hidden" + > + <div class="relative mb-4 sticky top-0 bg-primary z-10"> + <input bind:value={search} class="w-full" /> + <div class="flex gap-1 absolute right-6 top-3"> + {#if search} + <button on:click={clearSearch}> + <Icon icon="close" style="w-8" /> + </button> + {:else} + <Icon icon="search" style="w-8" /> + {/if} + </div> + </div> + + {#each list as marker, i} + <button + on:click={() => select(marker)} + class:font-bold={selected === marker} + class:selected={selected === marker} + class="block whitespace-nowrap text-ellipsis text-left w-full overflow-hidden" + > + {marker.tags.name} + </button> + {/each} </div> + {/if} + <div class="absolute flex top-2 right-2 gap-2"> + <button + class="rounded-full border-2 border-black bg-white w-10 h-10" + on:click={toggleList} + > + <Icon icon="list" style="w-4 m-auto" /> + </button> + <button + class="rounded-full border-2 border-black bg-white w-10 h-10" + on:click={toggle} + > + {#if timeout} + <Icon icon="pause" style="w-4 m-auto" /> + {:else} + <Icon icon="play" style="w-4 m-auto" /> + {/if} + </button> </div> </div> - - <!-- <div class="hidden lg:grid grid-cols-3 justify-items-center"> --> - <!-- {#each inview as m} --> - <!-- <button --> - <!-- on:click={() => select(m)} --> - <!-- class="text-left" --> - <!-- class:font-bold={m.id === inview[currentIndex]?.id} --> - <!-- id={`marker-${m.id}`}>{m.tags.name}</button --> - <!-- > --> - <!-- {/each} --> - <!-- </div> --> </div> <style> diff --git a/src/components/Mnemonic.svelte b/src/components/Mnemonic.svelte new file mode 100644 index 00000000..41e81d9a --- /dev/null +++ b/src/components/Mnemonic.svelte @@ -0,0 +1,16 @@ +<script> + export let mnemonic; +</script> + +<div class="flex w-full border p-4 rounded-2xl h-full"> + <div + class="text-secondary grid grid-flow-col grid-rows-6 sm:grid-rows-none grid-cols-2 sm:grid-cols-3 sm:grid-flow-row gap-x-8 gap-y-2 justify-center whitespace-nowrap m-auto" + > + {#each mnemonic.split(" ") as w, i} + <div> + <span class="select-none text-black">{i + 1}.</span> + <span>{@html w === "-" ? "—" : w}</span> + </div> + {/each} + </div> +</div> diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 9119999f..5b9aaa01 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -1,7 +1,7 @@ <script> import Left from "$comp/Left.svelte"; import Icon from "$comp/Icon.svelte"; - import { f, s, focus, post, warning, sat, sats } from "$lib/utils"; + import { f, s, focus, warning, sat, sats } from "$lib/utils"; import { t } from "$lib/translations"; export let amount, @@ -183,8 +183,8 @@ e.key === "Enter" && (e.preventDefault() || submit.click()); </script> -<div class="flex justify-center items-center mb-3 px-3"> - <div class="space-y-5"> +<div class="flex justify-center items-center"> + <div class="space-y-5 w-full"> <div class="text-center"> <div class="text-5xl md:text-6xl font-semibold tracking-widest flex justify-center" @@ -206,11 +206,11 @@ </div> <div class="mt-2"> <span class="text-secondary mr-1" - >{fiat ? sat(amount) : f(amountFiat, currency)}</span + >{fiat ? "⚡️" + s(amount) : f(amountFiat, currency)}</span > <button type="button" - on:click={() => { + on:click|preventDefault|stopPropagation={() => { if (fiat) { amount = parseInt((amountFiat / (rate / sats)).toFixed(0)); } else { @@ -225,13 +225,13 @@ </div> </div> - <div class="grid grid-cols-3 gap-2 w-[300px] mx-auto"> + <div class="grid grid-cols-3 gap-2 w-full mx-auto"> {#each numPad as value} {#if value === arrow} <button type="button" class="bg-primary rounded-xl py-4 px-8 font-semibold active:bg-black active:text-white flex justify-center items-center hover:opacity-80" - on:click={() => handleInput(value)} + on:click|preventDefault|stopPropagation={() => handleInput(value)} > <Left /> </button> @@ -239,7 +239,8 @@ <button type="button" class="bg-primary rounded-xl py-4 px-8 font-semibold active:bg-black active:text-white hover:opacity-80" - on:click={() => handleInput(value)}>{value}</button + on:click|preventDefault|stopPropagation={() => handleInput(value)} + >{value}</button > {/if} {/each} diff --git a/src/components/Pinpad.svelte b/src/components/Pinpad.svelte index 337b53d4..585a7942 100644 --- a/src/components/Pinpad.svelte +++ b/src/components/Pinpad.svelte @@ -73,7 +73,7 @@ <button type="button" class="bg-primary rounded-xl py-4 px-8 font-semibold active:bg-black active:text-white flex justify-center items-center hover:opacity-80" - on:click={() => handleInput(value)} + on:click|stopPropagation|preventDefault={() => handleInput(value)} > <Left /> </button> @@ -81,7 +81,8 @@ <button type="button" class="bg-primary rounded-xl py-4 px-8 font-semibold active:bg-black active:text-white hover:opacity-80" - on:click={() => handleInput(value)}>{value}</button + on:click|stopPropagation|preventDefault={() => handleInput(value)} + >{value}</button > {/if} {/each} diff --git a/src/components/Request.svelte b/src/components/Request.svelte deleted file mode 100644 index c085f9e2..00000000 --- a/src/components/Request.svelte +++ /dev/null @@ -1,39 +0,0 @@ -<script> - import { t } from "$lib/translations"; - import { fly } from "svelte/transition"; - - import Avatar from "$comp/Avatar.svelte"; - import Icon from "$comp/Icon.svelte"; - - import { request, requestRedirect } from "$lib/store"; - import { page } from "$app/stores"; - - export let user; - - $requestRedirect = $page.url.pathname; -</script> - -{#if $request} - <div class="fixed bottom-0 border-t w-full p-4 bg-white z-50" in:fly> - <div class="flex flex-wrap md:flex-nowrap max-w-xl mx-auto gap-2"> - <div class="my-auto mx-auto"> - <div class="flex"> - <Avatar user={$request.requester} size={12} /> - <h1 class="my-auto"> - <b>{$request.requester.username}</b> - {$t("payments.readyToPay")} - </h1> - </div> - </div> - <div class="mx-auto my-auto flex gap-2"> - <a href={`/${user.username}/receive/${$request.id}`}> - <button - class="rounded-full border py-2 px-4 font-bold hover:opacity-80 w-32" - > - {$t("payments.invoice")} - </button> - </a> - </div> - </div> - </div> -{/if} diff --git a/src/components/WalletPass.svelte b/src/components/WalletPass.svelte new file mode 100644 index 00000000..75c94f34 --- /dev/null +++ b/src/components/WalletPass.svelte @@ -0,0 +1,65 @@ +<script> + import { focus } from "$lib/utils"; + import { t } from "$lib/translations"; + import Icon from "$comp/Icon.svelte"; + export let cancel, password, submit; + let revealPassword; +</script> + +<div + class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-20" +> + <div + class="relative top-1/3 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white space-y-5" + > + <h1 class="text-center text-2xl font-semibold"> + {$t("payments.enterWalletPass")} + </h1> + <form on:submit|preventDefault={submit}> + <div class="relative mb-5"> + {#if revealPassword} + <input + name="password" + type="text" + required + bind:value={password} + autocapitalize="none" + use:focus + /> + {:else} + <input + name="password" + type="password" + required + bind:value={password} + autocapitalize="none" + use:focus + /> + {/if} + <button + type="button" + on:click={() => (revealPassword = !revealPassword)} + class="absolute right-5 top-1/2" + > + <Icon icon={revealPassword ? "eye" : "eye-off"} /> + </button> + </div> + <div class="w-full flex justify-center gap-2"> + <button + type="button" + class="border rounded-2xl font-semibold mx-auto py-5 px-6 hover:opacity-80 mx-auto grow" + on:click={cancel} + on:keydown={cancel} + > + <div class="my-auto">Cancel</div> + </button> + <button + type="submit" + class="border rounded-2xl font-semibold mx-auto py-5 px-6 hover:opacity-80 mx-auto grow" + > + <div class="my-auto">Submit</div> + </button> + </div> + </form> + </div> +</div> |
