aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/invoice/+server.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-08-23 02:26:09 -0700
committerAdam Soltys <[email protected]>2022-08-23 02:26:14 -0700
commitc7ee4f41c5fe8b5664c82e65bc4aa7948dc7b510 (patch)
tree3dea8c1d12518c6b5e8a3ebffa75313078232a7c /src/routes/invoice/+server.js
parent63628385f1128503334711c8813f483a87a78ebe (diff)
downloadcoinos-ui-c7ee4f41c5fe8b5664c82e65bc4aa7948dc7b510.tar.gz
coinos-ui-c7ee4f41c5fe8b5664c82e65bc4aa7948dc7b510.zip
generate new invoice on tip
Diffstat (limited to 'src/routes/invoice/+server.js')
-rw-r--r--src/routes/invoice/+server.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/routes/invoice/+server.js b/src/routes/invoice/+server.js
index c77784d7..4b961be9 100644
--- a/src/routes/invoice/+server.js
+++ b/src/routes/invoice/+server.js
@@ -1,16 +1,16 @@
-import { json as json$1 } from '@sveltejs/kit';
-import { post } from '$lib/utils';
-import { user } from '$lib/store';
-
-let network = 'lightning';
+import cookie from 'cookie';
+import { get, post } from '$lib/utils';
export async function POST({ request }) {
- let { amount, rate, username, text } = await request.json();
- if (!text) ({ text } = await post('/lightning/invoice', { amount }));
- let { uuid: id } = await post('/invoice', {
- invoice: { amount, currency: user.currency, network, rate, text },
- user: { username }
- });
+ let { token } = cookie.parse(request.headers.get('cookie') || '');
+
+ let network = 'lightning';
+ let { amount, currency, rate, tip, text, username } = await request.json();
+ let headers = { authorization: `Bearer ${token}` };
+
+ ({ text } = await post('/lightning/invoice', { amount }, headers));
+ let invoice = { amount, currency, network, rate, tip, text };
+ let { uuid } = await post('/invoice', { invoice, user: { username } }, headers);
- return json$1({ id });
+ return new Response(JSON.stringify(uuid), { headers: { 'content-type': 'application/json' } });
}