fix(agent-world): re-enable Buy after a purchase in Tiny Place trading#4217
Conversation
Clicking Buy on a fixed-price identity listing worked once, then every Buy
button stayed permanently disabled. The Buy button is gated on
`disabled={buying !== null}`, but `buying` was only reset by `closeBuy`, which
is reachable solely from the confirm dialog — and that dialog unmounts as soon
as the flow reaches a terminal `success`/`error` phase. So after the first
attempt `buying` never cleared, the terminal banners had no dismiss control,
and the trade UI was stuck.
Gate the button on a `buyInFlight` flag (active probe/confirm/pay phases only)
so it re-enables at the terminal banner, and add a Dismiss button to the
success/error banners that calls `closeBuy` to clear state. Adds a regression
test asserting Buy is enabled after a completed purchase and Dismiss clears the
banner.
Closes tinyhumansai#4196
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughTradingTab now keeps Buy enabled after terminal x402 outcomes, and both success and error banners add a Dismiss action that clears the banner. Regression tests cover successful, failed, and post-payment-failure purchases. ChangesTrading tab x402 buy flow
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d28744189b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| size="xs" | ||
| className="flex-1" | ||
| disabled={buying !== null} | ||
| disabled={buyInFlight} |
There was a problem hiding this comment.
Keep purchased listings from becoming buyable again
After a successful buy, useMarketplaceIdentities() still holds the same listings array because this flow does not refetch or remove buying.listingId, but this changed disabled condition makes the just-purchased card's Buy button active again as soon as bs.phase === 'success'. In the single-listing case covered by the new test, clicking Buy again sends another marketplace.buyIdentity('list-1', { confirmed: false }) for an already-sold listing; re-enable trading by refetching/filtering the purchased listing or keeping that specific card disabled until the list updates.
Useful? React with 👍 / 👎.
Covers the failed-purchase branch (error banner + its Dismiss reset) so the diff-coverage gate sees the new terminal-state UI lines exercised.
Root cause
In the Tiny Place Trading tab, the Buy button is gated on
disabled={buying !== null}(app/src/agentworld/pages/IdentitiesSection.tsx).buyingis only reset bycloseBuy(), which is reachable only from the confirm dialog's Cancel — but that dialog unmounts the moment the flow reaches a terminalsuccess/errorphase (it renders only forconfirm/paying). So after the very first Buy attempt,buyingis never cleared, the terminal banners have no dismiss control, and every Buy button stays permanently disabled — the trade UI is stuck with no way to act again.Fix
buyInFlightflag that is true only during the active probe/confirm/pay phases, so the buttons re-enable once a terminal banner shows.closeBuy()to clear the flow.No money-path/RPC logic changed — this is purely the stuck terminal-state UI.
Closes #4196
Summary by CodeRabbit