Support multiple Trade Republic connections per family

Merged
GF
2mo ago
+1093-234

Problem

The Trade Republic settings panel only ever shows one connection: _trade_republic_panel.html.erb defaults to Current.family.trade_republic_items.first_or_initialize, and every turbo_stream response from TradeRepublicItemsController re-renders the panel scoped to a single trade_republic_item local. This is purely a view/controller limitation — the model has no unique constraint on family_id, set_trade_republic_item is already params[:id]-scoped, and the Stimulus controllers (trade-republic-qr, trade-republic-login) are self-scoped and already safe with multiple instances on the page.

Users who hold accounts at Trade Republic under two different phone numbers (e.g. a personal and a joint/family account) have no way to connect both.

Resulting behavior

Introduces TradeRepublic::AccountEditorComponent, following the existing Trading212::AccountEditorComponent pattern:

  • Every connection renders as its own DS::Disclosure card with independent connect/sync/disconnect actions, QR login, push/authenticator login flow, and a credentials-update form.
  • A separate "add another connection" form (phone/PIN + QR login option) always renders below the list.
  • Controller turbo_stream responses (create, update, cancel_qr_login, render_login_panel, render_panel_error) now reload the whole panel from the DB instead of passing a single item local, matching how Trading212's controller already works.

While building this, found that Settings::ProvidersController#prepare_show_context loaded @trade_republic_items with .select(:id) — harmless for the old single-item panel (which never used that ivar), but breaks once the panel actually reads other columns from the collection. Fixed to load full records, matching Trading212's equivalent line.

No migration needed (model was already multi-item-safe), no JS changes needed (Stimulus controllers already self-scoped).

Validation

  • New tests: test/components/trade_republic/account_editor_component_test.rb (renders per item + empty-state add form), a new controller test asserting a second connection can be created without disturbing the first, and a new panel-render test asserting two connections render as independent cards with independent action URLs.
  • Updated test/controllers/trade_republic_panel_render_test.rb to target specific fixtures instead of any_instance stubs, since the panel now renders every fixture item for a family rather than just the first.
  • bin/rails test (models/controllers/components covering Trade Republic and Trading212 for parity comparison): green, no regressions versus an unmodified main checkout (verified via git stash comparison — the only pre-existing failures on this branch and on main are 19 unrelated redis-configuration-error redirects from this sandbox's local test environment not running Redis).
  • bin/rubocop, bundle exec erb_lint -u root, bin/brakeman: clean on the changed files. No JS files changed, so no biome run was needed.

Summary by CodeRabbit

  • New Features
    • Manage multiple Trade Republic connections in settings, with individual sync and disconnect controls.
    • Add connections using QR login, authenticator codes, or push approval, and view login and sync statuses.
    • Start an additional connection without changing existing connections.
    • Update connection settings when no login is in progress, and access disconnect controls when a login has failed or been abandoned.
    • See connection identifiers in disconnect confirmations.
  • Bug Fixes
    • Duplicate connections to an already-linked Trade Republic account are discarded with an alert.