Support staged group bid funding
Verify and publish checkpoint container / container (push) Successful in 10m27s

This commit is contained in:
Quintine committed 2026-10-28 23:22:50 +11:00
1 parent 34aa64cdef
commit 1eeeb32566
12 files changed
+426 -37

No files matched your search

+9 -5
View File
@@ -4,7 +4,7 @@ import { useId, useState } from 'react';
/** Only the viewer's own pledges and contributions offered to that viewer. */
export type CoalitionFundingView = {
targets: readonly { id: string; name: string; pledged: number; maximum: number }[];
targets: readonly { id: string; name: string; pledged: number; maximum: number; minimum?: number }[];
incoming: readonly { donor: string; name: string; amount: number }[];
blocked: string | null;
};
@@ -35,13 +35,15 @@ export function coalitionPledgeAction(
): CoalitionPledgeAction | null {
if (busy || blocked || !/^(0|[1-9]\d*)$/.test(raw)) return null;
const amount = Number(raw);
if (!Number.isSafeInteger(amount) || amount > safeMaximum(target.maximum)) return null;
if (!Number.isSafeInteger(amount) || amount < safeMaximum(target.minimum ?? 0) ||
amount > safeMaximum(target.maximum)) return null;
return { type: 'coalitionPledge', recipient: target.id, amount };
}
export function CoalitionFunding({ view, busy = false, act, onContributionsChange }: {
export function CoalitionFunding({ view, busy = false, act, onContributionsChange, purpose = 'shipment' }: {
view: CoalitionFundingView;
busy?: boolean;
purpose?: 'bid' | 'shipment';
act: (action: CoalitionPledgeAction) => void;
onContributionsChange?: (contributions: CoalitionFundingContribution[]) => void;
}) {
@@ -66,9 +68,11 @@ export function CoalitionFunding({ view, busy = false, act, onContributionsChang
const raw = pledges[target.id] ?? String(target.pledged);
const action = coalitionPledgeAction(target, raw, view.blocked, busy);
const inputId = `${id}-pledge-${index}`;
const minimum = safeMaximum(target.minimum ?? 0);
return <div key={target.id} className="space-y-2">
<label htmlFor={inputId}>Pledge to {target.name} · {target.pledged} spice currently set aside</label>
<input id={inputId} type="number" min={0} max={safeMaximum(target.maximum)} step={1}
{minimum > 0 && <p>The current high bid commits {minimum} spice of this pledge.</p>}
<input id={inputId} type="number" min={minimum} max={safeMaximum(target.maximum)} step={1}
inputMode="numeric" value={raw} disabled={busy || !!view.blocked}
onChange={event => setPledges(previous => ({ ...previous, [target.id]: event.target.value }))} />
<button type="button" className="game-action" disabled={!action}
@@ -84,7 +88,7 @@ export function CoalitionFunding({ view, busy = false, act, onContributionsChang
return <div key={entry.donor} className="space-y-2">
<p>{entry.name}: {entry.amount} spice</p>
{onContributionsChange && <>
<label htmlFor={inputId}>Use from {entry.name} for your next shipment</label>
<label htmlFor={inputId}>Use from {entry.name} for your next {purpose}</label>
<input id={inputId} type="number" min={0} max={maximum} step={1}
inputMode="numeric" value={value} disabled={busy || !!view.blocked}
onChange={event => {