Skip to content

Commit de5a19b

Browse files
sktbrdclaude
andcommitted
fix(poidh): remove Date.now() from render — use effect-driven state for isExpired
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a5ca9d7 commit de5a19b

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/components/bounties/VoteDashboard.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@ import { POIDH_ABI } from '@/lib/poidh/abi';
88
import { POIDH_CONTRACTS } from '@/lib/poidh/config';
99
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
1010

11-
function useDeadlineCountdown(deadlineSeconds: number): string {
11+
function useDeadlineCountdown(deadlineSeconds: number): { label: string; expired: boolean } {
1212
const calc = () => {
13-
if (!deadlineSeconds) return '';
13+
if (!deadlineSeconds) return { label: '', expired: false };
1414
const diff = deadlineSeconds * 1000 - Date.now();
15-
if (diff <= 0) return 'Expired';
15+
if (diff <= 0) return { label: 'Expired', expired: true };
1616
const hours = Math.floor(diff / 3_600_000);
1717
const minutes = Math.floor((diff % 3_600_000) / 60_000);
18-
if (hours > 0) return `${hours}h ${minutes}m`;
19-
return `${minutes}m`;
18+
return { label: hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`, expired: false };
2019
};
2120

22-
const [label, setLabel] = useState(calc);
21+
const [state, setState] = useState(calc);
2322

2423
useEffect(() => {
2524
if (!deadlineSeconds) return;
26-
const id = setInterval(() => setLabel(calc()), 30_000);
25+
const id = setInterval(() => setState(calc()), 30_000);
2726
return () => clearInterval(id);
2827
// eslint-disable-next-line react-hooks/exhaustive-deps
2928
}, [deadlineSeconds]);
3029

31-
return label;
30+
return state;
3231
}
3332

3433
interface VoteDashboardProps {
@@ -52,7 +51,7 @@ export function VoteDashboard({ chainId, onChainBountyId }: VoteDashboardProps)
5251
});
5352

5453
const deadlineSec = tracker ? Number(tracker[2]) : 0;
55-
const deadline = useDeadlineCountdown(deadlineSec);
54+
const { label: deadline, expired: isExpired } = useDeadlineCountdown(deadlineSec);
5655

5756
if (!tracker || deadlineSec === 0) return null;
5857

@@ -62,7 +61,6 @@ export function VoteDashboard({ chainId, onChainBountyId }: VoteDashboardProps)
6261
const noEth = parseFloat(formatEther(noWei));
6362
const total = yesEth + noEth;
6463
const yesPercent = total > 0 ? Math.round((yesEth / total) * 100) : 50;
65-
const isExpired = deadlineSec * 1000 < Date.now();
6664

6765
return (
6866
<Card className="border-yellow-500/20 bg-yellow-500/5">

0 commit comments

Comments
 (0)