feat: replace mock marketplace flows - #568
Open
somotochukwu-dev wants to merge 1 commit into
Open
Conversation
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.
Replace mock marketplace flows with production-safe request lifecycle management
Summary
Makes marketplace interactions safe for real backend data by validating request
state, auth requirements, and error boundaries around listing fetches and bids.
Both the mock and production providers now enforce the same request contract,
raw backend payloads are sanitized before they reach the UI, and all failures
resolve to clear loading/success/failure states with safe retry behavior.
Closes #525
Changes
1. Clear loading, success, and failure states with safe retry behavior
app/marketplace/page.tsxloadListingsso stale responses cannever overwrite fresh data when a retry is triggered while a previous
request is still in flight.
refetching, an inline error banner (with disabled retry button while
loading) handles recovery, and the full-page error state only renders when
nothing has loaded yet.
app/marketplace/loading.tsxrole="status"+aria-busy="true"with screen-reader text.2. Request-shape validation before network submission
hooks/marketplaceApi.tsvalidateBidRequest()— shared structural validation of bid requests(username presence/bounds/control characters, finite positive amount,
optional minimum). Used by both providers so dev/test mirrors production.
MarketplaceAuthRequiredError,getStoredAuthToken()andMARKETPLACE_AUTH_STORAGE_KEYso authenticated endpoints validate authrequirements client-side before submitting.
sanitizeListing(s),sanitizeUserBids,sanitizeUserListings) that coerce raw JSON into domain types: ISO datestrings become
Date, string-encoded numbers become numbers, and entriesthat cannot be repaired are dropped instead of crashing components that
call
.getTime()/.toLocaleString().hooks/providers/productionMarketplaceProvider.tsplaceBidvalidates request shape locally — invalid bids never hit the wire.fetchUserBids/fetchUserListingsfail fast with a clear signed-outmessage instead of making doomed network calls; the bearer token is attached
per-request and never logged or embedded in error messages.
hooks/providers/mockMarketplaceProvider.tsplaceBidenforces the exact same validation contract as production andrejects invalid input immediately (no simulated wallet delay).
components/BidModal.tsxNumber.isFinite) replacesparseFloat.invalid input surfaces as an inline error with no network call.
3. Error reporting captures user-visible failures without leaking sensitive details
hooks/providers/productionMarketplaceProvider.tsuser-facing messages — internal paths and status details never reach users.
a generic reason, and server-provided reasons are length-bounded.
components/BidModal.tsxerrorReporterwith safecontext fields only (listing id, username, operation) — no request bodies
or wallet material.
lib/errorReporter.tstransaction material:
signature,seed,seedPhrase,mnemonic,walletSecret,sessionCookie,cookie.4. Unblocking fix (required for verification)
lib/api.ts— fixed a pre-existing syntax error (missing closing brace ofdescribeApiErrorplus a broken doc-comment start at line ~76) that brokecompilation of the entire frontend. Minimal fix only; no behavior change.
Tests
src/hooks/providers/__tests__/productionMarketplaceProvider.test.tsfailure reasons asserted not to leak paths/status internals; malformed
response fallback.
src/hooks/__tests__/mockMarketplaceProvider.test.tsVerification
npx vitest run: all marketplace tests pass (161 passing).tsc --noEmitrun: no errors in any touched file.Pre-existing issues intentionally left untouched
These fail on the base branch as well and are outside the scope of this issue:
app/dashboard/page.tsx,app/settings/page.tsx,app/pay/page.tsx,components/Header.tsx(break full-project typecheck).src/components/__tests__/ErrorReportingShell.test.tsx(
useOnlineStatus must be used within OnlineStatusProvider).Files changed