problem: Revenue table doesn't work

This commit is contained in:
gsovereignty
2024-08-16 14:47:56 +08:00
parent 2ea6104031
commit ca583aeb33
4 changed files with 101 additions and 87 deletions

View File

@@ -40,6 +40,12 @@
{:else} {:else}
<PayNow {product} rocketProduct={rocket.Products().get(product.ID())} {rocket} /> <PayNow {product} rocketProduct={rocket.Products().get(product.ID())} {rocket} />
{/if} {/if}
<a
href="#"
on:click={() => {
console.log(product);
}}>print to console</a
>
</Card.Footer> </Card.Footer>
</Card.Root> </Card.Root>
{/if} {/if}

View File

@@ -11,12 +11,12 @@
//export let products: Product[]; //export let products: Product[];
export let rocket: Rocket; export let rocket: Rocket;
export let unratifiedZaps:Map<string, number>; //todo upstream bind this and pass outstanding zaps to merits and satflow component. export let unratifiedZaps: Map<string, number>;
let zaps = $ndk.storeSubscribe( let zaps = $ndk.storeSubscribe(
[{ '#a': [`31108:${rocket.Event.author.pubkey}:${rocket.Event.dTag}`], kinds: [9735] }], [{ '#a': [`31108:${rocket.Event.author.pubkey}:${rocket.Event.dTag}`], kinds: [9735] }],
{ {
subId: rocket.Name() + "_zaps" subId: rocket.Name() + '_zaps'
} }
); );
@@ -24,22 +24,14 @@
zaps?.unsubscribe(); zaps?.unsubscribe();
}); });
// let productEvent: NDKEvent | undefined; function productsInclude(id: string) {
let included = false;
// onMount(() => {
// $ndk.fetchEvent(product.ID).then((e) => {
// if (e) {
// productEvent = e;
// }
// });
// });
function productsInclude(id:string) {
let included = false
for (let p of products) { for (let p of products) {
if (p.ID() == id) {included = true} if (p.ID() == id) {
included = true;
}
} }
return included return included;
} }
let validZaps = derived(zaps, ($zaps) => { let validZaps = derived(zaps, ($zaps) => {
@@ -63,82 +55,85 @@
return zapMap; return zapMap;
}); });
let validPubkeys = writable(new Set<string>()) let validPubkeys = writable(new Set<string>());
zapsNotInRocket.subscribe((z) => { zapsNotInRocket.subscribe((z) => {
z.forEach((z) => { z.forEach((z) => {
ValidateZapPublisher(rocket.Event, z.ZapReceipt).then((result) => { ValidateZapPublisher(rocket.Event, z.ZapReceipt).then((result) => {
if (result) { if (result) {
validPubkeys.update(existing=>{ validPubkeys.update((existing) => {
existing.add(z.ZapReceipt.pubkey); existing.add(z.ZapReceipt.pubkey);
return existing return existing;
}) });
} }
}); });
}); });
}); });
let validatedZapsNotInRocket = derived([zapsNotInRocket, validPubkeys], ([$zapsNotInRocket, $validPubkeys]) => { let validatedZapsNotInRocket = derived(
let zapMap = new Map<string, ZapPurchase>(); [zapsNotInRocket, validPubkeys],
for (let [id, zap] of $zapsNotInRocket) { ([$zapsNotInRocket, $validPubkeys]) => {
if ($validPubkeys.has(zap.ZapReceipt.pubkey)) { let zapMap = new Map<string, ZapPurchase>();
zapMap.set(id, zap); for (let [id, zap] of $zapsNotInRocket) {
if ($validPubkeys.has(zap.ZapReceipt.pubkey)) {
zapMap.set(id, zap);
}
} }
return zapMap;
} }
return zapMap; );
});
validatedZapsNotInRocket.subscribe(zaps=>{ validatedZapsNotInRocket.subscribe((zaps) => {
for (let [_, z] of zaps) { for (let [_, z] of zaps) {
unratifiedZaps.set(z.ZapReceipt.id, z.Amount) unratifiedZaps.set(z.ZapReceipt.id, z.Amount);
} }
unratifiedZaps = unratifiedZaps unratifiedZaps = unratifiedZaps;
}) });
//todo: get existing purchases from rocket and render them //todo: get existing purchases from rocket and render them
//todo: update rocket event with confirmed zaps if we have votepower //todo: update rocket event with confirmed zaps if we have votepower
</script> </script>
<Table.Root> <Table.Root>
<Table.Caption <Table.Caption
class="mt-0 caption-top text-center text-lg font-semibold tracking-tight text-card-foreground" class="mt-0 caption-top text-center text-lg font-semibold tracking-tight text-card-foreground"
>Purchases</Table.Caption >Purchases</Table.Caption
> >
<Table.Header> <Table.Header>
<Table.Row> <Table.Row>
<Table.Head>Buyer</Table.Head> <Table.Head>Buyer</Table.Head>
<Table.Head class="hidden md:table-cell">Sats Paid</Table.Head> <Table.Head class="hidden md:table-cell">Sats Paid</Table.Head>
<Table.Head class="text-right"></Table.Head> <Table.Head class="text-right"></Table.Head>
</Table.Row> </Table.Row>
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{#each $validatedZapsNotInRocket as [id, purchase], _ (id)} {#each $validatedZapsNotInRocket as [id, purchase], _ (id)}
<Table.Row <Table.Row
on:click={() => { on:click={() => {
console.log(purchase.ZapReceipt.rawEvent()); console.log(purchase.ZapReceipt.rawEvent());
}} }}
class="bg-accent" class="bg-accent"
>
<Table.Cell>
<div class="flex flex-nowrap">
<Avatar
ndk={$ndk}
pubkey={purchase.BuyerPubkey}
class="h-8 w-8 flex-none rounded-full object-cover"
/>
<Name
ndk={$ndk}
pubkey={purchase.BuyerPubkey}
class="inline-block max-w-32 truncate p-1"
/>
</div>
</Table.Cell>
<Table.Cell class="hidden md:table-cell">{purchase.Amount / 1000}</Table.Cell>
<Table.Cell class="text-right"
>{unixToRelativeTime(purchase.ZapReceipt.created_at * 1000)}</Table.Cell
> >
<Table.Cell> </Table.Row>
<div class="flex flex-nowrap"> {/each}
<Avatar </Table.Body>
ndk={$ndk} </Table.Root>
pubkey={purchase.BuyerPubkey}
class="h-8 w-8 flex-none rounded-full object-cover"
/>
<Name
ndk={$ndk}
pubkey={purchase.BuyerPubkey}
class="inline-block max-w-32 truncate p-1"
/>
</div>
</Table.Cell>
<Table.Cell class="hidden md:table-cell">{purchase.Amount / 1000}</Table.Cell>
<Table.Cell class="text-right"
>{unixToRelativeTime(purchase.ZapReceipt.created_at * 1000)}</Table.Cell
>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>

View File

@@ -1,15 +1,21 @@
<script lang="ts"> <script lang="ts">
import { ndk } from '@/ndk'; import { ndk } from '@/ndk';
import type { NDKEvent } from '@nostr-dev-kit/ndk';
import { onDestroy } from 'svelte'; import { onDestroy } from 'svelte';
import ProductCard from './ProductCard.svelte';
import { derived } from 'svelte/store'; import { derived } from 'svelte/store';
import ProductCard from './ProductCard.svelte';
import { Product, type Rocket } from '@/event_helpers/rockets';
import * as Card from '@/components/ui/card';
export let rocket: NDKEvent; export let rocket: Rocket;
let proposals = $ndk.storeSubscribe( let proposals = $ndk.storeSubscribe(
[{ '#a': [`31108:${rocket.author.pubkey}:${rocket.dTag}`], kinds: [1908 as number] }], [
{ subId: rocket.dTag } {
'#a': [`31108:${rocket.Event.author.pubkey}:${rocket.Event.dTag}`],
kinds: [1908 as number]
}
],
{ subId: rocket.Name() }
); );
onDestroy(() => { onDestroy(() => {
@@ -17,16 +23,23 @@
}); });
let unratified = derived(proposals, ($proposals) => { let unratified = derived(proposals, ($proposals) => {
return $proposals.filter((p) => { $proposals = $proposals.filter((p) => {
let found = false; return Boolean(!rocket.Products().get(p.id));
for (let product of rocket.getMatchingTags('product')) {
if (product[1].split(':')[0] == p.id) {
found = true;
}
}
return !found;
}); });
let products = new Map<string, Product>();
for (let p of $proposals) {
products.set(p.id, new Product(p));
}
return products;
}); });
</script> </script>
{#each $unratified as r (r.id)}<ProductCard {rocket} product={r} />{/each} {#if $unratified.size > 0}
<Card.Root>
<Card.Header>PROPOSED PRODUCTS</Card.Header>
<Card.Content>
TODO: make this look better
{#each $unratified as [_, product] (product.ID())}<ProductCard {rocket} {product} />{/each}
</Card.Content>
</Card.Root>
{/if}

View File

@@ -36,7 +36,7 @@
<ProductFomo bind:unratifiedZaps rocket={new Rocket(rocket)} /> <ProductFomo bind:unratifiedZaps rocket={new Rocket(rocket)} />
<ProposedProducts {rocket} /> <ProposedProducts rocket={new Rocket(rocket)} />
<MeritRequests rocket={new Rocket(rocket)} /> <MeritRequests rocket={new Rocket(rocket)} />
<BitcoinAssociations rocket={new Rocket(rocket)} /> <BitcoinAssociations rocket={new Rocket(rocket)} />