From 40a3e7925026dc30292b0ecc0631b49076e3a03f Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Tue, 20 Feb 2024 21:05:56 +0000 Subject: [PATCH] fix some of ben's problems --- src/components/Activity.tsx | 72 +++++++++++++--------- src/components/GenericItem.tsx | 8 ++- src/i18n/en/translations.ts | 7 ++- src/routes/Chat.tsx | 107 ++++++++++++++++++++++++--------- src/routes/settings/Backup.tsx | 2 +- src/utils/fetchZaps.ts | 60 ++++-------------- 6 files changed, 145 insertions(+), 111 deletions(-) diff --git a/src/components/Activity.tsx b/src/components/Activity.tsx index f0f52d34..9d081919 100644 --- a/src/components/Activity.tsx +++ b/src/components/Activity.tsx @@ -1,6 +1,6 @@ import { TagItem } from "@mutinywallet/mutiny-wasm"; import { cache, createAsync, revalidate, useNavigate } from "@solidjs/router"; -import { Plus, Save, Search, Shuffle } from "lucide-solid"; +import { Plus, Save, Search, Shuffle, Users } from "lucide-solid"; import { createEffect, createSignal, For, Match, Show, Switch } from "solid-js"; import { ActivityDetailsModal, ButtonCard, NiceP } from "~/components"; @@ -30,6 +30,8 @@ export function UnifiedActivityItem(props: { item: IActivityItem; onClick: (id: string, kind: HackActivityType) => void; }) { + const navigate = useNavigate(); + const click = () => { props.onClick( props.item.id, @@ -115,33 +117,37 @@ export function UnifiedActivityItem(props: { }; return ( - <> - - +
+ : undefined} + primaryOnClick={() => + primaryName() !== "You" && primaryContact()?.id + ? navigate(`/chat/${primaryContact()?.id}`) + : undefined + } + amountOnClick={click} + primaryName={ + props.item.inbound + ? primaryContact()?.name || "Unknown" + : "You" + } + genericAvatar={shouldShowGeneric()} + verb={verb()} + message={message()} + secondaryName={secondaryName()} + amount={ + props.item.amount_sats + ? BigInt(props.item.amount_sats || 0) + : undefined + } + date={timeAgo(props.item.last_updated)} + accent={props.item.inbound ? "green" : undefined} + visibility={ + props.item.kind === "Lightning" ? "private" : undefined + } + /> +
); } @@ -199,6 +205,16 @@ export function CombinedActivity() { + + navigate("/settings/federations")} + > +
+ + {i18n.t("home.federation")} +
+
+
navigate("/receive")}>
diff --git a/src/components/GenericItem.tsx b/src/components/GenericItem.tsx index 80b59304..cff891cb 100644 --- a/src/components/GenericItem.tsx +++ b/src/components/GenericItem.tsx @@ -21,6 +21,7 @@ export function GenericItem(props: { forceSecondary?: boolean; link?: string; primaryOnClick?: () => void; + amountOnClick?: () => void; secondaryOnClick?: () => void; approveAction?: () => void; rejectAction?: () => void; @@ -76,7 +77,10 @@ export function GenericItem(props: {
{/* AMOUNT */} -
+ props.amountOnClick && props.amountOnClick() + } class="flex items-center gap-1 rounded-full px-2 py-1 text-xs font-semibold text-white" classList={{ "bg-m-grey-800": !props.accent, @@ -86,7 +90,7 @@ export function GenericItem(props: { {/* */} {`${props.amount!.toLocaleString()} sats`} -
+
{/* FIAT AMOUNT */} diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index 5a2f9167..99ffeec2 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -33,13 +33,18 @@ export default { receive: "Receive your first sats", find: "Find your friends on nostr", backup: "Secure your funds!", - connection: "Create a wallet connection" + connection: "Create a wallet connection", + federation: "Join a federation" }, profile: { nostr_identity: "Nostr Identity", add_lightning_address: "Add Lightning Address", edit_profile: "Edit Profile" }, + chat: { + prompt: "This is a new conversation. Try asking for money!", + placeholder: "Message" + }, contacts: { new: "new", add_contact: "Add Contact", diff --git a/src/routes/Chat.tsx b/src/routes/Chat.tsx index 777b9f7b..8304e6f2 100644 --- a/src/routes/Chat.tsx +++ b/src/routes/Chat.tsx @@ -1,6 +1,6 @@ import { TagItem } from "@mutinywallet/mutiny-wasm"; import { createAsync, useNavigate, useParams } from "@solidjs/router"; -import { ArrowDownLeft, ArrowUpRight, Zap } from "lucide-solid"; +import { ArrowDownLeft, ArrowUpRight, MessagesSquare, Zap } from "lucide-solid"; import { createEffect, createResource, @@ -19,6 +19,7 @@ import { AmountSats, BackPop, Button, + ButtonCard, ContactButton, ContactFormValues, ContactViewer, @@ -26,11 +27,13 @@ import { IActivityItem, LoadingShimmer, MutinyWalletGuard, + NiceP, showToast, SimpleInput, UnifiedActivityItem } from "~/components"; import { MiniFab } from "~/components/Fab"; +import { useI18n } from "~/i18n/context"; import { ParsedParams, toParsedParams } from "~/logic/waila"; import { useMegaStore } from "~/state/megaStore"; import { eify, hexpubFromNpub, timeAgo } from "~/utils"; @@ -267,6 +270,8 @@ export function Chat() { const [messageValue, setMessageValue] = createSignal(""); const [sending, setSending] = createSignal(false); + const i18n = useI18n(); + const contact = createAsync(async () => { try { return state.mutiny_wallet?.get_tag_item(params.id); @@ -283,20 +288,27 @@ export function Chat() { if (!contact || !contact?.npub) return undefined; if (!contact.npub) return [] as CombinedMessagesAndActivity[]; try { - const activity = await state.mutiny_wallet?.get_label_activity( - params.id - ); + let acts = [] as IActivityItem[]; + let dms = [] as FakeDirectMessage[]; - console.log("activity", activity); - const convo = await state.mutiny_wallet?.get_dm_conversation( - contact.npub, - 20n, - undefined, - undefined - ); + try { + acts = (await state.mutiny_wallet?.get_label_activity( + params.id + )) as IActivityItem[]; + } catch (e) { + console.error("error getting activity:", e); + } - const dms = convo as FakeDirectMessage[]; - const acts = activity as IActivityItem[]; + try { + dms = (await state.mutiny_wallet?.get_dm_conversation( + contact.npub, + 20n, + undefined, + undefined + )) as FakeDirectMessage[]; + } catch (e) { + console.error("error getting dms:", e); + } // Combine both arrays into an array of CombinedMessagesAndActivity, then sort by date const combined = [ @@ -339,13 +351,14 @@ export function Chat() { const npub = contact()?.npub; if (!npub) return; setSending(true); + const rememberedValue = messageValue(); + setMessageValue(""); try { const dmResult = await state.mutiny_wallet?.send_dm( npub, - messageValue() + rememberedValue ); console.log("dmResult:", dmResult); - setMessageValue(""); refetch(); } catch (e) { console.error("error sending dm:", e); @@ -495,15 +508,40 @@ export function Chat() { }> - - {/* TODO: figure out how not to do typecasting here */} - + 0 } - contact={contact()!} - /> - + > + {/* TODO: figure out how not to do typecasting here */} + + + + + requestFromContact( + contact() + ) + } + > +
+
+ +
+ + {i18n.t("chat.prompt")} + +
+
+
+
@@ -521,14 +559,23 @@ export function Chat() { } onRequest={() => requestFromContact(contact())} /> - setMessageValue(e.currentTarget.value)} - placeholder="Message" - /> +
{ + e.preventDefault(); + await sendMessage(); + }} + > + + setMessageValue(e.currentTarget.value) + } + placeholder={i18n.t("chat.placeholder")} + /> +
- +