From d67ed89c382165fdc26f9817702cdf8090ae826a Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Tue, 6 Aug 2024 18:26:53 +0000 Subject: [PATCH] web/donate: refactor, implement logic for choosing donation periodicity --- .../donate/DonateOptionsCard.svelte | 72 +++++++++---------- .../components/donate/DonationOption.svelte | 4 +- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/web/src/components/donate/DonateOptionsCard.svelte b/web/src/components/donate/DonateOptionsCard.svelte index 95f152a6..1ce362f9 100644 --- a/web/src/components/donate/DonateOptionsCard.svelte +++ b/web/src/components/donate/DonateOptionsCard.svelte @@ -11,65 +11,65 @@ import { donate } from "$lib/env"; - let customInputValue: number; + let customInputValue: number | null; - const donateStripe = (amount: number) => { - const url = new URL(donate.stripe); - url.searchParams.set("__prefilled_amount", (amount * 100).toString()); - window.open(url, "_blank"); + type Processor = "stripe" | "liberapay"; + let processor: Processor = "stripe"; + + const donationMethods: Record void> = { + stripe: (amount: number) => { + const url = new URL(donate.stripe); + url.searchParams.set("__prefilled_amount", amount.toString()); + window.open(url, "_blank"); + }, + liberapay: (amount: number) => { + const url = new URL(donate.liberapay); + url.searchParams.set("currency", "USD"); + url.searchParams.set("period", "monthly"); + url.searchParams.set("amount", (amount / 100).toString()); + window.open(url, "_blank"); + } }; - const donateLibera = (amount: number) => { - const url = new URL(donate.liberapay); - url.searchParams.set("currency", "USD"); - url.searchParams.set("period", "monthly"); - url.searchParams.set("amount", (amount / 100).toString()); - window.open(url, "_blank"); - }; - - const toClipboard = (text: string) => navigator.clipboard.writeText(text); + const send = (amount: number) => { + return donationMethods[processor](amount); + }
- -
- donateStripe(5)} - > + - donateStripe(10)} - > + - donateStripe(15)} - > + - donateStripe(30)} - > +
diff --git a/web/src/components/donate/DonationOption.svelte b/web/src/components/donate/DonationOption.svelte index c0988c90..9692ee91 100644 --- a/web/src/components/donate/DonationOption.svelte +++ b/web/src/components/donate/DonationOption.svelte @@ -1,7 +1,9 @@