mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-20 15:04:18 +01:00
problem: incorrect satflow calculation
This commit is contained in:
@@ -103,6 +103,7 @@
|
|||||||
<Table.Head class="hidden text-left md:table-cell">Problem</Table.Head>
|
<Table.Head class="hidden text-left md:table-cell">Problem</Table.Head>
|
||||||
<Table.Head class="table-cell">Amount (Sats)</Table.Head>
|
<Table.Head class="table-cell">Amount (Sats)</Table.Head>
|
||||||
<Table.Head class="table-cell">Merits</Table.Head>
|
<Table.Head class="table-cell">Merits</Table.Head>
|
||||||
|
<Table.Head class="hidden text-center md:table-cell">Status</Table.Head>
|
||||||
<Table.Head class="hidden text-right md:table-cell">When</Table.Head>
|
<Table.Head class="hidden text-right md:table-cell">When</Table.Head>
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
@@ -119,12 +120,12 @@
|
|||||||
<Avatar
|
<Avatar
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
pubkey={merit.Pubkey}
|
pubkey={merit.Pubkey}
|
||||||
class="h-10 w-10 flex-none rounded-full object-cover"
|
class="h-8 w-8 flex-none rounded-full object-cover"
|
||||||
/>
|
/>
|
||||||
<Name
|
<Name
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
pubkey={merit.Pubkey}
|
pubkey={merit.Pubkey}
|
||||||
class="hidden max-w-32 truncate p-2 md:inline-block"
|
class="hidden max-w-32 truncate p-1 md:inline-block"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
@@ -133,10 +134,11 @@
|
|||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell class="table-cell">{merit.Sats}</Table.Cell>
|
<Table.Cell class="table-cell">{merit.Sats}</Table.Cell>
|
||||||
<Table.Cell class="table-cell">{merit.Merits}</Table.Cell>
|
<Table.Cell class="table-cell">{merit.Merits}</Table.Cell>
|
||||||
|
<Table.Cell class="table-cell text-center">{status(merit).toUpperCase()}</Table.Cell>
|
||||||
<Table.Cell class="hidden text-right md:table-cell"
|
<Table.Cell class="hidden text-right md:table-cell"
|
||||||
>{unixToRelativeTime(merit.TimeStamp * 1000)}</Table.Cell
|
>{unixToRelativeTime(merit.TimeStamp * 1000)}</Table.Cell
|
||||||
>
|
>
|
||||||
<Table.Cell class="table-cell">{status(merit).toUpperCase()}</Table.Cell>
|
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
{/each}
|
{/each}
|
||||||
{#if $merits.size > $meritsTruncated.length}
|
{#if $merits.size > $meritsTruncated.length}
|
||||||
|
|||||||
@@ -8,17 +8,25 @@
|
|||||||
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
||||||
import { ndk } from '@/ndk';
|
import { ndk } from '@/ndk';
|
||||||
|
|
||||||
export let rocket: NDKEvent;
|
export let rocket: Rocket;
|
||||||
export let unratifiedZaps:number = 0;
|
export let unratifiedZaps: Map<string, number>;
|
||||||
|
|
||||||
let parsedRocket = new Rocket(rocket);
|
let unratifiedZapsAmount = 0;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
unratifiedZapsAmount = 0;
|
||||||
|
for (let [_, a] of unratifiedZaps) {
|
||||||
|
unratifiedZapsAmount += a / 1000;
|
||||||
|
}
|
||||||
|
unratifiedZapsAmount = unratifiedZapsAmount;
|
||||||
|
}
|
||||||
let _merits: { pubkey: string; merits: number; sats: number }[] = [];
|
let _merits: { pubkey: string; merits: number; sats: number }[] = [];
|
||||||
|
|
||||||
let merits = writable(_merits);
|
let merits = writable(_merits);
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
let m = new Map<string, { merits: number; sats: number }>();
|
let m = new Map<string, { merits: number; sats: number }>();
|
||||||
for (let [_, amr] of parsedRocket.ApprovedMeritRequests()) {
|
for (let [_, amr] of rocket.ApprovedMeritRequests()) {
|
||||||
let existing = m.get(amr.Pubkey);
|
let existing = m.get(amr.Pubkey);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
existing = { merits: 0, sats: 0 };
|
existing = { merits: 0, sats: 0 };
|
||||||
@@ -29,12 +37,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//calculate percentage ownership of each pubkey and divide the unratified sats among them (round up to nearest sat):
|
//calculate percentage ownership of each pubkey and divide the unratified sats among them (round up to nearest sat):
|
||||||
let satsPerMeritPercentage = unratifiedZaps/100
|
let satsPerMeritPercentage = unratifiedZapsAmount / 100;
|
||||||
let totalMerits = parsedRocket.TotalMerits()
|
let totalMerits = rocket.TotalMerits();
|
||||||
for (let [id, _m] of m) {
|
for (let [id, _m] of m) {
|
||||||
_m.sats += (((_m.merits/totalMerits)*100)*satsPerMeritPercentage)
|
_m.sats += (_m.merits / totalMerits) * 100 * satsPerMeritPercentage;
|
||||||
_m.sats = Math.round(_m.sats)
|
_m.sats = Math.round(_m.sats);
|
||||||
m.set(id, _m)
|
m.set(id, _m);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _merits: { pubkey: string; merits: number; sats: number }[] = [];
|
let _merits: { pubkey: string; merits: number; sats: number }[] = [];
|
||||||
@@ -42,16 +50,16 @@
|
|||||||
_merits.push({ pubkey: pubkey, merits: _m.merits, sats: _m.sats });
|
_merits.push({ pubkey: pubkey, merits: _m.merits, sats: _m.sats });
|
||||||
}
|
}
|
||||||
if (_merits.length == 0) {
|
if (_merits.length == 0) {
|
||||||
_merits.push({pubkey: rocket.pubkey, merits: 1, sats: 0})
|
_merits.push({ pubkey: rocket.Event.pubkey, merits: 1, sats: 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
merits.set(_merits);
|
merits.set(_merits);
|
||||||
}
|
}
|
||||||
|
|
||||||
const COLORS = ["bg-pink-800", 'bg-red-800', 'bg-purple-800', 'bg-blue-800'];
|
const COLORS = ['bg-pink-800', 'bg-red-800', 'bg-purple-800', 'bg-blue-800'];
|
||||||
|
|
||||||
function c(i:number) {
|
function c(i: number) {
|
||||||
return COLORS[i]
|
return COLORS[i];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -60,13 +68,13 @@
|
|||||||
<Card.Title>Merits and Satflow</Card.Title>
|
<Card.Title>Merits and Satflow</Card.Title>
|
||||||
<Card.Description class="grid grid-cols-2">
|
<Card.Description class="grid grid-cols-2">
|
||||||
<div class=" grid-cols-1">
|
<div class=" grid-cols-1">
|
||||||
This graph displays the Meritization of equity in {rocket.getMatchingTags('d')[0][1]}
|
This graph displays the Meritization of equity in {rocket.Name()}
|
||||||
<Pie data={$merits}/>
|
<Pie data={$merits} />
|
||||||
</div>
|
</div>
|
||||||
<div class=" grid-cols-1">
|
<div class=" grid-cols-1">
|
||||||
<Table.Root>
|
<Table.Root>
|
||||||
<Table.Header>
|
<Table.Header>
|
||||||
<Table.Row>
|
<Table.Row class="">
|
||||||
<Table.Head>Participant</Table.Head>
|
<Table.Head>Participant</Table.Head>
|
||||||
<Table.Head class="hidden md:table-cell">Merits</Table.Head>
|
<Table.Head class="hidden md:table-cell">Merits</Table.Head>
|
||||||
<Table.Head class="text-right">Revenue (Sats)</Table.Head>
|
<Table.Head class="text-right">Revenue (Sats)</Table.Head>
|
||||||
@@ -80,12 +88,12 @@
|
|||||||
<Avatar
|
<Avatar
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
{pubkey}
|
{pubkey}
|
||||||
class="h-10 w-10 flex-none rounded-full object-cover"
|
class="h-8 w-8 flex-none rounded-full object-cover"
|
||||||
/>
|
/>
|
||||||
<Name
|
<Name
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
{pubkey}
|
{pubkey}
|
||||||
class="hidden max-w-32 truncate p-2 md:inline-block"
|
class="hidden max-w-32 truncate p-1 md:inline-block"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
import { ChevronLeft, ChevronRight } from 'lucide-svelte';
|
import { ChevronLeft, ChevronRight } from 'lucide-svelte';
|
||||||
|
|
||||||
export let rocket: Rocket;
|
export let rocket: Rocket;
|
||||||
export let unratifiedZaps = 0;
|
export let unratifiedZaps:Map<string, number>;
|
||||||
|
|
||||||
let products = writable(new Map<string, Product>());
|
let products = writable(new Map<string, Product>());
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as Table from '@/components/ui/table';
|
import * as Table from '@/components/ui/table';
|
||||||
import { Product, Rocket, ValidateZapPublisher, ZapPurchase, type RocketProduct } from '@/event_helpers/rockets';
|
import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets';
|
||||||
import { unixToRelativeTime } from '@/helpers';
|
import { unixToRelativeTime } from '@/helpers';
|
||||||
import { ndk } from '@/ndk';
|
import { ndk } from '@/ndk';
|
||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
|
||||||
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import { derived, writable } from 'svelte/store';
|
import { derived, writable } from 'svelte/store';
|
||||||
|
|
||||||
export let products: Product[];
|
export let products: Product[];
|
||||||
//export let products: Product[];
|
//export let products: Product[];
|
||||||
export let rocket: Rocket;
|
export let rocket: Rocket;
|
||||||
|
|
||||||
export let unratifiedZaps:number = 0; //todo upstream bind this and parse outstanding zaps to merits and satflow component.
|
export let unratifiedZaps:Map<string, number>; //todo upstream bind this and pass outstanding zaps to merits and satflow component.
|
||||||
|
|
||||||
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] }],
|
||||||
@@ -90,11 +89,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
validatedZapsNotInRocket.subscribe(zaps=>{
|
validatedZapsNotInRocket.subscribe(zaps=>{
|
||||||
let total = 0
|
|
||||||
for (let [_, z] of zaps) {
|
for (let [_, z] of zaps) {
|
||||||
total += z.Amount
|
unratifiedZaps.set(z.ZapReceipt.id, z.Amount)
|
||||||
}
|
}
|
||||||
unratifiedZaps = total/1000
|
unratifiedZaps = unratifiedZaps
|
||||||
})
|
})
|
||||||
|
|
||||||
//todo: get existing purchases from rocket and render them
|
//todo: get existing purchases from rocket and render them
|
||||||
@@ -127,12 +125,12 @@
|
|||||||
<Avatar
|
<Avatar
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
pubkey={purchase.BuyerPubkey}
|
pubkey={purchase.BuyerPubkey}
|
||||||
class="h-10 w-10 flex-none rounded-full object-cover"
|
class="h-8 w-8 flex-none rounded-full object-cover"
|
||||||
/>
|
/>
|
||||||
<Name
|
<Name
|
||||||
ndk={$ndk}
|
ndk={$ndk}
|
||||||
pubkey={purchase.BuyerPubkey}
|
pubkey={purchase.BuyerPubkey}
|
||||||
class="inline-block max-w-32 truncate p-2"
|
class="inline-block max-w-32 truncate p-1"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
export let rocket: NDKEvent;
|
export let rocket: NDKEvent;
|
||||||
|
|
||||||
$: unratifiedZaps = 0
|
$: unratifiedZaps = new Map<string, number>()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
<main
|
<main
|
||||||
class="grid flex-1 items-start gap-4 p-4 sm:px-6 sm:py-0 md:gap-2 lg:grid-cols-3 xl:grid-cols-3"
|
class="grid flex-1 items-start gap-4 p-4 sm:px-6 sm:py-0 md:gap-2 lg:grid-cols-3 xl:grid-cols-3"
|
||||||
>
|
>
|
||||||
<MeritsAndSatflow {unratifiedZaps} {rocket} />
|
<MeritsAndSatflow {unratifiedZaps} rocket={new Rocket(rocket)} />
|
||||||
|
|
||||||
<ProductFomo bind:unratifiedZaps rocket={new Rocket(rocket)} />
|
<ProductFomo bind:unratifiedZaps rocket={new Rocket(rocket)} />
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
for (let e of $rockets) {
|
for (let e of $rockets) {
|
||||||
let existing = _r.get(`${e.pubkey}${e.dTag}`)
|
let existing = _r.get(`${e.pubkey}${e.dTag}`)
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
console.log(e)
|
|
||||||
existing = new Rocket(e)
|
existing = new Rocket(e)
|
||||||
}
|
}
|
||||||
if (existing.Event.created_at <= e.created_at) {
|
if (existing.Event.created_at <= e.created_at) {
|
||||||
|
|||||||
Reference in New Issue
Block a user