Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions api/src/routes/settlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ router.post('/simulate', (req: Request, res: Response) => {
}

// Basic input validation
const STELLAR_ADDRESS_RE = /^G[A-Z2-7]{55}$/;
for (const r of remittances) {
if (
typeof r !== 'object' ||
Expand All @@ -157,6 +158,18 @@ router.post('/simulate', (req: Request, res: Response) => {
};
return res.status(400).json(err);
}
const item = r as SimulateRemittanceInput;
if (!STELLAR_ADDRESS_RE.test(item.sender) || !STELLAR_ADDRESS_RE.test(item.agent)) {
const err: ErrorResponse = {
success: false,
error: {
message: 'sender and agent must be valid Stellar addresses (G... 56 characters)',
code: 'INVALID_INPUT',
},
timestamp: new Date().toISOString(),
};
return res.status(400).json(err);
}
}

const inputs = remittances as SimulateRemittanceInput[];
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/components/DisputeResolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export default function DisputeResolution() {
const [auditLog, setAuditLog] = useState<AuditLogItem[]>([]);
const [resolving, setResolving] = useState<string | number | null>(null);
const [confirmOpen, setConfirmOpen] = useState<ConfirmState | null>(null);
const [page, setPage] = useState(1);
const [hasMore, setHasMore] = useState(false);
const [resolvedTxHash, setResolvedTxHash] = useState<string | null>(null);

useEffect(() => {
void fetchDisputes(1);
Expand Down Expand Up @@ -131,14 +130,18 @@ export default function DisputeResolution() {
setConfirmOpen(null);
setResolving(id);
setError(null);
setResolvedTxHash(null);
try {
const res = await fetch(`${API_URL}/api/disputes/${id}/resolve`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ in_favour_of_sender: inFavourOfSender }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
await fetchDisputes(page);
const data = await res.json() as Record<string, unknown>;
const txHash = typeof data.tx_hash === 'string' ? data.tx_hash : null;
setResolvedTxHash(txHash);
await fetchDisputes();
await fetchAuditLog();
} catch (e: unknown) {
setError(e instanceof Error ? e.message : 'Unknown error');
Expand All @@ -153,6 +156,21 @@ export default function DisputeResolution() {

{error && <div className="error" role="alert">{error}</div>}

{resolvedTxHash && (
<div role="status" style={{ background: '#f0fff4', border: '1px solid #9ae6b4', borderRadius: '8px', padding: '12px 16px', marginBottom: '16px', fontSize: '0.85rem' }}>
✅ Dispute resolved on-chain.{' '}
<strong>Tx:</strong>{' '}
<a
href={`https://stellar.expert/explorer/public/tx/${resolvedTxHash}`}
target="_blank"
rel="noopener noreferrer"
style={{ wordBreak: 'break-all' }}
>
{resolvedTxHash}
</a>
</div>
)}

{confirmOpen && (
<div
role="dialog"
Expand Down
39 changes: 33 additions & 6 deletions frontend/src/components/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useCallback, useEffect, useRef } from 'react';

import './Toast.css';

export type ToastType = 'success' | 'error' | 'info' | 'warning';
Expand All @@ -22,19 +23,45 @@ interface ToastItemProps {
onDismiss: (id: string) => void;
}

const DEFAULT_DURATION: Record<ToastType, number> = {
error: 5000,
success: 3000,
info: 4000,
warning: 4000,
};

function ToastItem({ toast, onDismiss }: ToastItemProps) {
const duration = toast.duration ?? 4000;
const duration = toast.duration ?? DEFAULT_DURATION[toast.type];
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const remainingRef = useRef(duration);
const startRef = useRef<number>(0);

useEffect(() => {
if (duration > 0) {
timerRef.current = setTimeout(() => onDismiss(toast.id), duration);
const startTimer = useCallback(() => {
if (duration <= 0) return;
startRef.current = Date.now();
timerRef.current = setTimeout(() => onDismiss(toast.id), remainingRef.current);
}, [duration, toast.id, onDismiss]);

const pauseTimer = useCallback(() => {
if (timerRef.current) {
clearTimeout(timerRef.current);
remainingRef.current -= Date.now() - startRef.current;
}
}, []);

useEffect(() => {
startTimer();
return () => { if (timerRef.current) clearTimeout(timerRef.current); };
}, [toast.id, duration, onDismiss]);
}, [startTimer]);

return (
<div className={`toast ${toast.type}`} role="alert" aria-live="polite">
<div
className={`toast ${toast.type}`}
role="alert"
aria-live="polite"
onMouseEnter={pauseTimer}
onMouseLeave={startTimer}
>
<span className="toast-icon" aria-hidden="true">{ICONS[toast.type]}</span>
<span className="toast-message">{toast.message}</span>
<button
Expand Down
19 changes: 1 addition & 18 deletions sdk/src/governance.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { parseProposal } from "../src/convert.js";
import type { Proposal } from "../src/types.js";
import { xdr, nativeToScVal } from "@stellar/stellar-sdk";

// ─── Helpers ─────────────────────────────────────────────────────────────────

function makeProposalScVal(overrides: Record<string, unknown> = {}): xdr.ScVal {
const base = {
id: 1,
proposer: "GABC",
action: { UpdateFee: 300 },
state: { Pending: {} },
created_at: 1000,
expiry: 2000,
approval_count: 1,
approval_timestamp: null,
...overrides,
};
return nativeToScVal(base);
}
import { makeProposalScVal } from "../src/test-utils.js";

// ─── parseProposal ────────────────────────────────────────────────────────────

Expand Down
16 changes: 16 additions & 0 deletions sdk/src/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { xdr, nativeToScVal } from "@stellar/stellar-sdk";

export function makeProposalScVal(overrides: Record<string, unknown> = {}): xdr.ScVal {
const base = {
id: 1,
proposer: "GABC",
action: { UpdateFee: 300 },
state: { Pending: {} },
created_at: 1000,
expiry: 2000,
approval_count: 1,
approval_timestamp: null,
...overrides,
};
return nativeToScVal(base);
}