fix: base cancel-donation countdown on server-confirmed time - #1023
Open
Queen-T16 wants to merge 1 commit into
Open
fix: base cancel-donation countdown on server-confirmed time#1023Queen-T16 wants to merge 1 commit into
Queen-T16 wants to merge 1 commit into
Conversation
Anchor the grace-period countdown and expiry purge on a server-confirmed timestamp instead of the raw client clock. Derive a client<->server clock offset from the /api/health endpoint and apply it in useDonationGracePeriod (start/purge) and CancelDonationBanner (remaining seconds), so a skewed system clock no longer shows time remaining after the on-chain window has closed. Falls back to the client clock when the server is unreachable. Adds tests simulating a client clock 5 minutes behind the server for both the hook and the banner. Closes Iris-IV#811
Contributor
|
Auto-review failed (API error). Leaving PR for human review. |
|
@Queen-T16 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
well engineered fix: deriving the offset from /api/health's timestamp with a midpoint latency estimate, a shared cached promise so all consumers make one round-trip, a skew sanity bound, and graceful fallback to the client clock, plus thorough tests for skew, purge, unreachable server, and invalid timestamps. a couple of notes, non-blocking:
gate: branch is in conflict with main; rebase and rerun CI, then good to merge. |
This was referenced Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #811 — [Wallet] CancelDonationBanner countdown does not account for clock drift between client and server.
The grace-period countdown and expiry purge were previously anchored to the client's local
Date.now(). If the user's system clock was off, the banner could keep showing time remaining even after the on-chain grace period had actually closed. This PR anchors both the countdown and the purge on a server-confirmed timestamp.Approach
src/hooks/useDonationGracePeriod.tsGET /api/healthendpoint (already server-confirmed) and derives aclient <-> serverclock offset (ms).startGracePeriodnow setstimestamp/expiresAtfrom the server-adjusted clock.offset 0) — the app keeps working offline.getServerTimeMs), so the hook and banner share a single round-trip.resetServerTimeCache()is exported for tests / re-sync.src/components/CancelDonationBanner.tsxuseServerTimeOffset()and computesremainingSecondsfromexpiresAt - (Date.now() + offsetMs), so the displayed countdown matches the server/on-chain deadline regardless of client clock skew.src/__tests__/hooks/useDonationGracePeriod.test.tsxsrc/__tests__/components/CancelDonationBanner.test.tsxAcceptance criteria
Date.now().Test coverage
New tests simulate a client clock 5 minutes behind the server:
startGracePeriodstamps donations on server time (expiresAt = serverNow + 60s), not client time.60sremaining where a raw client clock would show360s.0s(and never negative) once the server-confirmed window has closed.All new tests pass. Lint is clean for the touched files (one pre-existing
onFinalizeunused-prop warning remains).Out of scope
Implementing the broader "Cancel Donation grace period" feature end-to-end (tracked in #640) is intentionally left untouched.