aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/invoice
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-24 13:34:37 -0700
committerAdam Soltys <[email protected]>2022-09-25 21:34:59 -0700
commit7bfd57b8b249fcf8ab87b52c8a4416d62f3cd1f6 (patch)
treeed85daeb18785e450fc4cb2e67066809cd0a1956 /src/routes/invoice
parente0e4441cfa2b20c3f5f0126a5cf8aeddaed269b6 (diff)
downloadcoinos-ui-7bfd57b8b249fcf8ab87b52c8a4416d62f3cd1f6.tar.gz
coinos-ui-7bfd57b8b249fcf8ab87b52c8a4416d62f3cd1f6.zip
wip
Diffstat (limited to 'src/routes/invoice')
-rw-r--r--src/routes/invoice/+server.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/routes/invoice/+server.js b/src/routes/invoice/+server.js
index 225f6bb1..d4c4c303 100644
--- a/src/routes/invoice/+server.js
+++ b/src/routes/invoice/+server.js
@@ -1,11 +1,17 @@
import { auth, get, post } from '$lib/utils';
-export async function POST({ request }) {
- let network = 'lightning';
- let { amount, currency, rate, tip, text, username } = await request.json();
- ({ text } = await post('/lightning/invoice', { amount }, auth(request)));
- let invoice = { amount, currency, network, rate, tip, text };
- let { uuid } = await post('/invoice', { invoice, user: { username } }, auth(request));
+export async function POST({ request, parent }) {
+ let { amount, currency, network = 'lightning', rate, tip, username } = await request.json();
+ let invoice = { amount, currency, network, rate, tip };
- return new Response(JSON.stringify(uuid), { headers: { 'content-type': 'application/json' } });
+ if (network === 'lightning') {
+ invoice.text = await post('/lightning/invoice', { amount }, auth(request));
+ } else {
+ invoice.address = (await parent()).user.address;
+ }
+
+ return new Response(
+ JSON.stringify(await post('/invoice', { invoice, user: { username } }, auth(request))),
+ { headers: { 'content-type': 'application/json' } }
+ );
}