From d99a3524fd2649f1a9ce3623333de56a99e06971 Mon Sep 17 00:00:00 2001 From: secondl1ght <85003930+secondl1ght@users.noreply.github.com> Date: Tue, 2 Aug 2022 13:23:59 -0600 Subject: lots of updates, implementing design, refactoring, bug fixes and more --- src/lib/utils.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/lib/utils.js') diff --git a/src/lib/utils.js b/src/lib/utils.js index db8a490a..6b728152 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -1,4 +1,5 @@ import { browser } from '$app/env'; +import { toast } from '@zerodevx/svelte-toast'; export function scroll(section) { section.scrollIntoView({ behavior: 'smooth' }); @@ -26,6 +27,7 @@ export const post = (url, body) => export const copy = (text) => { navigator.clipboard.writeText(text); + success('Copied!'); }; export function reverseFormat(val, locale) { @@ -37,4 +39,45 @@ export function reverseFormat(val, locale) { return Number.isNaN(reversedVal) ? 0 : +reversedVal; } -export let protectedRoutes = [/receive/, /customers/, /dashboard/, /settings/, /transactions/]; +export let protectedRoutes = [ + /receive/, + /customers/, + /dashboard/, + /settings/, + /transactions/, + /support/ +]; + +export const success = (m) => { + toast.pop(); + toast.push(m, { + theme: { + '--toastBarBackground': '#16A34A' + } + }); +}; + +export const warning = (m) => { + toast.pop(); + toast.push(m, { + theme: { + '--toastBarBackground': '#FFCE22' + } + }); +}; +export const failure = (m) => { + toast.pop(); + toast.push(m, { + theme: { + '--toastBarBackground': '#E93535' + } + }); +}; +export const info = (m) => { + toast.pop(); + toast.push(m, { + theme: { + '--toastBarBackground': '#1C69FF' + } + }); +}; -- cgit v1.2.3 From dcd4fe70f6f23a5ac2df3b773fea89c1acd878b6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 5 Aug 2022 10:21:48 -0700 Subject: lightning withdrawals --- src/lib/socket.js | 8 +++++- src/lib/utils.js | 8 +++--- src/routes/[username]/dashboard.svelte | 49 ++++++++++++++++++++++++++++------ src/routes/withdraw.js | 10 +++++++ 4 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 src/routes/withdraw.js (limited to 'src/lib/utils.js') diff --git a/src/lib/socket.js b/src/lib/socket.js index c1b68a12..a30d4376 100644 --- a/src/lib/socket.js +++ b/src/lib/socket.js @@ -1,5 +1,6 @@ import { get } from 'svelte/store'; import { rate, user, token, invoices, preferredCurrency, newPayment } from '$lib/store'; +import { success } from '$lib/utils'; let interval, socket; @@ -18,8 +19,13 @@ export const messages = (data) => ({ }, payment() { - invoices.set({ ...get(invoices), [data.invoice.uuid]: data.invoice }); + if (data.invoice) invoices.set({ ...get(invoices), [data.invoice.uuid]: data.invoice }); newPayment.set(true); + if (data.amount > 0) { + success(`Received ${data.amount} sats!`); + } else { + success(`Sent ${-data.amount} sats!`); + } }, connected: auth, diff --git a/src/lib/utils.js b/src/lib/utils.js index a812c136..24f94d40 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -18,11 +18,12 @@ export const get = (url, headers = { accept: 'application/json' }) => } }); -export const post = (url, body) => - fetch(base + url, { +export const post = (url, body, headers) => { + headers = { ...headers, accept: 'application/json', 'content-type': 'application/json' }; + return fetch(base + url, { method: 'POST', body: JSON.stringify(body), - headers: { accept: 'application/json', 'content-type': 'application/json' } + headers }) .then((r) => r.text()) .then((body) => { @@ -37,6 +38,7 @@ export const post = (url, body) => return body; }); +} export const copy = (text) => { navigator.clipboard.writeText(text); diff --git a/src/routes/[username]/dashboard.svelte b/src/routes/[username]/dashboard.svelte index 11295728..7fab2125 100644 --- a/src/routes/[username]/dashboard.svelte +++ b/src/routes/[username]/dashboard.svelte @@ -1,7 +1,29 @@ {#if $user} @@ -13,7 +15,13 @@
- +
@@ -35,11 +43,18 @@ class="block border rounded-xl p-2 w-full" type="text" name="message" + bind:value={message} required />
- +
{/if} diff --git a/src/routes/[username]/transactions.svelte b/src/routes/[username]/transactions.svelte index 24e3e146..c91fd900 100644 --- a/src/routes/[username]/transactions.svelte +++ b/src/routes/[username]/transactions.svelte @@ -18,8 +18,8 @@

AMOUNT

-

TYPE

-

TIME

+

TYPE

+

TIME

@@ -28,19 +28,21 @@
{tx.amount > 0 && '+'}{new Intl.NumberFormat('en-US', { + >{tx.amount > 0 ? '+' : ''}{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(tx.amount * (tx.rate / 100000000))} {new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format(tx.amount)} + >{tx.amount > 0 ? '+' : ''}{new Intl.NumberFormat('en-US', { + maximumFractionDigits: 0 + }).format(tx.amount)} SATS
-
+
{tx.amount < 0 ? 'Sent' : 'Received'}
diff --git a/src/routes/withdraw.js b/src/routes/withdraw.js index aaed2250..818d39da 100644 --- a/src/routes/withdraw.js +++ b/src/routes/withdraw.js @@ -1,8 +1,7 @@ import { post } from '$lib/utils'; export async function POST({ locals, request }) { let { token } = locals; - let body = await request.json(); - console.log(body) + let body = await request.json(); body = await post('/lightning/send', body, { authorization: `Bearer ${token}` }); -- cgit v1.2.3