import { createForm, custom, getValue, required, reset, setValue, submit } from "@modular-forms/solid"; import { Motion } from "@motionone/solid"; import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; import { nip19 } from "nostr-tools"; import { isOnlyOneEmoji } from "~/regex"; import { CheckOut } from "~/components/CheckOut"; import { NWA } from "~/components/Auth"; import { LoadingSpinner } from "~/components/LoadingSpinner"; const API_URL = import.meta.env.VITE_ZAPPLE_API_URL; const EMOJI_OPTIONS = ["⚡️", "🤙", "👍", "❤️", "🫂"]; type ZappleForm = { npub: string; amount_sats: string; nwc: string; manual_nwc: boolean; use_custom_emoji: boolean; emoji: string; donate_damus: boolean; donate_opensats: boolean; }; type ZapplePayPayloadEmoji = { npub: string; amount_sats: number; emoji: string; auth_id?: string; nwc?: string; donations?: Array<{ amount_sats: number; npub: string }>; }; export default function Home() { const [saving, setSaving] = createSignal(false); const [error, setError] = createSignal(); const [saved, setSaved] = createSignal(false); const [zappleForm, { Form, Field }] = createForm({ initialValues: { npub: "", amount_sats: "", nwc: "", emoji: "🤙", donate_damus: false, donate_opensats: false } }); const [nwaAuthId, setNwaAuthId] = createSignal( undefined ); const handleSubmit = async (f: ZappleForm) => { const { npub, amount_sats, nwc, emoji, donate_damus, donate_opensats } = f; setSaving(true); setError(undefined); const npubHex = nip19.decode(npub).data; let donations = []; if (donate_damus) { let item = { amount_sats: Number(amount_sats), npub: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" }; donations.push(item); } if (donate_opensats) { let item = { amount_sats: Number(amount_sats), npub: "787338757fc25d65cd929394d5e7713cf43638e8d259e8dcf5c73b834eb851f2" }; donations.push(item); } const payload: ZapplePayPayloadEmoji = { npub: npubHex.toString(), amount_sats: Number(amount_sats), emoji, donations }; try { if (nwaAuthId()) { payload.auth_id = nwaAuthId(); console.log("using auth id", nwaAuthId()); } else if (nwc) { payload.nwc = nwc; console.log("using nwc", nwc); } else { throw new Error("You must connect a wallet"); } const res = await fetch(`https://${API_URL}/set-user`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); console.log(res); if (res.ok) { console.log("saved"); setSaved(true); } else { throw new Error("something went wrong"); } } catch (e) { console.error(e); setError(e as Error); } finally { setSaving(false); } }; // regex for just numbers const regex = /^[0-9]+$/; const nwaParams = createMemo(() => { const amount = getValue(zappleForm, "amount_sats"); if (!amount) return undefined; const npub = getValue(zappleForm, "npub"); if (!npub) return undefined; let user_npub_hex = undefined; try { user_npub_hex = nip19.decode(npub).data; } catch (e) { return undefined; } // Empty object is truthy return {}; }); function handleConnectedChange(authId?: string) { console.log("connected change", authId); setNwaAuthId(authId); if (authId) { submit(zappleForm); } } return (

Zapple Pay lets you Zap from any nostr client. Just react to a note{" "} UnLoCkAbLe dIgItAl cOnTeNt {" "} with a {getValue(zappleForm, "emoji")} emoji and Zapple Pay will notify your lightning wallet to pay the zap.

{ let decoded = nip19.decode(value!); if (decoded.data) { return true; } else { return false; } }, "Please enter a valid npub") ]} > {(field, props) => ( <> {field.error && (
{field.error}
)} )}
{ if (isOnlyOneEmoji(value!)) { return true; } else { return false; } }, "Please enter a valid emoji") ]} > {(field, props) => ( <> {field.error && (
{field.error}
)} )}
{(field, props) => ( <> {field.error && (
{field.error}
)} )}
{(field, props) => (
)}
{ if (regex.test(value!)) { return true; } else { return false; } }, "Please enter a number") ]} > {(field, props) => ( <> {field.error && (
{field.error}
)} )}
} > {(field, props) => ( )} {(field, props) => ( <>