import { ParentComponent, createMemo, createResource } from "solid-js"; import { satsToUsd } from "~/utils/conversions"; import bolt from "~/assets/icons/bolt.svg" import chain from "~/assets/icons/chain.svg" import { timeAgo } from "~/utils/prettyPrintTime"; import { MutinyTagItem } from "~/utils/tags"; import { generateGradient } from "~/utils/gradientHash"; import { useMegaStore } from "~/state/megaStore"; export const ActivityAmount: ParentComponent<{ amount: string, price: number, positive?: boolean, center?: boolean }> = (props) => { const amountInUsd = createMemo(() => { const parsed = Number(props.amount); if (isNaN(parsed)) { return props.amount; } else { return satsToUsd(props.price, parsed, true); } }) const prettyPrint = createMemo(() => { const parsed = Number(props.amount); if (isNaN(parsed)) { return props.amount; } else { return parsed.toLocaleString(); } }) return (
{props.positive && "+ "}{prettyPrint()} SATS
≈ {amountInUsd()} USD
) } function LabelCircle(props: { name?: string, contact: boolean }) { // TODO: don't need to run this if it's not a contact const [gradient] = createResource(async () => { return generateGradient(props.name || "?") }) const text = () => (props.contact && props.name && props.name.length) ? props.name[0] : (props.name && props.name.length) ? "≡" : "?" const bg = () => (props.name && props.contact) ? gradient() : "gray" return (
{text()}
) } // function that takes a list of MutinyTagItems and returns bool if one of those items is of kind Contact function includesContact(labels: MutinyTagItem[]) { return labels.some((label) => label.kind === "Contact") } // sort the labels so that the contact is always first function sortLabels(labels: MutinyTagItem[]) { const contact = labels.find(label => label.kind === "Contact"); return contact ? [contact, ...labels.filter(label => label !== contact)] : labels; } // return a string of each label name separated by a comma and a space. if the array is empty return "Unknown" function labelString(labels: MutinyTagItem[]) { return labels.length ? labels.map(label => label.name).join(", ") : "Unknown" } export function ActivityItem(props: { kind: "lightning" | "onchain", labels: MutinyTagItem[], amount: number | bigint, date?: number | bigint, positive?: boolean, onClick?: () => void }) { const labels = () => sortLabels(props.labels) const [state, _actions] = useMegaStore(); return (
props.onClick && props.onClick()} class="grid grid-cols-[auto_minmax(0,_1fr)_minmax(0,_max-content)] pb-4 gap-4 border-b border-neutral-800 last:border-b-0" classList={{ "cursor-pointer": !!props.onClick }} >
{props.kind === "lightning" ? lightning : onchain}
{labelString(labels())}
) }