problem: not clear which rockets are for testing, and which are real

This commit is contained in:
Bob
2024-08-08 23:31:02 +08:00
parent 2186f6d1f3
commit 4db25ed767
6 changed files with 326 additions and 194 deletions

View File

@@ -4,15 +4,18 @@
import Button from '@/components/ui/button/button.svelte';
import { ndk } from '@/ndk';
import { currentUser } from '@/stores/session';
import ExclamationTriangle from 'svelte-radix/ExclamationTriangle.svelte';
import * as Alert from '$lib/components/ui/alert/index.js';
import validate from 'bitcoin-address-validation';
export let amrAuction: AMRAuction | undefined;
export let rocket: Rocket;
export let selected_amrs: Map<string, AMRAuction>;
export let selected_amrs: AMRAuction | undefined;
let bitcoinAddress: string = '';
$: bitcoinAddressInValid = true;
$: bitcoinAddressError = '';
$: isTestRocket = rocket.Name().toLowerCase().includes('test');
$: if (bitcoinAddress) {
if (!validate(bitcoinAddress)) {
@@ -49,7 +52,7 @@
console.log('AMRAuction', e);
e.publish().then((x) => {
console.log(x, e);
selected_amrs = new Map<string, AMRAuction>();
selected_amrs = undefined;
//goto(`${base}/rockets/${getRocketURL(e)}`);
});
}
@@ -60,6 +63,15 @@
You are selling {amrAuction.Merits} Merits
</div>
<div class="m-2 flex flex-col">
{#if isTestRocket}
<Alert.Root variant="destructive">
<ExclamationTriangle class="h-4 w-4" />
<Alert.Title>Warning</Alert.Title>
<Alert.Description
>Please do not enter a real Bitcoin address, as this is a test rocket.</Alert.Description
>
</Alert.Root>
{/if}
<div class="flex">
<Input
bind:value={bitcoinAddress}

View File

@@ -9,10 +9,11 @@
import { ChevronRight } from 'lucide-svelte';
export let rocket: Rocket;
//$page.url.searchParams.get("tab")
</script>
<Card.Root class="w-[350px]">
<Card.Root class="flex w-[350px] flex-col justify-between">
<Card.Header>
<Card.Title>{rocket.Name()}</Card.Title>
<Card.Description>{rocket.Mission()}</Card.Description>
@@ -27,17 +28,19 @@
<Name ndk={$ndk} pubkey={rocket.Event.pubkey} class="inline-block truncate" />
</div>
</Card.Content>
<Card.Footer class="flex justify-between">
<Button
on:click={() => {
console.log(rocket.Event.rawEvent());
}}
variant="outline">Print to Console</Button
>
<Button
on:click={() => {
goto(`${base}/rockets/${rocket.URL()}`);
}}>View Full Rocket<ChevronRight class="h-4 w-4" /></Button
>
<Card.Footer>
<div class="flex justify-between gap-2">
<Button
on:click={() => {
console.log(rocket.Event.rawEvent());
}}
variant="outline">Print to Console</Button
>
<Button
on:click={() => {
goto(`${base}/rockets/${rocket.URL()}`);
}}>View Full Rocket<ChevronRight class="h-4 w-4" /></Button
>
</div>
</Card.Footer>
</Card.Root>

View File

@@ -0,0 +1,103 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { Checkbox } from '@/components/ui/checkbox';
import * as Table from '@/components/ui/table';
import { currentUser } from '@/stores/session';
import { type RocketAMR, AMRAuction, Rocket } from '@/event_helpers/rockets';
import CreateAMRAuction from './CreateAMRAuction.svelte';
import Heading from './Heading.svelte';
export let rocket: Rocket;
export let amr: RocketAMR[];
let selected_amrs: AMRAuction | undefined;
function toggleSelected(amr: RocketAMR) {
if (!selected_amrs) {
selected_amrs = new AMRAuction(rocket.Event);
}
let existing = selected_amrs;
if (existing.AMRIDs.includes(amr.ID)) {
existing.Pop(amr);
} else {
existing.Push(amr);
}
selected_amrs = existing;
}
function getSelectedStatus(id: string, data: AMRAuction): boolean {
let has = false;
let amr = data;
if (amr) {
has = amr.AMRIDs.includes(id);
}
return has;
}
</script>
{#if $currentUser && amr.length > 0}
<Heading title={`ROCKET: ${rocket.Name()}`} />
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head class="w-[100px]">Selected</Table.Head>
<Table.Head class="w-[10px]">AMR</Table.Head>
<Table.Head>Merits</Table.Head>
<Table.Head>Status</Table.Head>
<Table.Head>Receiving Address</Table.Head>
<Table.Head class="text-right">Sats (approx)</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each rocket.PendingAMRAuctions().filter((r) => {
return Boolean(r.Owner == $currentUser.pubkey);
}) as p}
<Table.Row class="bg-purple-500 hover:bg-purple-600">
<Table.Cell><Checkbox /></Table.Cell>
<Table.Cell>{p.AMRIDs.length > 1 ? 'multiple' : p.AMRIDs[0].substring(0, 12)}</Table.Cell>
<Table.Cell>{p.Merits}</Table.Cell>
<Table.Cell>Pending</Table.Cell>
<Table.Cell>{p.RxAddress}</Table.Cell>
<Table.Cell class="text-right">{p.Merits}</Table.Cell>
</Table.Row>
{/each}
{#each amr as a, id (a.ID)}
{#if rocket.CanThisAMRBeSold(a.ID)}
<Table.Row
class={getSelectedStatus(a.ID, selected_amrs)
? 'bg-orange-500 hover:bg-orange-500'
: ''}
>
<Table.Cell
><Checkbox
disabled={Boolean(a.Extra?.eventAMR)}
id={a.ID}
checked={getSelectedStatus(a.ID, selected_amrs)}
on:click={() => {
toggleSelected(a);
}}
/></Table.Cell
>
<Table.Cell>
<span
class="cursor-pointer font-medium underline"
on:click={() => {
goto(`${base}/rockets/merits/${a.ID}`);
}}
>
{a.ID.substring(0, 6)}
</span>
</Table.Cell>
<Table.Cell>{a.Merits}</Table.Cell>
<Table.Cell>{a.Extra?.eventAMR ? 'pending' : 'Eligible'}</Table.Cell>
<Table.Cell>{a.Extra?.eventAMR?.RxAddress}</Table.Cell>
<Table.Cell class="text-right">{a.Merits}</Table.Cell>
</Table.Row>
{/if}
{/each}
</Table.Body>
</Table.Root>
<CreateAMRAuction {rocket} amrAuction={selected_amrs} bind:selected_amrs />
{/if}