web/donate: update logic for sending custom amounts

This commit is contained in:
dumbmoron 2024-08-06 18:28:54 +00:00
parent d67ed89c38
commit c90a01daf9
No known key found for this signature in database

View file

@ -11,6 +11,7 @@
import { donate } from "$lib/env";
let customInput: HTMLInputElement;
let customInputValue: number | null;
type Processor = "stripe" | "liberapay";
@ -34,6 +35,15 @@
const send = (amount: number) => {
return donationMethods[processor](amount);
}
const sendCustom = () => {
if (!customInput.reportValidity()) {
return;
}
const amount = Number(customInputValue) * 100;
send(amount);
}
</script>
<div id="donation-box">
@ -79,13 +89,16 @@
type="number"
min="2"
max="10000"
step=".01"
required
placeholder="custom amount (from $2)"
bind:this={customInput}
bind:value={customInputValue}
on:keydown={(e) => e.key === 'Enter' && sendCustom()}
/>
<button
id="donation-custom-submit"
on:click={() => donateStripe(customInputValue)}
on:click={sendCustom}
>
<IconArrowRight />
</button>