diff --git a/README.md b/README.md index e1931c7..8e046bd 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,8 @@ npm run dev 提交成果和投票都必须在链上截止秒之前确认。到达截止秒时,未完成的提交或审批窗口关闭,符合条件的支持者可以退款。已在截止前批准的阶段仍可在之后提款。网页通过 `getMilestoneWindow` 读取当前截止时间和开关状态。 +短超时演示可使用两个均有出资的支持者账户。倒计时归零后,等页面确认链上已截止,再用第一位支持者领取。核对交易成功提示的实付金额,切换到第二位支持者,确认其可领金额仍与首笔领取前一致。筹款失败的退款为全额出资,里程碑超时退款按未放款的托管金额计算。 + **50% 边界测试(Remix VM):** 1. A 创建目标 **100 wei** 的项目,B/C 为支持者,D 为无关账户。deadline 输入未来的 Unix 秒数,可在浏览器控制台计算 `Math.floor(Date.now() / 1000) + 3600` 后复制数值。 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)}> -
+