flotilla/src/app/components/NoteContentMinimalGoal.svelte

44 lines
1.5 KiB
Svelte
Raw Normal View History

2025-10-06 18:23:19 +00:00
<script lang="ts">
import type {ComponentProps} from "svelte"
2026-07-28 16:16:26 +00:00
import {derived} from "svelte/store"
2025-10-06 18:23:19 +00:00
import {sum} from "@welshman/lib"
2026-07-28 16:16:26 +00:00
import {ZAP_RECEIPT, fromMsats} from "@welshman/util"
import {ZapGoal} from "@welshman/domain"
import type {Zap} from "@welshman/domain"
import {Zappers} from "@welshman/app"
2025-10-06 18:23:19 +00:00
import Bolt from "@assets/icons/bolt.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import ContentMinimal from "@app/components/ContentMinimal.svelte"
2026-07-28 16:16:26 +00:00
import {app, reader} from "@app/core"
import {deriveEvents} from "@app/repository"
2025-10-06 18:23:19 +00:00
const props: ComponentProps<typeof ContentMinimal> = $props()
2026-07-28 16:16:26 +00:00
const goal = reader(ZapGoal)(props.event)
2025-10-06 18:23:19 +00:00
2026-07-28 16:16:26 +00:00
const title = goal.title()
const summaryEvent = $derived({content: goal.summary(), tags: props.event.tags})
const receipts = deriveEvents([{kinds: [ZAP_RECEIPT], "#e": [props.event.id]}])
const zaps = derived<typeof receipts, Zap[]>(
receipts,
($receipts, set) => $app.use(Zappers).validZapReceipts($receipts, props.event).$.subscribe(set),
[],
2025-11-20 23:54:06 +00:00
)
2025-10-06 18:23:19 +00:00
2026-07-28 16:16:26 +00:00
const goalAmount = goal.amount() ?? 0
const closedAt = goal.closedAt()
const counted = $derived($zaps.filter(zap => !closedAt || zap.response.created_at <= closedAt))
const zapAmount = $derived(fromMsats(sum(counted.map(zap => zap.invoiceAmount))))
2025-10-06 18:23:19 +00:00
</script>
<div class="flex justify-between">
2026-07-28 16:16:26 +00:00
<span class="text-sm">{title}</span>
2025-10-06 18:23:19 +00:00
<div class="flex items-center gap-1">
<Icon icon={Bolt} size={4} />
{zapAmount}/{goalAmount} sats funded
</div>
</div>
2026-07-28 16:16:26 +00:00
<ContentMinimal {...props} event={summaryEvent} />