fix(auctions): handle auction close races without stale action buttons - #989
Open
Olajcodes wants to merge 1 commit into
Open
fix(auctions): handle auction close races without stale action buttons#989Olajcodes wants to merge 1 commit into
Olajcodes wants to merge 1 commit into
Conversation
- Add computeEffectiveStatus() to resolve Active status past endTime - Fix DutchAuctionCard interval to clear when auction ends mid-tick - Guard Purchase button against stale clicks via async pending state - Filter auctions by effective status on the listing page - Prevent duplicate purchase submissions with in-flight ref guard - Show accessible 'This auction has ended' notice on transition - Add 18 tests covering close races, boundary conditions, and purchase guards Closes Creditra#942
|
@Olajcodes 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! 🚀 |
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
Fixes auction close race conditions where stale action buttons remain interactive after an auction has logically ended. This prevents users from attempting purchases on ended auctions and ensures deterministic UI state transitions.
Problem
When a Dutch auction's
endTimepasses while the card component is mounted, two races occur:setIntervalfor price/countdown continues running unnecessarily (leaked timer)status: 'Active'is not reconciled against the actual clockChanges
src/types/dutchAuction.tscomputeEffectiveStatus(auction, nowMs)— resolves the effective status by comparingendTimeagainst wall-clock time. ReturnsCompletedwhen anActiveauction's deadline has passed, preventing stale "Active" states.src/components/DutchAuctionCard.tsxeffectiveStatuson each 1-second tick instead of relying on the staticauction.statuspropsetIntervalas soon aseffectiveStatustransitions to non-Active (no leaked timers)handlePurchasecheckseffectiveStatus !== 'Active'before firing; usesisPurchasing+purchaseAttemptRefto prevent double-click racespendingandpendingLabelprops toPendingButtonfor correctaria-busyand disabled behaviorrole="status"+aria-live="polite"message when an Active auction expires while mountedsrc/pages/DutchAuctions.tsxcomputeEffectiveStatus()so time-expired auctions move to the "completed" tab automaticallySet<string>ref to prevent duplicate purchase submissions for the same auction IDAcceptance Criteria Mapping
computeEffectiveStatushandles exact boundary (now >= endTime), pre-boundary, and terminal statuses deterministicallyActive → Completedonly via clockpurchaseAttemptRefensures only one in-flight purchase per card;purchaseInFlightRefguards the page-level handlercomputeEffectiveStatus, 10 component tests for card close-race behaviorDutchAuctionCardPropsandDutchAuctionsAPI unchangedrole="status"+aria-live="polite"announces auction end to screen readersTest Plan
computeEffectiveStatus: Active with future endTime → ActivecomputeEffectiveStatus: Active with past endTime → CompletedcomputeEffectiveStatus: Exact boundary (now === endTime) → CompletedcomputeEffectiveStatus: Terminal statuses (Completed/Cancelled) pass through unchangednpm run build)Security & Failure-Mode Handling
purchaseAttemptRefpattern ensures stale async completions don't re-enable the wrong buttoncomputeEffectiveStatusis pure/deterministic — safe for concurrent callsCloses #942