Skip to content

fix(agent-world): re-enable Buy after a purchase in Tiny Place trading#4217

Merged
M3gA-Mind merged 6 commits into
tinyhumansai:mainfrom
M3gA-Mind:fix/tinyplace-buy-button-trading-4196
Jun 30, 2026
Merged

fix(agent-world): re-enable Buy after a purchase in Tiny Place trading#4217
M3gA-Mind merged 6 commits into
tinyhumansai:mainfrom
M3gA-Mind:fix/tinyplace-buy-button-trading-4196

Conversation

@M3gA-Mind

@M3gA-Mind M3gA-Mind commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Root cause

In the Tiny Place Trading tab, the Buy button is gated on disabled={buying !== null} (app/src/agentworld/pages/IdentitiesSection.tsx). buying is only reset by closeBuy(), which is reachable only from the confirm dialog's Cancel — but that dialog unmounts the moment the flow reaches a terminal success/error phase (it renders only for confirm/paying). So after the very first Buy attempt, buying is 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

  • Gate the Buy button on a new buyInFlight flag that is true only during the active probe/confirm/pay phases, so the buttons re-enable once a terminal banner shows.
  • Add a Dismiss button to the success and error banners that calls closeBuy() to clear the flow.
  • Regression test: after a completed purchase the Buy button is enabled, and Dismiss clears the banner.

No money-path/RPC logic changed — this is purely the stuck terminal-state UI.

Closes #4196

Summary by CodeRabbit

  • Bug Fixes
    • Buy buttons now re-enable after both successful and failed purchase attempts, so you can immediately try again.
    • Purchase success and error banners now include a dismiss option, clearing the message while keeping the Buy action available.
  • Tests
    • Added regression tests covering successful purchases, failed purchases, banner dismissal behavior, and the “payment sent but purchase did not complete” scenario.

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
@M3gA-Mind M3gA-Mind requested a review from a team June 26, 2026 16:11
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 89846507-8ca5-47bb-bc2d-790416d64128

📥 Commits

Reviewing files that changed from the base of the PR and between b72e842 and b929731.

📒 Files selected for processing (1)
  • app/src/agentworld/pages/IdentitiesSection.test.tsx

📝 Walkthrough

Walkthrough

TradingTab 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.

Changes

Trading tab x402 buy flow

Layer / File(s) Summary
Buy state gating
app/src/agentworld/pages/IdentitiesSection.tsx
TradingTab tracks an in-flight buy flag so Buy buttons disable only during the active x402 request, and the Buy button uses that flag.
Dismissable outcome banners
app/src/agentworld/pages/IdentitiesSection.tsx
The buy success and buy error banners now render a header row with a Dismiss button that calls closeBuy, replacing the previous terminal message-only layout.
x402 buy regressions
app/src/agentworld/pages/IdentitiesSection.test.tsx
New tests cover successful, failed, and post-payment-failure purchases, including Buy re-enabling and banner clearing after dismiss.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop, hop, the Buy button learned to stay,
Dismiss clears the banners and shows the way.
Success, fail, or payment sent astray,
This trading tab now bounces back to play.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR only re-enables the Buy button after terminal states and does not address the purchase-flow failure described in #4196. Investigate and fix the actual buy flow: confirm the RPC is invoked, payment/balance checks pass, and the modal submission completes the purchase.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: re-enabling Buy after Tiny Place trading purchases.
Out of Scope Changes check ✅ Passed Changes stay focused on Tiny Place trading UI behavior and regression tests.

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 26, 2026
@M3gA-Mind M3gA-Mind merged commit 4255fa2 into tinyhumansai:main Jun 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Buy button not working in Tiny Place identity trading

2 participants