From 04e635c8fda4202a119ba0c1a6f0b083d14a2d62 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 28 Jul 2023 17:09:08 -0500 Subject: [PATCH] pay button actually does something --- src/components/ActivityItem.tsx | 2 +- src/components/ContactViewer.tsx | 120 ++++++++++++++-------- src/routes/settings/SyncNostrContacts.tsx | 5 +- 3 files changed, 81 insertions(+), 46 deletions(-) diff --git a/src/components/ActivityItem.tsx b/src/components/ActivityItem.tsx index f2ce37b..b954f92 100644 --- a/src/components/ActivityItem.tsx +++ b/src/components/ActivityItem.tsx @@ -69,7 +69,7 @@ function LabelCircle(props: { return (
diff --git a/src/components/ContactViewer.tsx b/src/components/ContactViewer.tsx index f022072..2ba0a17 100644 --- a/src/components/ContactViewer.tsx +++ b/src/components/ContactViewer.tsx @@ -2,6 +2,7 @@ import { Dialog } from "@kobalte/core"; import { SubmitHandler } from "@modular-forms/solid"; import { Contact } from "@mutinywallet/mutiny-wasm"; import { createSignal, Match, Switch } from "solid-js"; +import { useNavigate } from "solid-start"; import close from "~/assets/icons/close.svg"; import { @@ -13,6 +14,8 @@ import { SmallHeader } from "~/components"; import { useI18n } from "~/i18n/context"; +import { toParsedParams } from "~/logic/waila"; +import { useMegaStore } from "~/state/megaStore"; import { DIALOG_CONTENT, DIALOG_POSITIONER } from "~/styles/dialogs"; export type ContactFormValues = { @@ -28,6 +31,8 @@ export function ContactViewer(props: { const i18n = useI18n(); const [isOpen, setIsOpen] = createSignal(false); const [isEditing, setIsEditing] = createSignal(false); + const [state, actions] = useMegaStore(); + const navigate = useNavigate(); const handleSubmit: SubmitHandler = ( c: ContactFormValues @@ -39,24 +44,48 @@ export function ContactViewer(props: { setIsEditing(false); }; + const handlePay = () => { + const network = state.mutiny_wallet?.get_network() || "signet"; + + const lnurl = props.contact.lnurl || props.contact.ln_address || ""; + + if (lnurl) { + const result = toParsedParams(lnurl, network); + if (!result.ok) { + showToast(result.error); + return; + } else { + if ( + result.value?.address || + result.value?.invoice || + result.value?.node_pubkey || + result.value?.lnurl + ) { + actions.setScanResult(result.value); + navigate("/send"); + } + } + } + }; + return ( @@ -91,33 +120,43 @@ export function ContactViewer(props: { /> -
-
- {props.contact.image_url && ( - - )} - {!props.contact.image_url && ( -
- {props.contact.name[0]} -
- )} -

+
+
+
+ + + + + + {props.contact.name[0]} + + +
+ +

{props.contact.name}

-

+

{props.contact.npub}

-

+

{props.contact.ln_address}

-

+

{props.contact.lnurl}

diff --git a/src/routes/settings/SyncNostrContacts.tsx b/src/routes/settings/SyncNostrContacts.tsx index 10ac980..18ee890 100644 --- a/src/routes/settings/SyncNostrContacts.tsx +++ b/src/routes/settings/SyncNostrContacts.tsx @@ -1,6 +1,7 @@ import { TextField } from "@kobalte/core"; import { createSignal } from "solid-js"; -import NavBar from "~/components/NavBar"; + +import { NavBar } from "~/components"; import { Button, DefaultMain, @@ -43,7 +44,7 @@ export default function SyncNostrContacts() { Sync Nostr Contacts