Stop broadcasting provider cards to the whole family

Closed
JA
2mo ago
+199-216

Summary

When a provider connection finishes syncing, its SyncCompleteEvent re-renders the connection's card and broadcasts it on the family Turbo stream. Every signed-in family member subscribes to that stream. The broadcast is rendered in a job with no viewer, and the card lists every account on the connection. So a member who was shared only some of a connection's accounts receives the names and balances of the rest over the WebSocket, and their filtered card is replaced by the full one on screen. This PR removes those card broadcasts. The family sync toast, which already makes each browser re-fetch its own page on an authenticated request, carries the update instead.

Part of jaysbeekay/sure#235 (fork issue). Upstream issue: we-promise/sure#3630.

Upstream PR: we-promise/sure#4046 (same branch, same commit).

Rebased onto upstream main after we-promise/sure#4044 merged (2026-10-10). #4044 was squash-merged as 94e71a8c2, and jjmata asked for the resulting conflict to be resolved, so this branch now carries only its own two commits (131541c01, 1a7a9b770) on top of it. The squash is identical to #4044's head (745b2a06c), and this PR's own diff is unchanged by the rebase. Its base is now mirror/upstream-main, which contains 94e71a8c2.

What changed

  • Provider events: the card broadcast_replace_to is removed from the 21 *_item/sync_complete_event.rb files that had one. Every one of them already ends with family.broadcast_sync_complete, except Kraken and CoinSpot, which now send it in place of the card.
  • On-chain wallet: OnchainWalletItem::SyncCompleteEvent broadcast the settings wallet row (onchain_wallet_items/_onchain_wallet_item), which names every address on the wallet, to the family stream. It now sends the toast instead. An admin on Settings › Providers sees the new state through the toast's re-fetch.
  • SimpleFIN: SimplefinItem::Syncer and SimplefinItem::BalancesOnlyJob rendered the card with ApplicationController.render and broadcast it. They already send family.broadcast_refresh right after, so the card render is dropped.
  • Questrade and Indexa activity jobs: broadcast_updates sends the toast instead of the card.
  • Generator: lib/generators/provider/family/templates/activities_fetch_job.rb.tt follows the same pattern, so a newly generated provider doesn't bring the broadcast back.

Deliberately not changed:

  • What a card lists when it is rendered in a request. That part of we-promise/sure#3630 is in jaysbeekay/sure#353 (upstream we-promise/sure#4048). The two are independent and touch different files. Each closes one route, and we-promise/sure#3630 needs both. This PR carries the closing keyword, so it's best merged after, or together with, jaysbeekay/sure#353 (upstream we-promise/sure#4048).
  • Account::SyncCompleteEvent's per-account row broadcast and the controllers that rebuild #manual-accounts. These are the same pattern for other data, and they're tracked separately.
  • EnableBankingItem::SyncCompleteEvent: we-promise/sure#4044 (merged) removed its settings panel broadcast, and this PR removes its card broadcast. With both, the event sends only the sync toast. #4044's test asserts only the toast, so it holds with or without this PR.

Behaviour change

  • Cards no longer update in place after a sync. They refresh through the sync toast: an idle page morph-refreshes, and a page with an open form shows the refresh button instead.
  • Five more senders of the toast. Kraken, CoinSpot and on-chain wallets didn't send it before and now do, and so do the Questrade and Indexa activity jobs. The toast also schedules RecurringTransaction.identify_patterns_for, which is debounced, so the extra calls are harmless.
  • Trading 212 now gets its toast. On main, its card reads Current.user.accessible_accounts, which raises when the card is rendered from the broadcast (there is no Current.user in a job). Sync#perform_post_sync only logs that error, so Trading 212 never reached family.broadcast_sync_complete. Removing the broadcast fixes it.

Scope

This PR closes the card route on the family stream. Account rows are still broadcast, with name and balance, by Account::SyncCompleteEvent, so a member still receives an unshared account's row until we-promise/sure#4050 lands. we-promise/sure#4048 closes the request side, where the card lists only the accounts the viewer can see. Each of the three closes a different route.

Demo data

No demo data needed.

Screenshots

No visual change. The card on /accounts looks the same; it updates through the existing sync toast instead of an in-place replace.

Migration notes

No migration.

Verification

Tests were written first and run against main (a92dec1e6):

  • ProviderItemSyncCompleteEventsTest runs every provider's event: the fixture-backed ones (binance, coinspot, fio, ibkr, indexa_capital, kraken, lunchflow, mercury, monobank, plaid, redbark, simplefin, snaptrade, trade_republic, trading212, wise), and akahu, coinbase, coinstats, sophtron and up built in the test. It also runs the Questrade and Indexa activity jobs. It asserts no stream targets the card's dom_id, and that sync-toast is sent. On main, all 23 fail (trading212 raises while rendering its card without a viewer).
  • OnchainWalletItem::SyncCompleteEventTest: no stream targets the wallet row, none contains the truncated address, and the toast is sent. It fails on main.
  • PlaidItem, KrakenItem and IbkrItem SyncCompleteEventTest: each fails on main.

With the change: 223 runs across every *_item/sync_complete_event test, test/models/simplefin_item and test/jobs, 0 failures.

Commands:

  • bin/rails test on 1a7a9b770 (rebased onto upstream main 94e71a8c2): 11,072 runs, 47,021 assertions, 0 failures, 0 errors, 34 skips. Earlier, stacked on we-promise/sure#4044 at 778362d87: 10,871 runs, 0 failures.
  • bin/rubocop on the changed Ruby files: no offenses.
  • bin/brakeman --no-pager: 0 warnings.
  • No ERB or JavaScript changed.

Blast radius

  • *::SyncCompleteEvent#broadcast is only reached through Syncable#broadcast_sync_complete, from Sync#perform_post_sync.
  • The toast it now relies on is Family::SyncCompleteEvent, which renders shared/notifications/sync_toast and accounts/sync_controls. Neither contains account data. The recurring-pattern job it schedules is already debounced, so an extra toast is harmless.
  • Linked accounts still get account.broadcast_sync_complete from the item events, unchanged.
  • Siblings: git grep broadcast_replace_to over app/models, app/jobs and lib/generators leaves:
    • Family::SyncCompleteEvent: no account data.
    • GenerateInsightsJob's badge: a count only.
    • Account::SyncCompleteEvent: tracked separately.
    • EnableBankingItem::SyncCompleteEvent's panel: removed by we-promise/sure#4044 (merged).