diff options
| author | Adam Soltys <[email protected]> | 2024-12-22 23:31:39 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-22 23:31:39 -0800 |
| commit | 747e8d82fbfa88351a99e8d5cb5712ba4b6e4000 (patch) | |
| tree | ede02749dc1eb059f8aa2d09953405d039b8602f | |
| parent | ab82b405be6f2665c43518b4ad253becc8ab7430 (diff) | |
| download | coinos-ui-747e8d82fbfa88351a99e8d5cb5712ba4b6e4000.tar.gz coinos-ui-747e8d82fbfa88351a99e8d5cb5712ba4b6e4000.zip | |
fix sendmax
4 files changed, 30 insertions, 13 deletions
diff --git a/src/routes/(app)/invoice/[id]/+page.svelte b/src/routes/(app)/invoice/[id]/+page.svelte index 350d2398..fdb180ef 100644 --- a/src/routes/(app)/invoice/[id]/+page.svelte +++ b/src/routes/(app)/invoice/[id]/+page.svelte @@ -115,11 +115,9 @@ let setMemo = async (e) => { e.preventDefault(); e.stopPropagation(); - console.log("setting"); settingMemo = false; invoice.memo = memo; - console.log("MEMO", invoice.memo); await update(); }; 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" /> diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index c78ba008..9b971f2f 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -24,8 +24,8 @@ export async function load({ cookies, params: { id }, parent }) { const rates = await getRates(); const rate = rates[user.currency]; const invoiceRate = rates[invoice.currency]; - const { balance } = await get(`/account/${aid}`, auth(cookies)); + const { balance } = await get(`/account/${aid}`, auth(cookies)); return { balance, invoice, user, rate, invoiceRate }; } |
