fix(transactions): stop Cancel in Convert to trade from converting

Merged
LY
2mo ago
+42-2

Problem

In the Convert to trade dialog, clicking Cancel on a filled-in form converts the transaction into a trade. With the required ticker empty, Cancel shows the browser's "fill in this field" prompt and the dialog stays open.

Cancel was a DS::Button with href: "#", which renders a button_to, a form of its own, inside the conversion form. The HTML parser ignores the nested <form> tag and assigns Cancel's submit button to the conversion form, so clicking it submits the conversion. Its close action could not run either: it was spelled click->ds--dialog#close, but Stimulus identifiers are case-sensitive and the controller is DS--dialog.

Fix

Cancel is now a plain type: "button" DS::Button calling DS--dialog#close, the same pattern as the Cancel in goals/consume.html.erb. No visual change: it keeps the outline variant.

Validation

  • New system test: opens the dialog from the transaction drawer, fills in a ticker and quantity, clicks Cancel, and asserts that the dialog closes, no trade is created and the entry is still a transaction.
  • Without the view change the test fails on the trade count (Cancel created a trade); with it, it passes.
  • bin/rails test: 10452 runs, 1 error in RecurringTransaction::PipelineTest, which fails identically on main in the devcontainer (it reads config[:username], while database.yml uses user:). bin/rails test:system, rubocop, erb_lint, Biome and Brakeman are clean.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Canceling a filled-in convert-to-trade dialog now closes the dialog without creating a trade or changing the transaction.
    • The cancel control now works as a direct button, avoiding unintended navigation when closing the dialog.