From 2810139cfb19643527c8be4589ab1562c441f618 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 11 Mar 2023 10:21:02 -0800 Subject: prompt for tip on internal payments --- src/routes/(app)/send/invoice/[id]/+page.server.js | 14 ++++++++----- src/routes/(app)/send/invoice/[id]/+page.svelte | 24 +++++++++++++++++----- src/routes/(app)/sent/+page.server.js | 1 + 3 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js index 3db03123..c3ae0945 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.js +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -1,22 +1,26 @@ import { error, fail, redirect } from '@sveltejs/kit'; import { fd, auth, get, post } from '$lib/utils'; -export async function load({ params: { id }, parent }) { +export async function load({ params: { id }, parent, url }) { let { user } = await parent(); - let { amount, address, tip, text, user: recipient } = await get(`/invoice/${id}`); + let { amount, address, rate, prompt, tip, text, user: recipient } = await get(`/invoice/${id}`); + + console.log("AMOUNT, TIP", amount, tip) + + if (prompt && tip === null) throw redirect(307, `/${recipient.username}/invoice/${id}/tip`); if (recipient.username === user.username) throw error(500, { message: 'Cannot send to self' }); - if (tip) amount += tip; - return { amount, address, payreq: text, recipient }; + return { amount, address, tip, rate, payreq: text, recipient }; } export const actions = { default: async ({ cookies, params: { hash }, request }) => { try { let body = await fd(request); - body.amount = parseInt(body.amount); body.hash = hash; + console.log("SENDING BODY", body) + await post('/payments', body, auth(cookies)); } catch (e) { return fail(400, { message: e.message }); diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte index 7570a61a..c9cb9392 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.svelte +++ b/src/routes/(app)/send/invoice/[id]/+page.svelte @@ -5,11 +5,11 @@ import { enhance } from '$app/forms'; import { Avatar, Icon, Numpad, Spinner } from '$comp'; import { page } from '$app/stores'; - import { back, f, s, sats } from '$lib/utils'; + import { back, f, fiat as toFiat, s, sats } from '$lib/utils'; export let data; export let form; - let { address, payreq, recipient, user } = data; + let { address, payreq, recipient, rate, tip, user } = data; let { currency } = user; let amount = form?.amount || data.amount; @@ -49,9 +49,23 @@

{$t('payments.send')}

-

- {fiat ? f(amountFiat, currency) : '⚡️' + s(amount)} -

+

+ {f(toFiat(amount, rate), currency)} + {#if tip} + + + {f(toFiat(tip, rate), currency)} + + {/if} +

+

+ ⚡️{s(amount)} + + {#if tip} + + + ⚡️{s(tip)} + + {/if} +

{$t('payments.to')}

diff --git a/src/routes/(app)/sent/+page.server.js b/src/routes/(app)/sent/+page.server.js index 381ff32f..cfd43472 100644 --- a/src/routes/(app)/sent/+page.server.js +++ b/src/routes/(app)/sent/+page.server.js @@ -2,5 +2,6 @@ import { get, auth } from '$lib/utils'; export let load = async ({ cookies }) => { let { payments } = await get('/payments', auth(cookies)); + console.log("HUH", payments[0]) return { payments }; }; -- cgit v1.2.3