From e2fcfdc4d608e260bb596952d8b54a7dcef05258 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 21 Dec 2024 10:24:04 -0800 Subject: send max for internal payments --- .../(app)/send/bitcoin/[address]/+page.svelte | 13 +++------- src/routes/(app)/send/invoice/[id]/+page.server.ts | 5 ++-- src/routes/(app)/send/invoice/[id]/+page.svelte | 30 +++++++++++++++++++--- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/+page.svelte index 09caaa85..060473ec 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/+page.svelte @@ -1,6 +1,4 @@
@@ -39,7 +34,7 @@ diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 6cacc1c6..c78ba008 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -3,8 +3,8 @@ import { auth, fd, get, post, types } from "$lib/utils"; import { error, redirect } from "@sveltejs/kit"; export async function load({ cookies, params: { id }, parent }) { - const aid = cookies.get("aid"); const { user } = await parent(); + const aid = cookies.get("aid") || user.id; const invoice = await get(`/invoice/${id}`); @@ -24,8 +24,9 @@ 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)); - return { invoice, user, rate, invoiceRate }; + return { balance, invoice, user, rate, invoiceRate }; } export const actions = { diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 5a446dbb..7d167f41 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -12,10 +12,21 @@ import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; - import { btc, sat, post, back, f, toFiat, s, sats, focus, loc } from "$lib/utils"; + import { + btc, + sat, + post, + back, + f, + toFiat, + s, + sats, + focus, + loc, + } from "$lib/utils"; let { data, form } = $props(); - let { invoice, user } = $state(data); + let { balance, invoice, user } = $state(data); let { address, hash, payreq, user: recipient, tip } = $state(invoice); let { currency } = $derived(user); let locale = $derived(loc(user)); @@ -76,6 +87,12 @@ // } // } // }); + + let setMax = (e) => { + e.preventDefault(); + fiat = false; + amount = balance; + }; {#if form?.message} @@ -156,10 +173,17 @@ {/if} {:else} + +