diff options
| author | Adrien Hopkins <[email protected]> | 2022-08-08 07:42:39 -0500 |
|---|---|---|
| committer | Adrien Hopkins <[email protected]> | 2022-08-08 07:42:39 -0500 |
| commit | f7aaa86c851d456a3426157bc04cdbfeecd1716b (patch) | |
| tree | 09892fccf026827fade28f4d76922fdcd514db64 /src/lib | |
| parent | ffc36d48b11045708967637832d959cade58b8eb (diff) | |
| parent | 93f9d0abf58c5b5154e35b63524405554042bef1 (diff) | |
| download | coinos-ui-f7aaa86c851d456a3426157bc04cdbfeecd1716b.tar.gz coinos-ui-f7aaa86c851d456a3426157bc04cdbfeecd1716b.zip | |
Merge branch 'master' into i18n
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/socket.js | 13 | ||||
| -rw-r--r-- | src/lib/store.js | 18 | ||||
| -rw-r--r-- | src/lib/utils.js | 53 |
3 files changed, 75 insertions, 9 deletions
diff --git a/src/lib/socket.js b/src/lib/socket.js index 66091d76..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 } from '$lib/store'; +import { rate, user, token, invoices, preferredCurrency, newPayment } from '$lib/store'; +import { success } from '$lib/utils'; let interval, socket; @@ -18,14 +19,20 @@ 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, login() { user.set(data); - preferredCurrency.set(data.currency); + preferredCurrency.set('USD'); } }); diff --git a/src/lib/store.js b/src/lib/store.js index b20fd10f..2693e945 100644 --- a/src/lib/store.js +++ b/src/lib/store.js @@ -1,7 +1,7 @@ import { get, writable } from 'svelte/store'; import { browser } from '$app/env'; -const persisted = (k, i) => { +const persistSession = (k, i) => { let s = writable( browser && sessionStorage.getItem(k) && sessionStorage.getItem(k) !== 'undefined' ? JSON.parse(sessionStorage.getItem(k)) @@ -13,10 +13,24 @@ const persisted = (k, i) => { return s; }; +const persistLocal = (k, i) => { + let s = writable( + browser && localStorage.getItem(k) && localStorage.getItem(k) !== 'undefined' + ? JSON.parse(localStorage.getItem(k)) + : i + ); + + s.subscribe((v) => browser && localStorage.setItem(k, JSON.stringify(v))); + + return s; +}; + export const rate = writable(); export const user = writable(); export const invoiceAmount = writable(); export const invoiceAmountFiat = writable(); -export const token = persisted('token'); +export const token = persistSession('token'); export const invoices = writable({}); export const preferredCurrency = writable(); +export const newPayment = persistLocal(); +export const colorTheme = writable('from-primary to-gradient'); diff --git a/src/lib/utils.js b/src/lib/utils.js index 669b2b5e..b42fe970 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' }); @@ -17,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) => { @@ -36,9 +38,11 @@ export const post = (url, body) => return body; }); +}; export const copy = (text) => { navigator.clipboard.writeText(text); + success('Copied!'); }; export function reverseFormat(val, locale) { @@ -50,4 +54,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' + } + }); +}; |
