aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-26 13:59:58 -0800
committerAdam Soltys <[email protected]>2025-02-26 13:59:58 -0800
commite41b139050143ffec87116db1d9094c785776cdc (patch)
tree4cd42c851abc7dac9e4808a2f98a2678adbd0a2b /src/components
parent66b5069777414d2f1e70b8a0804d7712e09b8304 (diff)
downloadcoinos-ui-e41b139050143ffec87116db1d9094c785776cdc.tar.gz
coinos-ui-e41b139050143ffec87116db1d9094c785776cdc.zip
submit postmessage after form submission
Diffstat (limited to 'src/components')
-rw-r--r--src/components/AppForm.svelte31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/components/AppForm.svelte b/src/components/AppForm.svelte
index ffdd3d26..5cef0d1e 100644
--- a/src/components/AppForm.svelte
+++ b/src/components/AppForm.svelte
@@ -1,4 +1,7 @@
<script>
+ import { browser } from "$app/environment";
+ import { applyAction, deserialize } from "$app/forms";
+ import { page } from "$app/stores";
import Numpad from "$comp/Numpad.svelte";
import { getPublicKey } from "nostr-tools";
import { onMount, tick } from "svelte";
@@ -7,6 +10,11 @@
import { copy, focus, fail, post } from "$lib/utils";
import { t } from "$lib/translations";
import { enhance } from "$app/forms";
+ import {
+ PUBLIC_COINOS_PUBKEY as walletPubkey,
+ PUBLIC_COINOS_RELAY as relayUrl,
+ } from "$env/static/public";
+
let { rate, user, name, max_amount, budget_renewal, pubkey, secret } =
$props();
let { currency } = $derived(user);
@@ -21,6 +29,27 @@
pubkey = getPublicKey(secret);
};
+ let lud16 = $derived(`${user.username}@${$page.url.host}`);
+
+ let el = $state();
+ let submit = async (e) => {
+ e.preventDefault();
+ let body = new FormData(el);
+ let params = { method: "POST", body };
+ let url = $page.url.pathname;
+
+ const response = await fetch(url, params);
+ const result = deserialize(await response.text());
+
+ if (result.type === "redirect") {
+ let type = "nwc:success";
+ let msg = { relayUrl, lud16, walletPubkey, type };
+ if (browser && window.opener) window.opener.postMessage(msg, "*");
+ }
+
+ applyAction(result);
+ };
+
let del = async () => {
try {
await post(`/post/apps/delete`, { pubkey });
@@ -43,7 +72,7 @@
let numpad = $state();
</script>
-<form use:enhance method="POST" class="space-y-5">
+<form method="POST" class="space-y-5" onsubmit={submit} bind:this={el}>
<div>
<label for="name" class="font-bold mb-1 block">{$t("accounts.name")}</label>
<input type="text" name="name" bind:value={name} use:focus />