aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/pay
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-22 23:31:39 -0800
committerAdam Soltys <[email protected]>2024-12-22 23:31:39 -0800
commit747e8d82fbfa88351a99e8d5cb5712ba4b6e4000 (patch)
treeede02749dc1eb059f8aa2d09953405d039b8602f /src/routes/(app)/pay
parentab82b405be6f2665c43518b4ad253becc8ab7430 (diff)
downloadcoinos-ui-747e8d82fbfa88351a99e8d5cb5712ba4b6e4000.tar.gz
coinos-ui-747e8d82fbfa88351a99e8d5cb5712ba4b6e4000.zip
fix sendmax
Diffstat (limited to 'src/routes/(app)/pay')
-rw-r--r--src/routes/(app)/pay/[username]/[...amount]/+page.server.ts5
-rw-r--r--src/routes/(app)/pay/[username]/[...amount]/+page.svelte34
2 files changed, 29 insertions, 10 deletions
diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
index 431310a3..812b97ec 100644
--- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
@@ -33,7 +33,7 @@ export async function load({ cookies, params, parent }) {
auth(cookies),
);
- const { balance } = await get(`/account/${user.id}`, auth(cookies));
+ const { balance } = await get(`/account/${user.id}`, auth(cookies));
redirect(307, `/invoice/${id}`);
}
@@ -45,8 +45,11 @@ export const actions = {
default: async ({ cookies, request }) => {
let id;
const body = await fd(request);
+ console.log("BODY", body);
const { amount, rate, prompt, type, username } = body;
+ console.log("AMT", amount);
+
try {
({ id } = await post(
"/invoice",
diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.svelte b/src/routes/(app)/pay/[username]/[...amount]/+page.svelte
index 7e696b22..618504ca 100644
--- a/src/routes/(app)/pay/[username]/[...amount]/+page.svelte
+++ b/src/routes/(app)/pay/[username]/[...amount]/+page.svelte
@@ -1,10 +1,12 @@
<script>
+ import { tick } from "svelte";
import { t } from "$lib/translations";
- import { goto } from "$app/navigation";
+ import { goto, invalidateAll } from "$app/navigation";
import { enhance } from "$app/forms";
import Numpad from "$comp/Numpad.svelte";
import { page } from "$app/stores";
import { f, loc, fail, post, s, sat, sats } from "$lib/utils";
+ import { applyAction, deserialize } from "$app/forms";
let { data, form } = $props();
@@ -13,16 +15,25 @@
let locale = $derived(loc(subject));
let next = $state();
- let initialAmount = form?.amount || data.amount;
+ let initialAmount = $derived(form?.amount || data.amount);
let amount = $state(initialAmount);
let fiat = $state(!initialAmount);
+ let formElement = $state();
- let setMax = (e) => {
+ let setMax = async (e) => {
e.preventDefault();
- fiat = false;
- amount = user.balance;
- console.log("OK YES", amount);
- next.click();
+ let body = new FormData(formElement);
+ body.set("fiat", false);
+ body.set("amount", user.balance);
+
+ const response = await fetch(formElement.action, {
+ method: "POST",
+ body,
+ });
+
+ const result = deserialize(await response.text());
+ if (result.type === "success") await invalidateAll();
+ applyAction(result);
};
</script>
@@ -35,8 +46,13 @@
<div class="container px-4 mt-20 max-w-xl mx-auto space-y-2">
<Numpad bind:amount bind:fiat {currency} {locale} {rate} submit={next} />
- <form method="POST" use:enhance class="flex gap-2 justify-center">
- <input name="amount" value={amount} type="hidden" />
+ <form
+ method="POST"
+ use:enhance
+ class="flex gap-2 justify-center"
+ bind:this={formElement}
+ >
+ <input name="amount" bind:value={amount} type="hidden" />
<input name="rate" value={rate} type="hidden" />
<input name="username" value={subject.username} type="hidden" />
<input name="prompt" value={subject.prompt} type="hidden" />