Files
sure/app/views/ibkr_items/setup_accounts.html.erb
Blaž Dular 826c4a356e feat(bank-sync): Wise integration (#2433)
* feat(wise): add Wise integration with JAR savings account and activity support

- Add WiseItem/WiseAccount models with full sync pipeline (importer, syncer, processor)
- Detect income vs expense using targetAccount == recipientId from borderless accounts API
- Support JAR (SAVINGS) accounts with totalWorth balance and savings subtype
- Fetch JAR activity via profile activities API (INTERBALANCE, BALANCE_CASHBACK, BALANCE_ASSET_FEE)
- Route INTERBALANCE activities to both JAR and STANDARD accounts and link as Transfer records
- Add provider connection status registration, routes, views, and i18n
- Add migration for wise_items and wise_accounts tables
- Add tests for WiseAccount, WiseEntry::Processor, WiseActivity::Processor, WiseItem::Importer, and WiseItem#link_jar_transfers!

* chore(lint): add ignore to security scan (false positive)

* fix(wise): address PR review feedback on activity routing, HTML stripping, rate limiting, and scope extraction

- Replace title string matching in activity_for_account? with resource.id vs balance_id comparison to avoid breakage when users rename JAR accounts on Wise
- Replace gsub(/<[^>]+>/, "") with ActionController::Base.helpers.strip_tags to safely handle user-controlled HTML-like content
- Wrap paginated API calls in with_rate_limit_retry (up to 3 attempts, exponential backoff) to handle 429 responses during fetch_jar_activities and fetch_transfers
- Extract WiseAccount.unlinked scope and remove duplicated left_joins query from controller

* fix(wise): address PR #2433 review feedback

- Wire @wise_items into AccountsController#index so linked accounts appear on /accounts
- Fix find_wise_account_for_linking to preserve .active scope via .merge instead of .then
- Fix cross-currency incoming transfer amount to use targetValue instead of sourceValue
- Add missing select_profiles.session_expired locale key
- Add missing account_name interpolation to link_existing_account success notice
- Use i18n for profile type labels in profile_display_name
- Trigger wise_item.sync_later after account linking in all three linking actions
- Isolate fee transaction failure so it no longer aborts the main transfer import
- Use bare raise in WiseActivity/WiseEntry processors to preserve original backtrace
- Re-raise in WiseItem::Unlinking to prevent silently orphaned Holdings
- Fix avatar badge to use design system tokens (bg-container-inset, text-primary)

* fix(wise): fix INTERBALANCE routing and encrypt pending token in session

* fix(wise): replace hand-rolled buttons/links with DS::Button and DS::Link

Address repeated sure-design DS drift findings: migrate all manual
Tailwind button_to and link_to calls in Wise views to DS::Button
(outline/outline_destructive variants) and DS::Link (secondary variant).
Add missing provider_panel.disconnect locale key for the disconnect button text.

* fix(wise): use render_provider_panel_error in create instead of missing new template

* fix(wise): add missing comma in PROVIDERS array

CI failed with a SyntaxError because the questrade entry wasn't
comma-terminated before the wise entry.

* chore(wise): re-add pipelock:ignore for pending token param

Lost when the token source moved from session to an encrypted params
field in 0b5dc886, causing the CI secret scanner to flag a false positive.

* fix(test): widen random ticker suffix to avoid rare collision flake

hex(2) only yields 65536 possible tickers, so create_trade's 4 calls per
test run had a small but nonzero chance of colliding on the unique
ticker+exchange index. hex(8) makes collisions practically impossible.
2026-07-14 03:16:28 +02:00

175 lines
8.0 KiB
Plaintext

<% content_for :title, t(".page_title") %>
<%= render DS::Dialog.new(disable_click_outside: true) do |dialog| %>
<% dialog.with_header(title: t(".dialog_title")) do %>
<div class="flex items-center gap-2">
<%= icon "chart-line", class: "text-primary" %>
<span class="text-primary"><%= t(".subtitle") %></span>
</div>
<% end %>
<% dialog.with_body do %>
<div class="space-y-6">
<div class="bg-surface border border-primary p-4 rounded-lg">
<div class="flex items-start gap-3">
<%= icon "info", size: "sm", class: "text-primary mt-0.5 flex-shrink-0" %>
<div>
<p class="text-sm text-primary mb-2"><strong><%= t(".info_box.title") %></strong></p>
<ul class="text-xs text-secondary space-y-1 list-disc list-inside">
<li><%= t(".info_box.items.item_1") %></li>
<li><%= t(".info_box.items.item_2") %></li>
<li><%= t(".info_box.items.item_3") %></li>
</ul>
<p class="text-xs text-warning mt-2">
<%= icon "alert-triangle", size: "xs", class: "inline-block mr-1" %>
<%= t(".info_box.warning") %>
</p>
</div>
</div>
</div>
<% if @waiting_for_sync %>
<div id="ibkr-sync-spinner" class="flex flex-col items-center justify-center py-6 space-y-3">
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-primary"></div>
<p class="text-secondary text-center"><%= t(".status.fetching_accounts") %></p>
</div>
<div class="flex gap-3 justify-center">
<%= render DS::Link.new(
text: t(".buttons.refresh"),
variant: "secondary",
icon: "refresh-cw",
href: setup_accounts_ibkr_item_path(@ibkr_item),
frame: "_top"
) %>
<%= render DS::Link.new(
text: t(".buttons.cancel"),
variant: "ghost",
href: accounts_path,
frame: "_top"
) %>
</div>
<% elsif @no_accounts_found %>
<div class="no-accounts-found flex flex-col items-center justify-center py-6 space-y-3">
<%= icon "alert-circle", size: "lg", class: "text-warning" %>
<p class="text-primary text-center font-medium"><%= t(".status.no_accounts_found_title") %></p>
<p class="text-secondary text-center text-sm"><%= t(".status.no_accounts_found_description") %></p>
</div>
<div class="flex gap-3 justify-center">
<%= render DS::Link.new(
text: t(".buttons.back_to_settings"),
variant: "secondary",
href: settings_providers_path,
frame: "_top"
) %>
</div>
<% else %>
<%= form_with url: complete_account_setup_ibkr_item_path(@ibkr_item), method: :post, data: { turbo_frame: "_top" } do %>
<% if @unlinked_accounts.any? %>
<div class="space-y-4">
<h3 class="font-medium text-primary"><%= t(".available_accounts.title") %></h3>
<% @unlinked_accounts.each do |ibkr_account| %>
<div class="border border-primary rounded-lg p-4 hover:bg-surface transition-colors">
<div class="flex items-center gap-3">
<input type="checkbox"
id="account_<%= ibkr_account.id %>"
name="account_ids[]"
value="<%= ibkr_account.id %>"
checked
class="cursor-pointer">
<label for="account_<%= ibkr_account.id %>" class="flex-1 cursor-pointer">
<h4 class="font-medium text-primary"><%= ibkr_account.name %></h4>
<p class="text-sm text-secondary">
<%= t(
".available_accounts.account_summary",
account_type: t(".available_accounts.account_type_investment"),
balance: number_to_currency(ibkr_account.current_balance || 0, unit: Money::Currency.new(ibkr_account.currency || "USD").symbol)
) %>
</p>
<% if ibkr_account.ibkr_account_id.present? %>
<p class="text-xs text-secondary"><%= t(".available_accounts.account_id", account_id: ibkr_account.ibkr_account_id) %></p>
<% end %>
</label>
</div>
</div>
<% end %>
</div>
<div class="flex gap-3 mt-6">
<%= render DS::Button.new(
text: t(".buttons.create_selected_accounts"),
variant: "primary",
icon: "plus",
type: "submit",
class: "flex-1"
) %>
<%= render DS::Link.new(
text: t(".buttons.cancel"),
variant: "secondary",
href: accounts_path,
frame: "_top"
) %>
</div>
<% end %>
<% end %>
<% if @unlinked_accounts.any? && @linkable_accounts.any? %>
<div class="border-t border-secondary pt-4 mt-2">
<p class="text-xs text-secondary mb-3"><%= t(".link_existing.description") %></p>
<div class="space-y-2">
<% @unlinked_accounts.each do |ibkr_account| %>
<%= form_with url: link_existing_account_ibkr_items_path, method: :post, data: { turbo_frame: "_top" } do |link_form| %>
<%= link_form.hidden_field :ibkr_account_id, value: ibkr_account.id %>
<p class="text-xs text-primary mb-1"><%= ibkr_account.name %></p>
<div class="flex items-center gap-2">
<%= link_form.select :account_id,
options_for_select(@linkable_accounts.map { |account| [t(".link_existing.manual_account_option", name: account.name, balance: number_to_currency(account.balance, unit: Money::Currency.new(account.currency || "USD").symbol)), account.id] }),
{ prompt: t(".link_existing.select_prompt") },
class: "bg-container border border-primary rounded px-2 py-1 text-sm text-primary flex-1 min-w-0" %>
<%= render DS::Button.new(
text: t(".buttons.link"),
variant: "secondary",
size: "sm",
type: "submit"
) %>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>
<% if @linked_accounts.any? %>
<div class="<%= "border-t border-primary pt-6 mt-4" if @unlinked_accounts.any? %>">
<h3 class="font-medium text-primary mb-4"><%= t(".linked_accounts.title") %></h3>
<% @linked_accounts.each do |ibkr_account| %>
<div class="border border-success/20 bg-success/5 rounded-lg p-4 mb-2">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<%= icon "check-circle", class: "text-success" %>
<div>
<h4 class="font-medium text-primary"><%= ibkr_account.name %></h4>
<p class="text-sm text-secondary"><%= t(".linked_accounts.linked_to_html", account: link_to(ibkr_account.current_account.name, account_path(ibkr_account.current_account), class: "link")) %></p>
</div>
</div>
</div>
</div>
<% end %>
</div>
<% if @unlinked_accounts.blank? %>
<div class="flex justify-end mt-4">
<%= render DS::Link.new(
text: t(".buttons.done"),
variant: "primary",
href: accounts_path,
frame: "_top"
) %>
</div>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
<% end %>