diff --git a/src/routes/rockets/[ignition]/+page.svelte b/src/routes/rockets/[ignition]/+page.svelte index bb3791b..b54786f 100644 --- a/src/routes/rockets/[ignition]/+page.svelte +++ b/src/routes/rockets/[ignition]/+page.svelte @@ -5,11 +5,11 @@ import type { ExtendedBaseType, NDKEventStore } from '@nostr-dev-kit/ndk-svelte'; import { onDestroy } from 'svelte'; import { derived, type Readable } from 'svelte/store'; - import Heading from '../../../components/Heading.svelte'; - import Todo from '../../../components/Todo.svelte'; import CreateNewProduct from '../../../components/CreateNewProduct.svelte'; - import Subheading from '../../../components/Subheading.svelte'; + import Heading from '../../../components/Heading.svelte'; import ProductCard from '../../../components/ProductCard.svelte'; + import Subheading from '../../../components/Subheading.svelte'; + import Todo from '../../../components/Todo.svelte'; //flow if we only have a d-tag: fetch all 31108's with this d-tag, sort by WoT, put Nostrocket Name Service one at the top. Dedupe same rocket (same state, shadows) from multiple users, just show them all as everyone agreeing. //second pass: fetch ignition event for each, rebuild current state and validate all proofs, compute votepower and display only the states with > 50%. @@ -76,15 +76,54 @@ return e.kind == 9735; }); }); + + let existingProducts = derived(latestRocketEvent, ($latestRocketEvent)=>{ + let m = new Map() + if ($latestRocketEvent) { + let products = getMapOfProducts($latestRocketEvent) + + } + }) } } } - function getMapOfProducts(rocket: NDKEvent): Map { - let productIDs = new Map(); + class RocketProduct { + ID: string; + Price: number; + ValidAfter: number; //unix time + MaxPurchases: number; + Purchases: Map; + constructor(tag:NDKTag) { + this.Purchases = new Map() + this.ID = tag[1].split(':')[0] + this.Price = parseInt(tag[1].split(':')[1], 10) + this.ValidAfter = parseInt(tag[1].split(':')[2], 10) + this.MaxPurchases = parseInt(tag[1].split(':')[3], 10) + let purchases = JSON.parse(tag[3]) + for (let p of purchases) { + let payment = new ProductPayment(p) + this.Purchases.set(payment.ZapID, payment) + } + } + } + + class ProductPayment { + ZapID: string; + BuyerPubkey: string; + WitnessedAt: number; + constructor(purchase:string) { + this.ZapID = purchase.split(":")[0] + this.BuyerPubkey = purchase.split(":")[1] + this.WitnessedAt = parseInt(purchase.split(":")[2], 10) + } + } + + function getMapOfProducts(rocket: NDKEvent): Map { + let productIDs = new Map(); for (let product of rocket.getMatchingTags('product')) { if (product.length > 1 && product[1].split(':') && product[1].split(':').length > 0) { - productIDs.set(product[1].split(':')[0], product); + productIDs.set(product[1].split(':')[0], new RocketProduct(product)); } } return productIDs; @@ -94,6 +133,7 @@ //todo: list purchases on the rocket page (from product tags, as well as zap receipts that aren't yet included). Deduct total products available if not 0. //todo: make the page flash or something and show each time someone buys the product. //todo: split this out so that we can consume it for the payment page too (so that we know if there are really products left or they're all sold) + //todo: make store of all purchases (in rocket and zaps), sort by timestamp and render with profile of buyer function getZapData(zap: NDKEvent) { let productPrice = 0; let zapAmount = 0; @@ -110,12 +150,12 @@ for (let productIDfromZapRequest of zapRequestETags) { if (productIDfromZapRequest.length > 1) { let productsInRocket = getMapOfProducts($latestRocketEvent); - if (productsInRocket) { + if (productsInRocket.size > 0) { productID = productIDfromZapRequest[1]; if (productID.length == 64) { let productDataFromRocket = productsInRocket.get(productID); if (productDataFromRocket) { - productPrice = parseInt(productDataFromRocket[1].split(':')[1], 10); + productPrice = productDataFromRocket.Price } } else { } @@ -168,7 +208,9 @@ {/if} {#if zaps && $zaps} - {#each $zaps as z}

{ let zapdata = getZapData(z); if (zapdata) {