mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/donate: update logic for sending custom amounts
This commit is contained in:
parent
d67ed89c38
commit
c90a01daf9
1 changed files with 14 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
import { donate } from "$lib/env";
|
import { donate } from "$lib/env";
|
||||||
|
|
||||||
|
let customInput: HTMLInputElement;
|
||||||
let customInputValue: number | null;
|
let customInputValue: number | null;
|
||||||
|
|
||||||
type Processor = "stripe" | "liberapay";
|
type Processor = "stripe" | "liberapay";
|
||||||
|
@ -34,6 +35,15 @@
|
||||||
const send = (amount: number) => {
|
const send = (amount: number) => {
|
||||||
return donationMethods[processor](amount);
|
return donationMethods[processor](amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sendCustom = () => {
|
||||||
|
if (!customInput.reportValidity()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const amount = Number(customInputValue) * 100;
|
||||||
|
send(amount);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="donation-box">
|
<div id="donation-box">
|
||||||
|
@ -79,13 +89,16 @@
|
||||||
type="number"
|
type="number"
|
||||||
min="2"
|
min="2"
|
||||||
max="10000"
|
max="10000"
|
||||||
|
step=".01"
|
||||||
required
|
required
|
||||||
placeholder="custom amount (from $2)"
|
placeholder="custom amount (from $2)"
|
||||||
|
bind:this={customInput}
|
||||||
bind:value={customInputValue}
|
bind:value={customInputValue}
|
||||||
|
on:keydown={(e) => e.key === 'Enter' && sendCustom()}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
id="donation-custom-submit"
|
id="donation-custom-submit"
|
||||||
on:click={() => donateStripe(customInputValue)}
|
on:click={sendCustom}
|
||||||
>
|
>
|
||||||
<IconArrowRight />
|
<IconArrowRight />
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue