aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-31 15:23:49 -0700
committerAdam Soltys <[email protected]>2024-08-31 15:23:49 -0700
commita89d4ee9b9bf0c15505a58803585f1847731983e (patch)
tree46098814beabc79de334898dbc4808aed8d5f329 /src
parentdf71664f20312e81134ee90ad561f55d3020ee0a (diff)
downloadcoinos-ui-a89d4ee9b9bf0c15505a58803585f1847731983e.tar.gz
coinos-ui-a89d4ee9b9bf0c15505a58803585f1847731983e.zip
typescript
Diffstat (limited to 'src')
-rw-r--r--src/lib/handler.ts19
-rw-r--r--src/lib/translations/index.js8
-rw-r--r--src/lib/types.ts22
-rw-r--r--src/locales/en.json14
-rw-r--r--src/routes/(app)/[username]/(profile)/event/[id]/+page.server.ts2
-rw-r--r--src/routes/(app)/[username]/address/+page.server.ts5
-rw-r--r--src/routes/(app)/[username]/generate/+server.ts2
-rw-r--r--src/routes/(app)/[username]/items/[id]/+page.server.ts4
-rw-r--r--src/routes/(app)/[username]/items/create/+page.server.ts4
-rw-r--r--src/routes/(app)/[username]/messages/+page.server.ts17
-rw-r--r--src/routes/(app)/[username]/messages/[recipient]/+page.server.ts7
-rw-r--r--src/routes/(app)/[username]/payments/[...page]/+page.server.ts2
-rw-r--r--src/routes/(app)/[username]/receive/[...param]/+page.server.ts4
-rw-r--r--src/routes/(app)/[username]/settings/[...tab]/+page.server.ts2
-rw-r--r--src/routes/(app)/[username]/shopify.js/+server.ts2
-rw-r--r--src/routes/(app)/[username]/verify/[code]/+page.server.ts2
-rw-r--r--src/routes/(app)/admin/+layout.server.ts2
-rw-r--r--src/routes/(app)/buy/+page.server.ts28
-rw-r--r--src/routes/(app)/buy/+page.svelte138
-rw-r--r--src/routes/(app)/ecash/[id]/+layout.server.ts6
-rw-r--r--src/routes/(app)/ecash/[id]/+page.server.ts2
-rw-r--r--src/routes/(app)/forgot/+page.server.ts6
-rw-r--r--src/routes/(app)/fund/[id]/+page.server.ts4
-rw-r--r--src/routes/(app)/fund/[id]/withdraw/+page.server.ts4
-rw-r--r--src/routes/(app)/ln/[lnurl]/+page.server.ts4
-rw-r--r--src/routes/(app)/locations/+server.ts2
-rw-r--r--src/routes/(app)/login/+page.server.ts6
-rw-r--r--src/routes/(app)/otpsecret/+server.ts4
-rw-r--r--src/routes/(app)/pay/[username]/[...amount]/+page.server.ts4
-rw-r--r--src/routes/(app)/payment/[id]/bump/+server.ts2
-rw-r--r--src/routes/(app)/receive/[...token]/+page.server.ts14
-rw-r--r--src/routes/(app)/register/+page.server.ts4
-rw-r--r--src/routes/(app)/reset/[code]/+page.server.ts4
-rw-r--r--src/routes/(app)/send/[...text]/+page.server.ts12
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts8
-rw-r--r--src/routes/(app)/send/ecash/+page.server.ts5
-rw-r--r--src/routes/(app)/send/ecash/+page.svelte4
-rw-r--r--src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts2
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.server.ts4
-rw-r--r--src/routes/(app)/send/invoice/[id]/+page.svelte3
-rw-r--r--src/routes/(app)/send/lightning/[payreq]/+page.server.ts4
-rw-r--r--src/routes/(static)/+layout.server.ts8
-rw-r--r--src/routes/+layout.server.ts2
-rw-r--r--src/routes/+layout.ts2
44 files changed, 134 insertions, 270 deletions
diff --git a/src/lib/handler.ts b/src/lib/handler.ts
index 03795ad9..559761f0 100644
--- a/src/lib/handler.ts
+++ b/src/lib/handler.ts
@@ -1,14 +1,13 @@
import { goto } from "$app/navigation";
import { applyAction } from "$app/forms";
-export default (submitting) =>
- () => {
- submitting = true;
- return async ({ result }) => {
- if (result.type === "redirect") {
- goto(result.location);
- } else {
- await applyAction(result);
- }
- };
+export default (toggle) => () => {
+ toggle();
+ return async ({ result }) => {
+ if (result.type === "redirect") {
+ goto(result.location);
+ } else {
+ await applyAction(result);
+ }
};
+};
diff --git a/src/lib/translations/index.js b/src/lib/translations/index.js
index ae2fcedf..cd7c20dd 100644
--- a/src/lib/translations/index.js
+++ b/src/lib/translations/index.js
@@ -1,17 +1,9 @@
import i18n from "sveltekit-i18n";
-import lang from "./lang.json";
-
-const availableLocales = Object.keys(lang);
-const trans = {};
-for (let i = 0; i < availableLocales.length; i++) {
- trans[availableLocales[i]] = { lang };
-}
export const defaultLocale = "en";
const config = {
fallbackLocale: "en",
- translations: trans,
loaders: [
{
locale: "en",
diff --git a/src/lib/types.ts b/src/lib/types.ts
new file mode 100644
index 00000000..33f78c85
--- /dev/null
+++ b/src/lib/types.ts
@@ -0,0 +1,22 @@
+export interface Message {
+ author: User;
+ created_at: number;
+ recipient: User;
+}
+
+export interface Note {
+ created_at: number;
+ seen: number;
+}
+
+export interface User {
+ id: string;
+}
+
+export interface Invoice {
+ id?: string;
+ memoPrompt?: boolean;
+ memo?: string;
+ rate: number;
+ type: string;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index ee2cf878..09935e45 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -383,5 +383,17 @@
"price": "Price",
"submit": "Submit",
"image": "Image"
- }
+ },
+ "lang": {
+ "en": "English",
+ "es": "Español",
+ "fr": "Français",
+ "de": "Deutsch",
+ "ja": "日本語",
+ "ru": "Русский",
+ "pt": "Português",
+ "zh": "中文",
+ "fa": "فارسی ",
+ "el": "Ελληνικά"
+ }
}
diff --git a/src/routes/(app)/[username]/(profile)/event/[id]/+page.server.ts b/src/routes/(app)/[username]/(profile)/event/[id]/+page.server.ts
index 42c568c5..baeab3d7 100644
--- a/src/routes/(app)/[username]/(profile)/event/[id]/+page.server.ts
+++ b/src/routes/(app)/[username]/(profile)/event/[id]/+page.server.ts
@@ -6,7 +6,7 @@ export async function load({ params: { id } }) {
let event = await get(`/event/${id}`);
if (!event) error(500, "Event not found");
return { event };
- } catch (e: Error) {
+ } catch (e: any) {
error(500, e.message);
}
}
diff --git a/src/routes/(app)/[username]/address/+page.server.ts b/src/routes/(app)/[username]/address/+page.server.ts
index d173594a..2f7841ab 100644
--- a/src/routes/(app)/[username]/address/+page.server.ts
+++ b/src/routes/(app)/[username]/address/+page.server.ts
@@ -1,9 +1,8 @@
-import { auth, get, post } from "$lib/utils";
+import { auth, post } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-export async function load({ cookies, params, parent }) {
+export async function load({ cookies, parent }) {
let user = (await parent()).subject;
- let rates = await get("/rates");
let invoice = { type: "bitcoin" };
let { id } = await post(`/invoice`, { invoice, user }, auth(cookies));
redirect(307, `/${user.username}/invoice/${id}`);
diff --git a/src/routes/(app)/[username]/generate/+server.ts b/src/routes/(app)/[username]/generate/+server.ts
index 3e3a9358..cdfac166 100644
--- a/src/routes/(app)/[username]/generate/+server.ts
+++ b/src/routes/(app)/[username]/generate/+server.ts
@@ -5,7 +5,7 @@ export async function POST({ cookies, request }) {
try {
let body = await request.json();
return json(await post(`/user`, body, auth(cookies)));
- } catch (e) {
+ } catch (e: any) {
error(500, e.message);
}
}
diff --git a/src/routes/(app)/[username]/items/[id]/+page.server.ts b/src/routes/(app)/[username]/items/[id]/+page.server.ts
index 4cfc952c..67cebd93 100644
--- a/src/routes/(app)/[username]/items/[id]/+page.server.ts
+++ b/src/routes/(app)/[username]/items/[id]/+page.server.ts
@@ -1,7 +1,7 @@
import { fd, auth, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
-export let load = async ({ cookies, params: { id } }) => {
+export let load = async ({ params: { id } }) => {
let item = await get(`/items/${id}`);
return { item };
};
@@ -11,7 +11,7 @@ export const actions = {
let form = await fd(request);
try {
await post(`/items`, form, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/[username]/items/create/+page.server.ts b/src/routes/(app)/[username]/items/create/+page.server.ts
index 8cb48399..2e006a3e 100644
--- a/src/routes/(app)/[username]/items/create/+page.server.ts
+++ b/src/routes/(app)/[username]/items/create/+page.server.ts
@@ -1,12 +1,12 @@
import { fail, redirect } from "@sveltejs/kit";
-import { fd, auth, get, post } from "$lib/utils";
+import { fd, auth, post } from "$lib/utils";
export const actions = {
default: async ({ cookies, request, url }) => {
let form = await fd(request);
try {
await post("/items", form, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/[username]/messages/+page.server.ts b/src/routes/(app)/[username]/messages/+page.server.ts
index 33d9ccaa..94659621 100644
--- a/src/routes/(app)/[username]/messages/+page.server.ts
+++ b/src/routes/(app)/[username]/messages/+page.server.ts
@@ -1,7 +1,16 @@
-import { auth, get } from "$lib/utils";
+import { get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-export async function load({ cookies, params, parent, url }) {
+interface Message {
+ created_at: number;
+}
+
+interface Note {
+ created_at: number;
+ seen: number;
+}
+
+export async function load({ params, parent, }) {
let { user } = await parent();
if (user.username !== params.username) redirect(307, `/${params.username}`);
let { since = 0 } = params;
@@ -13,7 +22,7 @@ export async function load({ cookies, params, parent, url }) {
let { pubkey } = user;
try {
messages = await get(`/${pubkey}/${since}/messages`);
- messages = messages.sort((a, b) => b.created_at - a.created_at);
+ messages = messages.sort((a: Message, b: Message) => b.created_at - a.created_at);
} catch (e) {
console.log(`failed to fetch nostr messages`, e);
}
@@ -24,7 +33,7 @@ export async function load({ cookies, params, parent, url }) {
console.log(`failed to fetch nostr notes for ${pubkey}`, e);
}
- notes.map((e) => {
+ notes.map((e: Note) => {
e.seen = e.created_at;
});
}
diff --git a/src/routes/(app)/[username]/messages/[recipient]/+page.server.ts b/src/routes/(app)/[username]/messages/[recipient]/+page.server.ts
index 6936a06b..6be9f6ec 100644
--- a/src/routes/(app)/[username]/messages/[recipient]/+page.server.ts
+++ b/src/routes/(app)/[username]/messages/[recipient]/+page.server.ts
@@ -1,10 +1,11 @@
import { get } from "$lib/utils";
+import type { Message } from "$lib/types";
-export async function load({ params, parent, url }) {
+export async function load({ params, parent }) {
let { user } = await parent();
let { since = 0 } = params;
- let messages = [];
+ let messages: Message[] = [];
let recipient = await get(`/users/${params.recipient}`);
try {
@@ -12,7 +13,7 @@ export async function load({ params, parent, url }) {
messages = messages
.filter(
- (m) => m.recipient?.id === recipient.id || m.author?.id === recipient.id
+ (m: Message) => m.recipient?.id === recipient.id || m.author?.id === recipient.id
)
.sort((a, b) => a.created_at - b.created_at);
} catch (e) {
diff --git a/src/routes/(app)/[username]/payments/[...page]/+page.server.ts b/src/routes/(app)/[username]/payments/[...page]/+page.server.ts
index 4a539e43..070349f8 100644
--- a/src/routes/(app)/[username]/payments/[...page]/+page.server.ts
+++ b/src/routes/(app)/[username]/payments/[...page]/+page.server.ts
@@ -2,7 +2,7 @@ import { get, auth } from "$lib/utils";
let limit = 25;
-export async function load({ cookies, depends, params, request }) {
+export async function load({ cookies, depends, params }) {
depends("app:payments");
let parts = params.page.split("/");
diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.server.ts b/src/routes/(app)/[username]/receive/[...param]/+page.server.ts
index 953954e9..502678a9 100644
--- a/src/routes/(app)/[username]/receive/[...param]/+page.server.ts
+++ b/src/routes/(app)/[username]/receive/[...param]/+page.server.ts
@@ -1,11 +1,11 @@
import { redirect } from "@sveltejs/kit";
import { auth, post } from "$lib/utils";
-import invoice from "$lib/invoice";
+import type { Invoice } from "$lib/types";
export let load = async ({ cookies, parent }) => {
let {subject, user, rates } = await parent();
- let invoice = {
+ let invoice: Invoice = {
type: "lightning",
rate: rates[user?.currency || subject?.currency],
};
diff --git a/src/routes/(app)/[username]/settings/[...tab]/+page.server.ts b/src/routes/(app)/[username]/settings/[...tab]/+page.server.ts
index 5ff691f0..42639b38 100644
--- a/src/routes/(app)/[username]/settings/[...tab]/+page.server.ts
+++ b/src/routes/(app)/[username]/settings/[...tab]/+page.server.ts
@@ -23,7 +23,7 @@ export const actions = {
try {
({ user } = await post(`/user`, user, auth(cookies)));
- } catch (e) {
+ } catch (e: any) {
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/[username]/shopify.js/+server.ts b/src/routes/(app)/[username]/shopify.js/+server.ts
index c93ac729..43a2ef2d 100644
--- a/src/routes/(app)/[username]/shopify.js/+server.ts
+++ b/src/routes/(app)/[username]/shopify.js/+server.ts
@@ -1,4 +1,4 @@
-export async function GET({ cookies, params, url }) {
+export async function GET({ params, url }) {
let { username } = params;
let js = `
diff --git a/src/routes/(app)/[username]/verify/[code]/+page.server.ts b/src/routes/(app)/[username]/verify/[code]/+page.server.ts
index 19453d9d..fec1a85c 100644
--- a/src/routes/(app)/[username]/verify/[code]/+page.server.ts
+++ b/src/routes/(app)/[username]/verify/[code]/+page.server.ts
@@ -1,5 +1,5 @@
import { get } from "$lib/utils";
-import { error, redirect } from "@sveltejs/kit";
+import { redirect } from "@sveltejs/kit";
export let load = async ({ params: { code } }) => {
let user;
diff --git a/src/routes/(app)/admin/+layout.server.ts b/src/routes/(app)/admin/+layout.server.ts
index 9250a7d4..58f8df09 100644
--- a/src/routes/(app)/admin/+layout.server.ts
+++ b/src/routes/(app)/admin/+layout.server.ts
@@ -1,7 +1,7 @@
import { auth, get } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-export async function load({ cookies, parent }) {
+export async function load({ cookies }) {
let token = cookies.get("token");
if (!token) redirect(307, "/login");
let user = await get("/me", auth(cookies));
diff --git a/src/routes/(app)/buy/+page.server.ts b/src/routes/(app)/buy/+page.server.ts
deleted file mode 100644
index b8897741..00000000
--- a/src/routes/(app)/buy/+page.server.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { env } from "$env/dynamic/private";
-import { error, fail, redirect } from "@sveltejs/kit";
-import { post, auth } from "$lib/utils";
-import { createTicket } from "$lib/ticket";
-
-export const actions = {
- default: async ({ cookies, request }) => {
- let form = await request.formData();
-
- let amount = parseFloat(form.get("amount"));
- if (!amount || amount < 0 || amount > 500)
- return fail(400, { message: "Invalid amount" });
-
- await post(
- "/buy",
- {
- amount: form.get("amount"),
- number: form.get("number").replace(/\s+/g, ""),
- month: form.get("expiry").slice(0, 2),
- year: form.get("expiry").slice(-2),
- cvc: form.get("cvc"),
- },
- auth(cookies)
- );
-
- redirect(307, `/${form.get("username")}/payments`);
- },
-};
diff --git a/src/routes/(app)/buy/+page.svelte b/src/routes/(app)/buy/+page.svelte
deleted file mode 100644
index 2b81b7a8..00000000
--- a/src/routes/(app)/buy/+page.svelte
+++ /dev/null
@@ -1,138 +0,0 @@
-<script>
- import { enhance } from "$app/forms";
- import Icon from "$comp/Icon.svelte";
- import Lock from "$comp/Lock.svelte";
- import Card from "$comp/Card.svelte";
- import Calendar from "$comp/Calendar.svelte";
- import Spinner from "$comp/Spinner.svelte";
- import { f } from "$lib/utils";
-
- export let data, form;
-
- let { username, currency } = data.user;
- let loading;
-
- let amount, n, d, cvc;
-</script>
-
-<div class="container px-4 max-w-xl mx-auto mt-10 space-y-5">
- <div class="w-full flex">
- <a href="/" class="mx-auto">
- <Icon icon="logo" />
- </a>
- </div>
-
- <div class="flex justify-center items-center">
- <div class="shadow-xl rounded-3xl px-10 pt-5 pb-10 space-y-5 w-full mx-5">
- <div class="relative">
- <h1 class="text-2xl md:text-3xl font-semibold text-center">
- Buy Bitcoin
- </h1>
- </div>
- <p class="text-secondary text-center">
- Purchase up to $500 worth of Bitcoin
- </p>
-
- {#if form?.message}
- <div class="text-red-600 text-center">
- {form.message}
- </div>
- {/if}
-
- <form
- method="POST"
- class="flex flex-wrap gap-5 w-full p-5 mt-20"
- use:enhance={() => {
- loading = true;
- return ({ update }) => update() && (loading = false);
- }}
- >
- <input type="hidden" name="username" value={username} />
-
- <label class="relative w-full flex flex-col">
- <span class="font-bold mb-3">Amount</span>
- <input
- class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300"
- type="text"
- name="amount"
- placeholder="&bull;&bull;&bull;"
- bind:value={amount}
- />
- <span
- class="absolute bottom-[9px] left-0 translate-x-1/2 w-6 text-black peer-placeholder-shown:text-gray-300
- ">$</span
- >
- </label>
-
- <label class="relative w-full flex flex-col">
- <span class="font-bold mb-3">Card number</span>
- <input
- class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300"
- type="text"
- name="number"
- placeholder="0000 0000 0000 0000"
- bind:value={n}
- />
- <Card />
- </label>
-
- <label class="relative flex-1 flex flex-col">
- <span class="font-bold mb-3">Expire date</span>
- <input
- class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300"
- type="text"
- name="expiry"
- placeholder="MM/YY"
- bind:value={d}
- />
- <Calendar />
- </label>
-
- <label class="relative flex-1 flex flex-col">
- <span class="font-bold flex items-center gap-3 mb-3">
- CVC/CVV
- <span class="relative group">
- <span
- class="hidden group-hover:flex justify-center items-center px-2 py-1 text-xs absolute -right-2 transform translate-x-full -translate-y-1/2 w-max top-1/2 bg-black text-white"
- >
- 3-digit number on the back of your card</span
- >
- </span>
- </span>
- <input
- class="rounded-md peer pl-12 pr-2 py-2 border-2 border-gray-200 placeholder-gray-300"
- type="text"
- name="cvc"
- placeholder="&bull;&bull;&bull;"
- bind:value={cvc}
- />
- <Lock />
- </label>
-
- <div class="w-full flex mt-8">
- <button
- class="bg-black text-white border rounded-full px-8 py-4 font-bold hover:opacity-80 mx-auto text-xl"
- type="submit"
- disabled={loading}
- >
- {#if loading}
- <Spinner />
- {:else}
- Submit
- {/if}
- </button>
- </div>
- </form>
-
- <div class="flex">
- <div class="text-secondary flex mr-auto">
- <div class="flex mr-1">
- <div class="my-auto mr-1">1</div>
- <img src="/images/bitcoin.svg" class="w-5 my-auto" alt="Bitcoin" />
- </div>
- </div>
- <p class="text-secondary">3% credit card fee applies</p>
- </div>
- </div>
- </div>
-</div>
diff --git a/src/routes/(app)/ecash/[id]/+layout.server.ts b/src/routes/(app)/ecash/[id]/+layout.server.ts
index 0b8b2917..5de15341 100644
--- a/src/routes/(app)/ecash/[id]/+layout.server.ts
+++ b/src/routes/(app)/ecash/[id]/+layout.server.ts
@@ -1,8 +1,6 @@
-import { auth, get } from "$lib/utils";
-import { fail, redirect } from "@sveltejs/kit";
-import parse from "$lib/parse";
+import { get } from "$lib/utils";
-export async function load({ cookies, params, request, url }) {
+export async function load({ params }) {
let { id } = params;
let { token, status } = await get(`/cash/${id}`);
let { spent, total, mint, external } = status;
diff --git a/src/routes/(app)/ecash/[id]/+page.server.ts b/src/routes/(app)/ecash/[id]/+page.server.ts
index 624ac314..0ed2d1c4 100644
--- a/src/routes/(app)/ecash/[id]/+page.server.ts
+++ b/src/routes/(app)/ecash/[id]/+page.server.ts
@@ -11,7 +11,7 @@ export const actions = {
try {
claimed = await post(`/claim`, { token }, auth(cookies));
claimed = { ok: true };
- } catch (e) {
+ } catch (e: any) {
return fail(400, { error: e.message });
}
if (claimed?.ok) {
diff --git a/src/routes/(app)/forgot/+page.server.ts b/src/routes/(app)/forgot/+page.server.ts
index 48411539..de440f02 100644
--- a/src/routes/(app)/forgot/+page.server.ts
+++ b/src/routes/(app)/forgot/+page.server.ts
@@ -1,5 +1,5 @@
-import { fail, redirect } from "@sveltejs/kit";
-import { fd, post, login } from "$lib/utils";
+import { fail } from "@sveltejs/kit";
+import { fd, post } from "$lib/utils";
export const actions = {
default: async ({ request }) => {
@@ -7,7 +7,7 @@ export const actions = {
let { email } = await fd(request);
await post("/forgot", { email });
return { success: true };
- } catch (e) {
+ } catch (e: any) {
return fail(400, { error: e.message });
}
},
diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts
index c5c8db2f..e553b1b4 100644
--- a/src/routes/(app)/fund/[id]/+page.server.ts
+++ b/src/routes/(app)/fund/[id]/+page.server.ts
@@ -1,4 +1,4 @@
-import { error, redirect } from "@sveltejs/kit";
+import { redirect } from "@sveltejs/kit";
import { auth, get, post } from "$lib/utils";
import Qr from "qrcode-base64";
@@ -10,7 +10,7 @@ export let load = async ({ params: { id }, url }) => {
};
export const actions = {
- default: async ({ cookies, locals, params, request }) => {
+ default: async ({ cookies, locals, params }) => {
let { user } = locals;
if (user) {
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts
index 1da349f8..f0379153 100644
--- a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts
+++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts
@@ -1,4 +1,4 @@
-import { fail, json, redirect } from "@sveltejs/kit";
+import { fail, redirect } from "@sveltejs/kit";
import { fd, auth, post } from "$lib/utils";
export async function load({ parent }) {
@@ -11,7 +11,7 @@ export const actions = {
let body = await fd(request);
try {
await post("/take", body, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts
index 7f0536c1..d1b1b86e 100644
--- a/src/routes/(app)/ln/[lnurl]/+page.server.ts
+++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts
@@ -10,7 +10,7 @@ export async function load({ params, parent }) {
try {
let { lnurl } = params;
data = await get(`/decode?text=${lnurl}`);
- } catch (e) {
+ } catch (e: any) {
error(500, e.message);
}
@@ -21,7 +21,7 @@ export async function load({ params, parent }) {
}
export const actions = {
- pay: async ({ cookies, fetch, request }) => {
+ pay: async ({ fetch, request }) => {
let error;
let { callback, amount, minSendable, maxSendable } = await fd(request);
diff --git a/src/routes/(app)/locations/+server.ts b/src/routes/(app)/locations/+server.ts
index 8a046475..987459bc 100644
--- a/src/routes/(app)/locations/+server.ts
+++ b/src/routes/(app)/locations/+server.ts
@@ -1,7 +1,7 @@
import { get } from "$lib/utils";
import { json } from "@sveltejs/kit";
-export async function GET({ fetch, setHeaders }) {
+export async function GET({ setHeaders }) {
let locations = [];
try {
diff --git a/src/routes/(app)/login/+page.server.ts b/src/routes/(app)/login/+page.server.ts
index 7fb1a6b3..fd7fec8c 100644
--- a/src/routes/(app)/login/+page.server.ts
+++ b/src/routes/(app)/login/+page.server.ts
@@ -1,7 +1,7 @@
import { fail, redirect } from "@sveltejs/kit";
import { login, fd } from "$lib/utils";
-export const load = async ({ parent, url }) => {
+export const load = async ({ parent }) => {
let { user } = await parent();
if (user?.pubkey) redirect(307, `/${user.username}`);
};
@@ -15,12 +15,12 @@ export const actions = {
if (loginRedirect === "undefined") loginRedirect = undefined;
try {
- let r = await login(
+ await login(
user,
cookies,
request.headers.get("cf-connecting-ip")
);
- } catch (e) {
+ } catch (e: any) {
return fail(400, { error: "Login failed", message: e.message, ...form });
}
diff --git a/src/routes/(app)/otpsecret/+server.ts b/src/routes/(app)/otpsecret/+server.ts
index 63d06849..2539ba27 100644
--- a/src/routes/(app)/otpsecret/+server.ts
+++ b/src/routes/(app)/otpsecret/+server.ts
@@ -10,8 +10,8 @@ export async function POST({ cookies, request }) {
return new Response(
JSON.stringify({ secret, uri, qr: Qr.drawImg(uri, { size: 600 }) })
);
- } catch (e) {
+ } catch (e: any) {
if (e.message.includes("pin")) throw e;
- throw new error(500, "Problem saving secret");
+ error(500, "Problem saving secret");
}
}
diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
index 884e3eee..e9a0ec9e 100644
--- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
@@ -4,7 +4,7 @@ import { types, sats, fd, auth, get, post } from "$lib/utils";
export async function load({ cookies, params, parent }) {
let subject = await get(`/users/${params.username}`);
- let { rates, user } = await parent();
+ let { rates } = await parent();
let { username } = params;
let [amount, currency] = params.amount.split("/");
@@ -40,7 +40,7 @@ export const actions = {
try {
let body = await fd(request);
await post("/payments", body, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
console.log(e);
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/payment/[id]/bump/+server.ts b/src/routes/(app)/payment/[id]/bump/+server.ts
index 513198b0..336284ba 100644
--- a/src/routes/(app)/payment/[id]/bump/+server.ts
+++ b/src/routes/(app)/payment/[id]/bump/+server.ts
@@ -6,7 +6,7 @@ export async function POST({ cookies, request }) {
try {
let res = await post("/replace", body, auth(cookies));
return json(res);
- } catch (e) {
+ } catch (e: any) {
error(400, e.message);
}
}
diff --git a/src/routes/(app)/receive/[...token]/+page.server.ts b/src/routes/(app)/receive/[...token]/+page.server.ts
index 30b42f32..011ffb00 100644
--- a/src/routes/(app)/receive/[...token]/+page.server.ts
+++ b/src/routes/(app)/receive/[...token]/+page.server.ts
@@ -1,17 +1,17 @@
-import { auth, fd, get, post } from "$lib/utils";
-import { error, fail, redirect } from "@sveltejs/kit";
+import { fd} from "$lib/utils";
+import { fail, redirect } from "@sveltejs/kit";
import parse from "$lib/parse";
-export async function load({ cookies, params, parent, url }) {
+export async function load({ params, parent, url }) {
let { user } = await parent();
if (!user) redirect(307, `/register?redirect=${url.pathname}`);
- await parse(params.token, url.host, cookies);
+ await parse(params.token, url.host);
}
export const actions = {
- default: async ({ cookies, request, url }) => {
+ default: async ({ request, url }) => {
let { text } = await fd(request);
- let msg = await parse(text, url.host, cookies);
- return fail(400, { error: msg || "default" });
+ await parse(text, url.host );
+ return fail(400, { error: "default" });
},
};
diff --git a/src/routes/(app)/register/+page.server.ts b/src/routes/(app)/register/+page.server.ts
index 9cbb777e..731530c4 100644
--- a/src/routes/(app)/register/+page.server.ts
+++ b/src/routes/(app)/register/+page.server.ts
@@ -24,14 +24,14 @@ export const actions = {
try {
await post("/register", { user }, { "cf-connecting-ip": ip });
- } catch (e) {
+ } catch (e: any) {
error = e.message;
}
try {
await login(user, cookies, ip);
error = null;
- } catch (e) {
+ } catch (e: any) {
error ||= e.message;
}
diff --git a/src/routes/(app)/reset/[code]/+page.server.ts b/src/routes/(app)/reset/[code]/+page.server.ts
index 67f2d919..375fd588 100644
--- a/src/routes/(app)/reset/[code]/+page.server.ts
+++ b/src/routes/(app)/reset/[code]/+page.server.ts
@@ -16,13 +16,13 @@ export const actions = {
try {
await login(user, cookies, ip);
error = null;
- } catch (e) {
+ } catch (e: any) {
error ||= e.message;
}
if (error) return fail(400, { error });
redirect(307, `/${user.username}`);
- } catch (e) {
+ } catch (e: any) {
console.log(e.message);
return fail(400, { error: e.message });
}
diff --git a/src/routes/(app)/send/[...text]/+page.server.ts b/src/routes/(app)/send/[...text]/+page.server.ts
index ba5d6190..950a2c98 100644
--- a/src/routes/(app)/send/[...text]/+page.server.ts
+++ b/src/routes/(app)/send/[...text]/+page.server.ts
@@ -1,19 +1,19 @@
import { auth, fd, get } from "$lib/utils";
-import { fail, redirect } from "@sveltejs/kit";
+import { fail } from "@sveltejs/kit";
import parse from "$lib/parse";
-export async function load({ cookies, params, request, url }) {
+export async function load({ cookies, params, url }) {
let { text } = params;
- await parse(text, url.host, cookies);
+ await parse(text, url.host);
let contacts = await get("/contacts", auth(cookies));
return { contacts };
}
export const actions = {
- default: async ({ cookies, request, url }) => {
+ default: async ({ request, url }) => {
let { text } = await fd(request);
- let msg = await parse(text, url.host, cookies);
- return fail(400, { error: msg || "default" });
+ await parse(text, url.host);
+ return fail(400, { error: "default" });
},
};
diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
index d4498b39..7efe6e49 100644
--- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts
@@ -1,8 +1,6 @@
import { fail, redirect } from "@sveltejs/kit";
import { auth, post, fd } from "$lib/utils";
-let seen = {};
-
export async function load({ params: { address, amount, feeRate }, cookies }) {
try {
let { fee, fees, ourfee, hex } = await post(
@@ -12,7 +10,7 @@ export async function load({ params: { address, amount, feeRate }, cookies }) {
);
return { amount, address, fee, fees, feeRate, ourfee, hex };
- } catch (e) {
+ } catch (e: any) {
return { amount, address, feeRate, message: e.message };
}
}
@@ -24,8 +22,8 @@ export const actions = {
request,
}) => {
try {
- let r = await post("/bitcoin/send", await fd(request), auth(cookies));
- } catch (e) {
+ await post("/bitcoin/send", await fd(request), auth(cookies));
+ } catch (e: any) {
console.log("problem sending bitcoin", e);
return fail(400, { address, amount, feeRate, message: e.message });
}
diff --git a/src/routes/(app)/send/ecash/+page.server.ts b/src/routes/(app)/send/ecash/+page.server.ts
index cef1ba78..64de18c7 100644
--- a/src/routes/(app)/send/ecash/+page.server.ts
+++ b/src/routes/(app)/send/ecash/+page.server.ts
@@ -1,6 +1,5 @@
-import { error, redirect, Cookies } from "@sveltejs/kit";
+import { error, redirect } from "@sveltejs/kit";
import { auth, post, fd } from "$lib/utils";
-import { v4 } from "uuid";
export const actions = {
default: async ({ cookies, request }) => {
@@ -9,7 +8,7 @@ export const actions = {
try {
({ id } = await post("/mint", body, auth(cookies)));
- } catch (e) {
+ } catch (e: any) {
console.log("problem creating ecash", e);
error(400, { message: e.message });
}
diff --git a/src/routes/(app)/send/ecash/+page.svelte b/src/routes/(app)/send/ecash/+page.svelte
index 983e9a44..15c7c5d3 100644
--- a/src/routes/(app)/send/ecash/+page.svelte
+++ b/src/routes/(app)/send/ecash/+page.svelte
@@ -24,7 +24,9 @@
fiat = false;
amount = balance;
};
+
let submitting;
+ let toggle = () => (submitting = !submitting);
</script>
<a href="/send">
@@ -38,7 +40,7 @@
{$t("payments.createEcash")}
</h1>
- <form use:enhance={handler(submitting)} method="POST">
+ <form use:enhance={handler(toggle)} method="POST">
<Numpad bind:amount bind:fiat {currency} {submit} bind:rate={$rate} />
<input type="hidden" name="amount" bind:value={amount} />
diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts
index 51277e5d..2897b159 100644
--- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts
@@ -8,7 +8,7 @@ export const actions = {
try {
p = await post("/payments", body, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
return fail(400, { message: e.message });
}
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts
index 2662e771..ed0198cf 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.server.ts
+++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts
@@ -1,7 +1,7 @@
import { error, redirect } from "@sveltejs/kit";
import { fd, auth, get, post } from "$lib/utils";
-export async function load({ params: { id }, parent, url }) {
+export async function load({ params: { id }, parent }) {
let { rates, user } = await parent();
let invoice = await get(`/invoice/${id}`);
@@ -27,7 +27,7 @@ export const actions = {
body.hash = id;
await post("/payments", body, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
console.log("payment failed", id, e);
error(500, e.message);
}
diff --git a/src/routes/(app)/send/invoice/[id]/+page.svelte b/src/routes/(app)/send/invoice/[id]/+page.svelte
index bc62b5f5..81a2c521 100644
--- a/src/routes/(app)/send/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/send/invoice/[id]/+page.svelte
@@ -49,6 +49,7 @@
};
let submitting;
+ let toggle = () => (submitting = !submitting);
let external = async () => {
let { id } = await post(`/${recipient.username}/invoice`, {
@@ -168,7 +169,7 @@
/>
{/if}
- <form method="POST" use:enhance={handler(submitting)}>
+ <form method="POST" use:enhance={handler(toggle)}>
<input name="address" value={address} type="hidden" />
<input name="amount" value={amount} type="hidden" />
<input name="payreq" value={payreq} type="hidden" />
diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.server.ts b/src/routes/(app)/send/lightning/[payreq]/+page.server.ts
index 89bcc3c3..ddec2968 100644
--- a/src/routes/(app)/send/lightning/[payreq]/+page.server.ts
+++ b/src/routes/(app)/send/lightning/[payreq]/+page.server.ts
@@ -6,14 +6,14 @@ export async function load({ cookies, params }) {
}
export const actions = {
- setAmount: async ({ cookies, request }) => fd(request),
+ setAmount: async ({ request }) => fd(request),
send: async ({ cookies, request }) => {
try {
let body = await fd(request);
await post("/payments", body, auth(cookies));
- } catch (e) {
+ } catch (e: any) {
if (e.message.includes("unusable"))
e.message = "Failed to route payment, try sending a lower amount";
return fail(400, { message: e.message });
diff --git a/src/routes/(static)/+layout.server.ts b/src/routes/(static)/+layout.server.ts
index 81d1d3dc..c26f8d96 100644
--- a/src/routes/(static)/+layout.server.ts
+++ b/src/routes/(static)/+layout.server.ts
@@ -1,11 +1,9 @@
-import { get, post, auth, protectedRoutes } from "$lib/utils";
+import { get, auth} from "$lib/utils";
-export async function load({ cookies, request, url, params }) {
+export async function load({ cookies }) {
let token = cookies.get("token");
- let rate,
- rates = { USD: 1 };
- let user;
+ let user;
if (token) {
try {
user = await get("/me", auth(cookies));
diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts
index aebac694..c21e8525 100644
--- a/src/routes/+layout.server.ts
+++ b/src/routes/+layout.server.ts
@@ -4,7 +4,7 @@ import {
loadTranslations,
translations,
defaultLocale,
-} from "$lib/translations";
+} from "$lib/translations/index";
export let load = async ({ cookies, request, url }) => {
let { host, pathname } = url;
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts
index 7b5d4f44..d9f713b4 100644
--- a/src/routes/+layout.ts
+++ b/src/routes/+layout.ts
@@ -1,4 +1,4 @@
-import { addTranslations, setLocale, setRoute } from "$lib/translations";
+import { addTranslations, setLocale, setRoute } from "$lib/translations/index";
/** @type {import('@sveltejs/kit').Load} */
export const load = async ({ data }) => {