aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/apps
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-07 22:23:00 -0800
committerAdam Soltys <[email protected]>2025-02-07 22:23:00 -0800
commit479cb9ad44d05b56cd2e60735687702fc37487a0 (patch)
treefad9e4080887c2f11e8f750714c83e619f833afa /src/routes/(app)/apps
parentd92352dafc6d9e62716625d75be2316039a97a69 (diff)
downloadcoinos-ui-479cb9ad44d05b56cd2e60735687702fc37487a0.tar.gz
coinos-ui-479cb9ad44d05b56cd2e60735687702fc37487a0.zip
nwc connections
Diffstat (limited to 'src/routes/(app)/apps')
-rw-r--r--src/routes/(app)/apps/[pubkey]/+page.server.ts26
-rw-r--r--src/routes/(app)/apps/[pubkey]/+page.svelte19
-rw-r--r--src/routes/(app)/apps/new/+page.server.ts31
-rw-r--r--src/routes/(app)/apps/new/+page.svelte19
4 files changed, 95 insertions, 0 deletions
diff --git a/src/routes/(app)/apps/[pubkey]/+page.server.ts b/src/routes/(app)/apps/[pubkey]/+page.server.ts
new file mode 100644
index 00000000..a2cc50e7
--- /dev/null
+++ b/src/routes/(app)/apps/[pubkey]/+page.server.ts
@@ -0,0 +1,26 @@
+import getRates from "$lib/rates";
+import { auth, fd, get, post } from "$lib/utils";
+import { fail, redirect } from "@sveltejs/kit";
+
+export const load = async ({ cookies, params, parent }) => {
+ const { pubkey } = params;
+ const { user } = await parent();
+ const rates = await getRates();
+ const rate = rates[user.currency];
+ const app = await get(`/app/${pubkey}`, auth(cookies));
+ return { app, rate };
+};
+
+export const actions = {
+ default: async ({ cookies, request }) => {
+ try {
+ const body = await fd(request);
+ await post("/app", body, auth(cookies));
+ } catch (e) {
+ const { message: error } = e as Error;
+ return fail(400, { error });
+ }
+
+ redirect(307, "/settings/nostr");
+ },
+};
diff --git a/src/routes/(app)/apps/[pubkey]/+page.svelte b/src/routes/(app)/apps/[pubkey]/+page.svelte
new file mode 100644
index 00000000..d1a5f2bd
--- /dev/null
+++ b/src/routes/(app)/apps/[pubkey]/+page.svelte
@@ -0,0 +1,19 @@
+<script>
+ import { t } from "$lib/translations";
+ import AppForm from "$comp/AppForm.svelte";
+ import { untrack } from "svelte";
+ let { data, form } = $props();
+ let { app, rate, user } = $derived(data);
+</script>
+
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h2 class="text-2xl font-bold mb-2">{$t("accounts.connection")}</h2>
+
+ {#if form?.error}
+ <div class="text-red-600 text-center">
+ {form.error}
+ </div>
+ {/if}
+
+ <AppForm {...app} {rate} {user} />
+</div>
diff --git a/src/routes/(app)/apps/new/+page.server.ts b/src/routes/(app)/apps/new/+page.server.ts
new file mode 100644
index 00000000..7c335f8c
--- /dev/null
+++ b/src/routes/(app)/apps/new/+page.server.ts
@@ -0,0 +1,31 @@
+import getRates from "$lib/rates";
+import { auth, fd, post } from "$lib/utils";
+import { fail, redirect } from "@sveltejs/kit";
+
+export const load = async ({ parent, url }) => {
+ const app = {
+ name: url.searchParams.get("name"),
+ pubkey: url.searchParams.get("pubkey"),
+ max_amount: url.searchParams.get("max_amount"),
+ budget_renewal: url.searchParams.get("budget_renewal"),
+ };
+
+ const { user } = await parent();
+ const rates = await getRates();
+ const rate = rates[user.currency];
+ return { app, rate };
+};
+
+export const actions = {
+ default: async ({ cookies, request }) => {
+ try {
+ const body = await fd(request);
+ await post("/app", body, auth(cookies));
+ } catch (e) {
+ const { message: error } = e as Error;
+ return fail(400, { error });
+ }
+
+ redirect(307, "/settings/nostr");
+ },
+};
diff --git a/src/routes/(app)/apps/new/+page.svelte b/src/routes/(app)/apps/new/+page.svelte
new file mode 100644
index 00000000..d1a5f2bd
--- /dev/null
+++ b/src/routes/(app)/apps/new/+page.svelte
@@ -0,0 +1,19 @@
+<script>
+ import { t } from "$lib/translations";
+ import AppForm from "$comp/AppForm.svelte";
+ import { untrack } from "svelte";
+ let { data, form } = $props();
+ let { app, rate, user } = $derived(data);
+</script>
+
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h2 class="text-2xl font-bold mb-2">{$t("accounts.connection")}</h2>
+
+ {#if form?.error}
+ <div class="text-red-600 text-center">
+ {form.error}
+ </div>
+ {/if}
+
+ <AppForm {...app} {rate} {user} />
+</div>