From 22876513c14b8703d36fffbaa3b8047410cd86ce Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 5 Nov 2026 09:25:07 +0800 Subject: [PATCH 1/2] fix(ui): align refund actions with on-chain deadlines --- src/App.jsx | 255 +++++++++++++++++++++++------------------- src/contract.js | 9 ++ src/utils.js | 25 +++++ tests/utils.test.mjs | 35 ++++++ tests/wallet.test.mjs | 25 +++++ 5 files changed, 234 insertions(+), 115 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 72ba6de..80f527c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -13,15 +13,19 @@ import { readExpiredRefundAmount, readMilestoneWindow, readProvider, + refundAmountFromReceipt, switchToSepolia, } from "./contract.js"; import { budget, + deadlineView, errorMessage, eth, + expiryRefundState, matchesFilter, percent, positiveEth, + remainingText, safeUrl, shortAddress, } from "./utils.js"; @@ -46,20 +50,13 @@ function Badge({ status, expired }) { ); } -// Cards need a reason to act now, so show time left instead of a raw timestamp. -function countdown(deadlineSec, now) { - const left = Number(deadlineSec) - now; - if (left <= 0) return { text: "Deadline passed", urgent: false, over: true }; - const days = Math.floor(left / 86400); - const hours = Math.floor((left % 86400) / 3600); - const minutes = Math.floor((left % 3600) / 60); - const text = - days > 0 - ? `${days}d ${hours}h left` - : hours > 0 - ? `${hours}h ${minutes}m left` - : `${minutes}m left`; - return { text, urgent: left < 86400, over: false }; +function fundingDeadlineView(project, blockTimestamp, now) { + if (project.status !== 0n) return null; + return deadlineView( + project.deadline, + BigInt(blockTimestamp) < project.deadline, + now, + ); } // Stage position is already on chain, so the card can show progress for free. @@ -72,17 +69,6 @@ function stageText(project) { return `Target ${eth(project.target)} ETH`; } -// Short form for deadline hints: "3d 4h" / "5h 12m" / "9m". -function remainingText(seconds) { - const left = Math.max(0, Math.floor(Number(seconds))); - const days = Math.floor(left / 86400); - const hours = Math.floor((left % 86400) / 3600); - const minutes = Math.floor((left % 3600) / 60); - if (days > 0) return `${days}d ${hours}h`; - if (hours > 0) return `${hours}h ${minutes}m`; - return `${minutes}m`; -} - function Progress({ value, label, tone }) { return (
= Number(p.deadline); + const fundingWindow = fundingDeadlineView(p, blockTimestamp, now); + const expired = fundingWindow?.state === "closed"; const remainingTarget = p.target - p.totalRaised; async function contribute(event) { @@ -453,6 +440,10 @@ function ProjectDetails({ data, account, ready, busy, now, transact, onClose })

)} + {fundingWindow?.state === "confirming" && ( +

Waiting for a block to confirm the funding deadline.

+ )} + {p.status === 0n && !expired && (isCreator ? ( @@ -502,13 +493,16 @@ function ProjectDetails({ data, account, ready, busy, now, transact, onClose }) )} {p.status === 2n && contribution > 0n && !refunded && ( - + <> +

Funding failed. You can reclaim your full contribution.

+ + )} {p.status === 3n && ( @@ -526,40 +520,30 @@ function ProjectDetails({ data, account, ready, busy, now, transact, onClose }) const isCurrentStage = BigInt(index) === p.currentMilestone; const current = p.status === 1n && isCurrentStage; const projected = p.status === 0n; - const hasPendingWindow = - isCurrentStage && (p.status === 1n || p.status === 4n) && !m.approved; - const legacyTimeout = m.submitted ? timeouts?.approval : timeouts?.submission; - const legacyOpenedAt = m.submitted ? m.submittedAt : p.successfulAt; - const deadline = hasPendingWindow - ? milestoneWindow?.deadline ?? (legacyTimeout > 0n ? legacyOpenedAt + legacyTimeout : 0n) - : 0n; - const secondsLeft = deadline > 0n ? Number(deadline) - now : null; - const actionWindowClosed = hasPendingWindow && milestoneWindow?.open === false; - const showWindowClosed = milestoneWindow - ? actionWindowClosed - : secondsLeft !== null && secondsLeft <= 0; - const canExpireRefund = - isCurrentStage && (expiredRefundAmount ?? 0n) > 0n; - const missingRefundQuote = - isCurrentStage && - contribution > 0n && - !refunded && - expiredRefundAmount === null && - showWindowClosed; + const deadline = + isCurrentStage && milestoneWindow?.deadline > 0n + ? deadlineView(milestoneWindow.deadline, milestoneWindow.open, now) + : null; + const windowClosed = deadline?.state === "closed"; + const refundState = isCurrentStage + ? expiryRefundState(contribution, refunded, expiredRefundAmount, windowClosed) + : null; const stateLabel = m.withdrawn ? "Released" : m.approved ? "Approved" - : m.submitted - ? "In review" - : current - ? "Awaiting evidence" - : "Pending"; + : windowClosed + ? "Timed out" + : m.submitted + ? "In review" + : current + ? "Awaiting evidence" + : "Pending"; const stateClass = m.withdrawn ? "is-released" : m.approved ? "is-approved" - : m.submitted + : m.submitted && !windowClosed ? "is-review" : ""; return ( @@ -634,22 +618,31 @@ function ProjectDetails({ data, account, ready, busy, now, transact, onClose }) Needs more than 50% of contributed weight. Exactly 50% fails.

- {secondsLeft !== null && ( + {deadline?.state === "open" && (

{m.submitted - ? showWindowClosed - ? "Approval window closed. Backers can reclaim the remaining escrow." - : `Approval closes in ${remainingText(secondsLeft)}.` - : showWindowClosed - ? "No evidence submitted in time. Backers can reclaim the remaining escrow." - : `Creator has ${remainingText(secondsLeft)} to submit evidence.`} + ? `Approval closes in ${remainingText(deadline.secondsLeft)}.` + : `Creator has ${remainingText(deadline.secondsLeft)} to submit evidence.`} +

+ )} + {deadline?.state === "confirming" && ( +

Waiting for a block to confirm the milestone deadline.

+ )} + {windowClosed && ( +

+ {m.submitted ? "Approval deadline passed." : "Evidence submission deadline passed."} +

+ )} + {current && !m.approved && milestoneWindow === null && ( +

+ This deployment does not provide milestone timing. Check the configured contract address.

)}
- {current && !m.submitted && isCreator && ( + {current && milestoneWindow?.open && !m.submitted && isCreator && (
evidence(e, index)}> -
+