← Back to Pull requests

feat(trade-republic): add connections from the panel and create them only once approved #4265

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 16, 2026 11:07 UTC
Author

Builds on #4232, which is merged; main is merged in, so the diff now shows only this PR's changes.

Problem

  • With a connection in place, the Trade Republic panel showed two phone number and PIN forms, one for the connection and one for adding another, plus a "Log in" button that could not log in because the PIN is never stored.

  • Adding a connection created a TradeRepublicItem before Trade Republic approved the login. A cancelled or abandoned QR login left a connection behind, and "Add another connection" appeared before the first one existed.

  • "Add another connection" opened a drawer, and starting a QR login there closed it again.

  • A connection could show its QR code and its PIN login form at the same time.

  • The setup steps described only the PIN login, in the wrong order, and nine locales had no translated panel.
  • Behavior after this PR

  • Each connection is a row, laid out like Enable Banking: Sync (only while logged in), QR login, PIN login and Remove. The PIN login opens inline below the row, like the QR code. While one login runs, the other's button is hidden; the PIN login comes back only once a QR cancel is done, so the cancel cannot clear a PIN login started meanwhile.

  • Add a connection ends the panel with two buttons. QR login starts the login and shows its QR code in a new row; PIN login opens a row with the phone number and PIN form. Both take the place of Add a connection until they finish or are cancelled. No drawer opens.

  • A connection exists only once its login succeeds. The login runs on a new TradeRepublicPendingConnection, which holds the pending login state and device ID and becomes a TradeRepublicItem when Trade Republic approves it. Cancelling removes it. A lapsed QR login counts as expired, so it no longer blocks adding a connection. The QR, push and authenticator steps move into TradeRepublicLoginFlow, shared with an existing connection that logs in again.

  • One new connection at a time per family, enforced by a unique index and a FOR NO KEY UPDATE lock on the family. That lock does not conflict with the KEY SHARE lock an approval takes for the family foreign key, so a start and an approval cannot deadlock.

  • A failed login stays open until it is dealt with. A failed QR poll or cancel keeps the QR login as the running one, showing the error with Cancel QR login, because it may still be pending on the server; the PIN login returns once the cancel succeeds. A wrong PIN keeps the PIN form open, for an existing connection as for a new one.

  • Polls that lost their login are superseded. A poll for a new connection that was cancelled, replaced or approved meanwhile gets the superseded response instead of a 404.

  • A page acts only on the login it shows. Each page sends a token of its login (a digest of the QR challenge or login process ID, which stay the same across one login's steps). A poll, authenticator code or QR cancel from a tab still showing an earlier login leaves the login another tab started meanwhile alone. A page loaded before the deploy sends no token and keeps the previous behavior.

  • The unused initiate_login action goes. Nothing posts to TradeRepublicItemsController#initiate_login since the rows have no Log in button, and it could not log in anyway because the PIN is never stored. Its route, its tests and translations nothing uses are removed.

  • The setup steps name both buttons and follow the real PIN order: phone number and PIN or password, then the authenticator code, then approval in the app.

  • Translations are complete for every locale that translates the providers page. pt-BR and ro have no providers.meta section yet, so their login_required and login_expires_soon fall back to English, as their other providers.meta keys already do. Trade Republic product names (Brokerage, Private Markets, Crypto Wallet, Saveback, Round up) stay untranslated, as in the Trade Republic app; Dutch uses the app's own "Vaste Rente".

  • DS::Card gets an inset variant and a tag option, used for the QR code and both PIN forms instead of the same panel built by hand three times. No new styles.

  • Each row shows the Trade Republic logo, as the provider guide asks. A long status text wraps beside the row's buttons instead of pushing them onto their own line.
  • Screenshots

    | Before | After |
    |---|---|
    | Connections in Settings: each with its own phone number and PIN form, plus a form to add another | Connections as rows; Add a connection with QR login and PIN login |
    | <img width="767" height="1293" alt="image" src="https://github.com/user-attachments/assets/166810f4-a11f-402f-aa8c-8573f1eca833" /> | <img width="767" height="425" alt="image" src="https://github.com/user-attachments/assets/119bb898-6778-4e93-8231-0c57dbe72579" />|
    | QR login on a connection, above its PIN form | QR login on a connection; its PIN login is hidden meanwhile |
    | <img width="767" height="1603" alt="image" src="https://github.com/user-attachments/assets/eb994205-194b-4751-9deb-88679150c9f0" /> | <img width="767" height="731" alt="image" src="https://github.com/user-attachments/assets/3de50d4a-2253-45ab-9414-ad1d414292fb" /> |
    | (the PIN form was always shown, see above) | PIN login opened inline below the row |
    | See above | <img width="767" height="619" alt="image" src="https://github.com/user-attachments/assets/0e69f32d-1e4f-40b2-b568-28e43164e146" /> |

    Migration notes

  • 20261015170000_create_trade_republic_pending_connections creates trade_republic_pending_connections (family_id with a unique index and foreign key, phone_number, pending_login_state, currency, device_id with default gen_random_uuid()). It is a new, empty table; existing connections are not touched.

  • A new connection whose login was started before the deploy (still a TradeRepublicItem waiting for approval) keeps working as an existing connection and can log in again from its row.
  • Validation

  • New and updated component, controller and system tests cover the rows, Add a connection, the pending connection lifecycle (create, approve, cancel, lapse), one login at a time per connection, the held and the failed QR cancel, a failed QR poll, a failed PIN login on an existing connection, polls whose pending connection was removed, polls and cancels from a tab whose login was replaced, the lock type and the redacted debug log, plus QR cancels after a start that failed, was superseded or returned an unreadable response, and that non-admin members cannot start or cancel a new connection.

  • bin/rails test on a5b6f98f4: 12,295 runs, 3 failures and 3 errors, in Settings::HostingsControllerTest, Eval::Langfuse::ExperimentRunnerTest and SimplefinEntry::ProcessorTest. These fail the same way on main in my environment and are unrelated to Trade Republic.

  • System tests test/system/trade_republic_new_connection_test.rb, test/system/trade_republic_qr_login_test.rb, test/system/settings/providers_test.rb, test/system/settings_test.rb, test/system/onchain_wallets_test.rb and test/system/replace_url_back_test.rb: 49 runs, all pass.

  • bin/rubocop, bundle exec erb_lint --lint-all, npm run lint and bin/brakeman pass.
  • Council review

    Rounds: 6

    | Delegate | Round 1 | Round 2 | Round 3 | Round 4 | Round 5 | Round 6 |
    | --- | --- | --- | --- | --- | --- | --- |
    | Claude Opus 5.5 | 8.5/10 | 9/10 | 9/10 | 9.5/10 | 9.5/10 | 9.5/10 |
    | GPT-6.1 Sol | 9/10 | 9/10 | 8.5/10 | 8.5/10 | 9.5/10 | 9.5/10 |
    | Grok 4.7 | 7/10 | 8/10 | – | – | – | – |
    | Claude Sonnet 5.5 | – | – | 9/10 | 9.5/10 | 9.5/10 | 9.5/10 |

    Sonnet 5.5 replaced Grok from round 3. Resulting changes: a non-admin authorization test, one shared lapsed? rule, and QR cancels that are no longer sent without a login token after a failed, superseded or unreadable start. Round 6 covered the encryption backfill entry, the untranslated product names, removing pending logins in a financial data reset, and the locale merges with main; no findings.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Set up Trade Republic connections using QR or phone-and-PIN login, with authenticator-code entry and approval prompts.
    Connection cards show login, sync, and session-expiry status, with controls to manage multiple connections.
    Sessions nearing expiry can trigger a sync before they expire.
    Added translated connection and login guidance across supported languages.
    Provider status warns when login is required or a session is nearing expiry.
    Bug Fixes
    Expired sessions are identified as requiring login and excluded from syncing.
    * QR login errors remain cancellable, and blank phone-number submissions no longer overwrite a saved number.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: nielseulink Review duration: 65227m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4265"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.6% · Safe to merge
    32.6%