mirror of
https://github.com/aljazceru/hypergolic.git
synced 2026-02-06 06:04:22 +01:00
problem: can't see how much btc is waiting to invest in a rocket
This commit is contained in:
122
src/components/AssociatedBitcoinAddresses.svelte
Normal file
122
src/components/AssociatedBitcoinAddresses.svelte
Normal file
@@ -0,0 +1,122 @@
|
||||
<script lang="ts">
|
||||
import * as Card from '@/components/ui/card';
|
||||
import * as Table from '@/components/ui/table';
|
||||
import { BitcoinAssociation, Rocket } from '@/event_helpers/rockets';
|
||||
import { getCuckPrice } from '@/helpers';
|
||||
import { ndk } from '@/ndk';
|
||||
import { getBalance } from '@/stores/bitcoin';
|
||||
import { NDKKind } from '@nostr-dev-kit/ndk';
|
||||
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
export let rocket: Rocket;
|
||||
|
||||
let cuckprice = 0;
|
||||
|
||||
let associations = writable(new Map<string, BitcoinAssociation>());
|
||||
|
||||
onMount(() => {
|
||||
getCuckPrice().then((price) => {
|
||||
if (price) cuckprice = price;
|
||||
});
|
||||
associations.set(rocket.BitcoinAssociations());
|
||||
$associations.forEach((a) => {
|
||||
if (a.Address) {
|
||||
getBalance(a.Address)
|
||||
.then((v) => {
|
||||
a.Balance = v;
|
||||
associations.update((existing) => {
|
||||
existing.set(a.Address!, a);
|
||||
return existing;
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let amounts = derived(associations, ($associations) => {
|
||||
let amounts = new Map<string, number>();
|
||||
for (let [_, a] of $associations) {
|
||||
if (a.Balance > 0) {
|
||||
let existing = amounts.get(a.Pubkey);
|
||||
if (!existing) {
|
||||
existing = 0;
|
||||
}
|
||||
existing += a.Balance;
|
||||
amounts.set(a.Pubkey, existing);
|
||||
}
|
||||
}
|
||||
return amounts;
|
||||
});
|
||||
|
||||
let total = derived(amounts, ($amounts) => {
|
||||
let t = 0;
|
||||
for (let [_, a] of $amounts) {
|
||||
t += a;
|
||||
}
|
||||
return t;
|
||||
});
|
||||
</script>
|
||||
|
||||
<Card.Root class="sm:col-span-3">
|
||||
<Card.Header class="px-7">
|
||||
<Card.Title>Sponsors</Card.Title>
|
||||
<Card.Description
|
||||
>These people want to sponsor Contributors working on {rocket.Name()}.</Card.Description
|
||||
>
|
||||
</Card.Header>
|
||||
<Card.Content>
|
||||
<Table.Root>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.Head class="w-[200px]">Sponsor</Table.Head>
|
||||
<Table.Head class="hidden text-left md:table-cell">Amount (Sats)</Table.Head>
|
||||
<Table.Head class="hidden text-left md:table-cell">CuckLoserBucks</Table.Head>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{#each $amounts as [npub, amount], _ (npub)}
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
<div class="flex flex-nowrap">
|
||||
<Avatar
|
||||
ndk={$ndk}
|
||||
pubkey={npub}
|
||||
class="h-10 w-10 flex-none rounded-full object-cover"
|
||||
/>
|
||||
<Name
|
||||
ndk={$ndk}
|
||||
pubkey={npub}
|
||||
class="hidden max-w-32 truncate p-2 md:inline-block"
|
||||
/>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell class="hidden text-left md:table-cell">
|
||||
{amount.toLocaleString()}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="hidden text-left md:table-cell">
|
||||
${Math.floor((amount / 100000000) * cuckprice).toLocaleString()}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
{/each}
|
||||
{#if $total > 0}
|
||||
<Table.Row
|
||||
class=" bg-violet-200 hover:bg-violet-300 dark:bg-violet-950 dark:hover:bg-violet-900"
|
||||
>
|
||||
<Table.Cell>TOTAL</Table.Cell>
|
||||
<Table.Cell class="hidden text-left md:table-cell">
|
||||
{$total.toLocaleString()}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="hidden text-left md:table-cell">
|
||||
${Math.floor(($total / 100000000) * cuckprice).toLocaleString()}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
{/if}
|
||||
</Table.Body>
|
||||
</Table.Root>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
@@ -1,86 +0,0 @@
|
||||
<script lang="ts">
|
||||
import * as Card from '@/components/ui/card';
|
||||
import * as Table from '@/components/ui/table';
|
||||
import { BitcoinAssociation, Rocket } from '@/event_helpers/rockets';
|
||||
import { ndk } from '@/ndk';
|
||||
import { getBalance } from '@/stores/bitcoin';
|
||||
import { NDKKind } from '@nostr-dev-kit/ndk';
|
||||
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
|
||||
export let rocket: Rocket;
|
||||
|
||||
let _associationRequests = $ndk.storeSubscribe(
|
||||
[{ '#a': [`31108:${rocket.Event.author.pubkey}:${rocket.Name()}`], kinds: [1413 as NDKKind] }],
|
||||
{
|
||||
subId: `${rocket.Name()}_bitcoin_associations`
|
||||
}
|
||||
);
|
||||
|
||||
onDestroy(() => {
|
||||
_associationRequests?.unsubscribe();
|
||||
});
|
||||
|
||||
let addresses = new Map<string, BitcoinAssociation>();
|
||||
|
||||
onMount(() => {
|
||||
addresses = rocket.BitcoinAssociations();
|
||||
addresses.forEach((a) => {
|
||||
if (a.Address) {
|
||||
getBalance(a.Address)
|
||||
.then((v) => {
|
||||
a.Balance = v;
|
||||
addresses.set(a.Address!, a);
|
||||
addresses = addresses;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<Card.Root class="sm:col-span-3">
|
||||
<Card.Header class="px-7">
|
||||
<Card.Title>Registered Bitcoin Addresses</Card.Title>
|
||||
<Card.Description
|
||||
>These people have registered a Bitcoin address and want to sponsor Contributors working on {rocket.Name()}</Card.Description
|
||||
>
|
||||
</Card.Header>
|
||||
<Card.Content>
|
||||
<Table.Root>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.Head class="w-[200px]">Sponsor</Table.Head>
|
||||
<Table.Head class="hidden text-left md:table-cell">Amount (Sats)</Table.Head>
|
||||
<Table.Head class="table-cell">Address</Table.Head>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{#each addresses as [address, ba], _ (address)}
|
||||
<Table.Row>
|
||||
<Table.Cell>
|
||||
<div class="flex flex-nowrap">
|
||||
<Avatar
|
||||
ndk={$ndk}
|
||||
pubkey={ba.Pubkey}
|
||||
class="h-10 w-10 flex-none rounded-full object-cover"
|
||||
/>
|
||||
<Name
|
||||
ndk={$ndk}
|
||||
pubkey={ba.Pubkey}
|
||||
class="hidden max-w-32 truncate p-2 md:inline-block"
|
||||
/>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell class="hidden text-left md:table-cell">
|
||||
{ba.Balance.toLocaleString()}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="table-cell">{ba.Address}</Table.Cell>
|
||||
</Table.Row>
|
||||
{/each}
|
||||
</Table.Body>
|
||||
</Table.Root>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
@@ -12,12 +12,11 @@
|
||||
import Todo from './Todo.svelte';
|
||||
import UpdateMission from './UpdateMission.svelte';
|
||||
import { Rocket } from '@/event_helpers/rockets';
|
||||
import BitcoinAssociations from './BitcoinAssociations.svelte';
|
||||
import BitcoinAssociations from './AssociatedBitcoinAddresses.svelte';
|
||||
|
||||
export let rocket: NDKEvent;
|
||||
|
||||
$: unratifiedZaps = new Map<string, number>()
|
||||
|
||||
$: unratifiedZaps = new Map<string, number>();
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col sm:gap-4">
|
||||
@@ -44,7 +43,7 @@
|
||||
<ProposedProducts {rocket} />
|
||||
|
||||
<MeritRequests rocket={new Rocket(rocket)} />
|
||||
<BitcoinAssociations rocket={new Rocket(rocket)}/>
|
||||
<BitcoinAssociations rocket={new Rocket(rocket)} />
|
||||
<Card.Root class="sm:col-span-3">
|
||||
<Card.Header class="pb-3">
|
||||
<Card.Title>Actions</Card.Title>
|
||||
@@ -62,10 +61,6 @@
|
||||
<Card.Footer></Card.Footer>
|
||||
</Card.Root>
|
||||
|
||||
<Todo
|
||||
text={[
|
||||
'delete rocket (if current user is rocket creator) - publish deletion request'
|
||||
]}
|
||||
/>
|
||||
<Todo text={['delete rocket (if current user is rocket creator) - publish deletion request']} />
|
||||
</main>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user