mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
web/donate: refactor, implement logic for choosing donation periodicity
This commit is contained in:
parent
1077797aae
commit
d67ed89c38
2 changed files with 39 additions and 37 deletions
|
@ -11,65 +11,65 @@
|
||||||
|
|
||||||
import { donate } from "$lib/env";
|
import { donate } from "$lib/env";
|
||||||
|
|
||||||
let customInputValue: number;
|
let customInputValue: number | null;
|
||||||
|
|
||||||
const donateStripe = (amount: number) => {
|
type Processor = "stripe" | "liberapay";
|
||||||
const url = new URL(donate.stripe);
|
let processor: Processor = "stripe";
|
||||||
url.searchParams.set("__prefilled_amount", (amount * 100).toString());
|
|
||||||
window.open(url, "_blank");
|
const donationMethods: Record<Processor, (_: number) => 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 send = (amount: number) => {
|
||||||
const url = new URL(donate.liberapay);
|
return donationMethods[processor](amount);
|
||||||
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);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="donation-box">
|
<div id="donation-box">
|
||||||
<div id="donation-types">
|
<div id="donation-types">
|
||||||
<button id="donation-type-once" class="donation-type selected">
|
<button
|
||||||
|
id="donation-type-once"
|
||||||
|
class="donation-type"
|
||||||
|
on:click={() => processor = 'stripe'}
|
||||||
|
class:selected={processor === 'stripe'}
|
||||||
|
>
|
||||||
<div class="donation-type-icon"><IconCoin /></div>
|
<div class="donation-type-icon"><IconCoin /></div>
|
||||||
<div class="donation-title">one-time donation</div>
|
<div class="donation-title">one-time donation</div>
|
||||||
<div class="donation-subtitle">processed by stripe</div>
|
<div class="donation-subtitle">processed by stripe</div>
|
||||||
</button>
|
</button>
|
||||||
<button id="donation-type-monthly" class="donation-type">
|
<button
|
||||||
|
id="donation-type-monthly"
|
||||||
|
class="donation-type"
|
||||||
|
on:click={() => processor = 'liberapay'}
|
||||||
|
class:selected={processor === 'liberapay'}
|
||||||
|
>
|
||||||
<div class="donation-type-icon"><IconCalendarRepeat /></div>
|
<div class="donation-type-icon"><IconCalendarRepeat /></div>
|
||||||
<div class="donation-title">monthly donation</div>
|
<div class="donation-title">monthly donation</div>
|
||||||
<div class="donation-subtitle">processed by liberapay</div>
|
<div class="donation-subtitle">processed by liberapay</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="donation-options">
|
<div id="donation-options">
|
||||||
<DonationOption
|
<DonationOption price={5} desc="cup of coffee" {send}>
|
||||||
price={5}
|
|
||||||
desc="cup of coffee"
|
|
||||||
click={() => donateStripe(5)}
|
|
||||||
>
|
|
||||||
<IconCup />
|
<IconCup />
|
||||||
</DonationOption>
|
</DonationOption>
|
||||||
<DonationOption
|
<DonationOption price={10} desc="full size pizza" {send}>
|
||||||
price={10}
|
|
||||||
desc="full size pizza"
|
|
||||||
click={() => donateStripe(10)}
|
|
||||||
>
|
|
||||||
<IconPizza />
|
<IconPizza />
|
||||||
</DonationOption>
|
</DonationOption>
|
||||||
<DonationOption
|
<DonationOption price={15} desc="full lunch" {send}>
|
||||||
price={15}
|
|
||||||
desc="full lunch"
|
|
||||||
click={() => donateStripe(15)}
|
|
||||||
>
|
|
||||||
<IconToolsKitchen2 />
|
<IconToolsKitchen2 />
|
||||||
</DonationOption>
|
</DonationOption>
|
||||||
<DonationOption
|
<DonationOption price={30} desc="two lunches" {send}>
|
||||||
price={30}
|
|
||||||
desc="two lunches"
|
|
||||||
click={() => donateStripe(30)}
|
|
||||||
>
|
|
||||||
<IconToolsKitchen2 />
|
<IconToolsKitchen2 />
|
||||||
</DonationOption>
|
</DonationOption>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let price: number;
|
export let price: number;
|
||||||
export let desc: string;
|
export let desc: string;
|
||||||
export let click: () => void;
|
export let send: (amount: number) => void;
|
||||||
|
|
||||||
|
const click = () => send(price * 100);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button class="donation-option" on:click={click}>
|
<button class="donation-option" on:click={click}>
|
||||||
|
|
Loading…
Reference in a new issue