Skip to content

Commit

Permalink
problem: Revenue table doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Aug 16, 2024
1 parent 2ea6104 commit ca583ae
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 87 deletions.
6 changes: 6 additions & 0 deletions src/components/ProductCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
{:else}
<PayNow {product} rocketProduct={rocket.Products().get(product.ID())} {rocket} />
{/if}
<a
href="#"
on:click={() => {
console.log(product);
}}>print to console</a
>
</Card.Footer>
</Card.Root>
{/if}
139 changes: 67 additions & 72 deletions src/components/ProductPurchases.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,27 @@
//export let products: Product[];
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(
[{ '#a': [`31108:${rocket.Event.author.pubkey}:${rocket.Event.dTag}`], kinds: [9735] }],
{
subId: rocket.Name() + "_zaps"
subId: rocket.Name() + '_zaps'
}
);
onDestroy(() => {
zaps?.unsubscribe();
});
// let productEvent: NDKEvent | undefined;
// onMount(() => {
// $ndk.fetchEvent(product.ID).then((e) => {
// if (e) {
// productEvent = e;
// }
// });
// });
function productsInclude(id:string) {
let included = false
function productsInclude(id: string) {
let included = false;
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) => {
Expand All @@ -63,82 +55,85 @@
return zapMap;
});
let validPubkeys = writable(new Set<string>())
let validPubkeys = writable(new Set<string>());
zapsNotInRocket.subscribe((z) => {
z.forEach((z) => {
ValidateZapPublisher(rocket.Event, z.ZapReceipt).then((result) => {
if (result) {
validPubkeys.update(existing=>{
validPubkeys.update((existing) => {
existing.add(z.ZapReceipt.pubkey);
return existing
})
return existing;
});
}
});
});
});
let validatedZapsNotInRocket = derived([zapsNotInRocket, validPubkeys], ([$zapsNotInRocket, $validPubkeys]) => {
let zapMap = new Map<string, ZapPurchase>();
for (let [id, zap] of $zapsNotInRocket) {
if ($validPubkeys.has(zap.ZapReceipt.pubkey)) {
zapMap.set(id, zap);
let validatedZapsNotInRocket = derived(
[zapsNotInRocket, validPubkeys],
([$zapsNotInRocket, $validPubkeys]) => {
let zapMap = new Map<string, ZapPurchase>();
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) {
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: update rocket event with confirmed zaps if we have votepower
</script>

<Table.Root>
<Table.Caption
class="mt-0 caption-top text-center text-lg font-semibold tracking-tight text-card-foreground"
>Purchases</Table.Caption
>
<Table.Header>
<Table.Row>
<Table.Head>Buyer</Table.Head>
<Table.Head class="hidden md:table-cell">Sats Paid</Table.Head>
<Table.Head class="text-right"></Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each $validatedZapsNotInRocket as [id, purchase], _ (id)}
<Table.Row
on:click={() => {
console.log(purchase.ZapReceipt.rawEvent());
}}
class="bg-accent"
<Table.Root>
<Table.Caption
class="mt-0 caption-top text-center text-lg font-semibold tracking-tight text-card-foreground"
>Purchases</Table.Caption
>
<Table.Header>
<Table.Row>
<Table.Head>Buyer</Table.Head>
<Table.Head class="hidden md:table-cell">Sats Paid</Table.Head>
<Table.Head class="text-right"></Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each $validatedZapsNotInRocket as [id, purchase], _ (id)}
<Table.Row
on:click={() => {
console.log(purchase.ZapReceipt.rawEvent());
}}
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>
<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.Row>
{/each}
</Table.Body>
</Table.Root>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
41 changes: 27 additions & 14 deletions src/components/ProposedProducts.svelte
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
<script lang="ts">
import { ndk } from '@/ndk';
import type { NDKEvent } from '@nostr-dev-kit/ndk';
import { onDestroy } from 'svelte';
import ProductCard from './ProductCard.svelte';
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(
[{ '#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(() => {
proposals.unsubscribe();
});
let unratified = derived(proposals, ($proposals) => {
return $proposals.filter((p) => {
let found = false;
for (let product of rocket.getMatchingTags('product')) {
if (product[1].split(':')[0] == p.id) {
found = true;
}
}
return !found;
$proposals = $proposals.filter((p) => {
return Boolean(!rocket.Products().get(p.id));
});
let products = new Map<string, Product>();
for (let p of $proposals) {
products.set(p.id, new Product(p));
}
return products;
});
</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}
2 changes: 1 addition & 1 deletion src/components/RocketDashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<ProductFomo bind:unratifiedZaps rocket={new Rocket(rocket)} />

<ProposedProducts {rocket} />
<ProposedProducts rocket={new Rocket(rocket)} />

<MeritRequests rocket={new Rocket(rocket)} />
<BitcoinAssociations rocket={new Rocket(rocket)} />
Expand Down

0 comments on commit ca583ae

Please sign in to comment.