feat(trades): revoke/dispute a trade record (s=revoked)

On /trades, each authored trade record gets a 'Revoke' action (with a confirm
dialog) that republishes the 31871 with s=revoked — retracting it from
reputation for a disputed or mistaken deal. The counterparty keeps their own
attestation. Revoked records are already excluded from aggregation.

Gate: 101 tests, 0 errors/warnings, boot smoke green.
This commit is contained in:
SkateSpots 2026-09-26 23:00:10 +07:00
parent 5b163c632f
commit e0e41ae625
2 changed files with 93 additions and 2 deletions

View file

@ -49,7 +49,9 @@ session with **no other memory of this project**. So:
— one implementation). Buyer/seller attestations build mutual, WoT-weighted
reputation. **No payments are implemented** — "Buy" is intentionally absent;
buyers contact the seller and settle off-app. A **`/trades`** page ("My Trades")
manages incoming requests, pending confirmations, and the user's trade records.
manages incoming requests, pending confirmations, and the user's trade records,
and can **revoke** a record (`s=revoked`, excluded from reputation) for a dispute
or mistake.
- **Cashu escrow** (marketplace): time-locked **P2PK** (lock to seller + buyer
refund key + locktime) — see **`ESCROW.md`** and `src/lib/cashuEscrow.ts`
(unit-tested). Protocol: `cashu_token` on the `31872`; each user advertises a

View file

@ -7,6 +7,13 @@ import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { LoginArea } from '@/components/auth/LoginArea';
import { TradeReputationCard } from '@/components/TradeReputationCard';
import { useCurrentUser } from '@/hooks/useCurrentUser';
@ -51,6 +58,12 @@ export default function TradesPage() {
const { data: reputation, isLoading: loadingRep } = useTradeReputation(user?.pubkey);
const [busy, setBusy] = useState<string | null>(null);
const [revokeTarget, setRevokeTarget] = useState<{
listing: { pubkey: string; identifier: string };
role: 'sold' | 'bought';
counterparty: string;
} | null>(null);
const [revoking, setRevoking] = useState(false);
useSeoMeta({
title: 'My Trades — SkateSpots',
@ -102,6 +115,33 @@ export default function TradesPage() {
}
};
const handleRevoke = async () => {
if (!revokeTarget) return;
setRevoking(true);
try {
await publishTrade({
listing: revokeTarget.listing,
role: revokeTarget.role,
counterparty: revokeTarget.counterparty,
state: 'revoked',
note: 'Retracted by the author.',
});
toast({
title: 'Trade record revoked',
description: 'It no longer counts toward reputation.',
});
setRevokeTarget(null);
} catch (e) {
toast({
title: 'Could not revoke the trade',
description: e instanceof Error ? e.message : 'Something went wrong.',
variant: 'destructive',
});
} finally {
setRevoking(false);
}
};
if (!user) {
return (
<Layout>
@ -240,7 +280,12 @@ export default function TradesPage() {
const coord = ev.tags.find(([t]) => t === 'a')?.[1];
const parsed = parseListingCoord(coord);
const d = ev.tags.find(([t]) => t === 'd')?.[1] ?? '';
const role = d.includes(':trade:sold:') ? 'Sold' : d.includes(':trade:bought:') ? 'Bought' : 'Trade';
const roleTyped: 'sold' | 'bought' | null = d.includes(':trade:sold:')
? 'sold'
: d.includes(':trade:bought:')
? 'bought'
: null;
const role = roleTyped === 'sold' ? 'Sold' : roleTyped === 'bought' ? 'Bought' : 'Trade';
const state = ev.tags.find(([t]) => t === 's')?.[1] ?? 'valid';
const counterparty = ev.tags.find(([t]) => t === 'p')?.[1];
return (
@ -272,12 +317,56 @@ export default function TradesPage() {
View listing <ArrowRight className="inline h-3 w-3" />
</Link>
)}
{roleTyped && counterparty && parsed && (
<button
type="button"
onClick={() =>
setRevokeTarget({
listing: { pubkey: parsed.pubkey, identifier: parsed.identifier },
role: roleTyped,
counterparty,
})
}
className="shrink-0 text-xs text-red-400/70 hover:text-red-400"
>
Revoke
</button>
)}
</CardContent>
</Card>
);
})}
</section>
</div>
<Dialog open={!!revokeTarget} onOpenChange={(o) => !o && setRevokeTarget(null)}>
<DialogContent className="border-2 border-red-500/30 bg-black sm:max-w-md">
<DialogHeader>
<DialogTitle className="text-white">Revoke this trade record?</DialogTitle>
<DialogDescription className="text-sm text-gray-400">
It will stop counting toward your reputation. The other party keeps their own
attestation. Use this for a disputed or mistaken deal.
</DialogDescription>
</DialogHeader>
<div className="flex gap-2 pt-1">
<Button
variant="outline"
onClick={() => setRevokeTarget(null)}
className="flex-1 border-white/15"
>
Cancel
</Button>
<Button
onClick={handleRevoke}
disabled={revoking}
className="flex-1 gap-2 bg-red-500 font-bold text-white hover:bg-red-500/90"
>
{revoking ? <Loader2 className="h-4 w-4 animate-spin" /> : null}
Revoke
</Button>
</div>
</DialogContent>
</Dialog>
</Layout>
);
}