diff options
| author | Adam Soltys <[email protected]> | 2024-01-02 20:21:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-01-02 20:21:20 -0800 |
| commit | a20ade414740804385ba05e6028f53b670e0236d (patch) | |
| tree | 493ac4e50319121c1e35a67243a6b11560b17910 /src/lib | |
| parent | ea8944bd05f3cdb83eab52b8abdb2351ce68bda1 (diff) | |
| parent | ae1c0add85daeae8bc44c34f9559bcd50c56d873 (diff) | |
| download | coinos-ui-a20ade414740804385ba05e6028f53b670e0236d.tar.gz coinos-ui-a20ade414740804385ba05e6028f53b670e0236d.zip | |
Merge branch 'master' into swapee
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/invoice.js | 9 | ||||
| -rw-r--r-- | src/lib/samples.js | 8 | ||||
| -rw-r--r-- | src/lib/utils.js | 33 |
3 files changed, 38 insertions, 12 deletions
diff --git a/src/lib/invoice.js b/src/lib/invoice.js index 87707c89..06a9a94e 100644 --- a/src/lib/invoice.js +++ b/src/lib/invoice.js @@ -25,13 +25,12 @@ export default async ({ cookies, request, url }) => { if (request_id) { if (url.pathname.endsWith("tip")) { - throw redirect(307, `/send/invoice/${id}`); + redirect(307, `/send/invoice/${id}`); } - throw redirect(307, `/${user.username}/request/${request_id}`); + redirect(307, `/${user.username}/request/${request_id}`); } - if (invoice.prompt) - throw redirect(307, `/${user.username}/invoice/${id}/tip`); - else throw redirect(307, `/${user.username}/invoice/${id}`); + if (invoice.prompt) redirect(307, `/${user.username}/invoice/${id}/tip`); + else redirect(307, `/${user.username}/invoice/${id}`); }; diff --git a/src/lib/samples.js b/src/lib/samples.js index c8a60c71..6624064b 100644 --- a/src/lib/samples.js +++ b/src/lib/samples.js @@ -1,3 +1,9 @@ +import { PUBLIC_DOMAIN, PUBLIC_COINOS_URL } from "$env/static/public"; + +let api = PUBLIC_DOMAIN.includes("localhost") + ? `${PUBLIC_COINOS_URL}` + : `https://${PUBLIC_DOMAIN}/api`; + export default { register: `curl "https://swapee.me/api/register" -H "content-type: application/json" -d '{ "user": { @@ -24,7 +30,7 @@ export default { -H "Authorization: Bearer $token" -d '{ "amount": 5000, - "hash": "bc1q3unh97w4rmelflrm2hvdwz37d8kray3vn4d5ca" + "address": "bc1q3unh97w4rmelflrm2hvdwz37d8kray3vn4d5ca" }'`, internal: `HASH=$(curl "https://swapee.me/api/invoice" -H "content-type: application/json" diff --git a/src/lib/utils.js b/src/lib/utils.js index c0df81ae..738413bf 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -101,8 +101,8 @@ export function reverseFormat(val, locale) { export let protectedRoutes = [/customers/, /settings/, /payments/]; -export let success = (m) => { - toast.pop(); +export let success = (m, clear = true) => { + if (clear) toast.pop(); toast.push(m, { theme: { "--toastBarBackground": "#F5F7FA", @@ -110,16 +110,16 @@ export let success = (m) => { }); }; -export let warning = (m) => { - toast.pop(); +export let warning = (m, clear = true) => { + if (clear) toast.pop(); toast.push(m, { theme: { "--toastBarBackground": "#FFCE22", }, }); }; -export let fail = (m) => { - toast.pop(); +export let fail = (m, clear = true) => { + if (clear) toast.pop(); toast.push(m, { theme: { "--toastBarBackground": "#E93535", @@ -186,6 +186,7 @@ export let f = (s, currency) => export let s = (s) => new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(s); + export let sat = (s) => { s = Math.abs(s); let p = Math.floor(Math.log(s) / Math.LN10 + 0.000000001); @@ -265,6 +266,7 @@ export function ss(str1, str2) { export let types = { bitcoin: "bitcoin", + liquid: "liquid", lightning: "lightning", internal: "internal", fund: "fund", @@ -280,3 +282,22 @@ export function shuffleArray(array) { [array[i], array[j]] = [array[j], array[i]]; } } + +export let closest = (a, n) => + a.reduce((prev, curr) => + Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev + ); + +export let isLiquid = (text) => + text.startsWith("Az") || + text.startsWith("lq1") || + text.startsWith("VJL") || + text.startsWith("VT") || + text.startsWith("XR") || + text.startsWith("XC") || + ((text.startsWith("H") || text.startsWith("G") || text.startsWith("Q")) && + text.length === 34) || + (text.startsWith("ert1q") && text.length === 43) || + (text.startsWith("ex1q") && text.length === 42) || + text.startsWith("el1qq") || + text.startsWith("lq1qq"); |
