mirror of
https://github.com/we-promise/sure.git
synced 2026-09-08 16:14:23 +00:00
* Add Trade Republic provider integration
Introduce authenticated web and QR login, resilient account synchronization, deterministic financial imports, account discovery, and provider diagnostics. Keep login state encrypted, PINs transient, and incomplete provider responses non-destructive.
* Address Trade Republic review findings
Keep QR-authenticated sessions syncable, preserve historical holding snapshots, correct dividend direction, handle unpriced positions safely, localize repair feedback, and align provider controls with the design system.
* Add Trade Republic translations for supported locales
* Restore German Trade Republic account labels
* Resolve remaining Trade Republic review findings
* Resolve remaining Trade Republic review findings
* Address latest Trade Republic review feedback
* Refactor Trade Republic panel buttons to use DS::Button component and add integration tests
* Fix 100x money inflation and missing positions locale key in TR views
Money.new takes major units, so multiplying by 100 displayed EUR 12.34
as EUR 1234 in the holdings category cards and expense summary. Also
add the pluralized holdings.index.positions key that t(".positions")
resolves to (previously only defined at the unused holdings.positions
root level), across all 18 locales.
* fix(db): repair merge artifacts in schema and migrations
- Remove duplicated icon/progress_basis columns on goals in schema.rb
- Renumber Trade Republic migrations to unique versions (clashed with
main's 20260824120000_add_lifecycle_to_goals)
- Bump schema version to match latest migration
* Address remaining Trade Republic review feedback
* fix(trade-republic): address open PR #3168 review findings\n\n- Reject authenticated sessions without a securities account number so a\n blank account does not mark the item connected on a broken session.\n- Derive a missing trade amount from |quantity| x price, and a missing\n price from the resolved amount, without changing the signed import amount.\n- Regenerate db/schema.rb so the Trade Republic item/account tables and\n indexes are present; a fresh test database was otherwise missing the\n tables even though the migrations were marked up.\n
* fix(trade-republic): localize activity labels in ActivitiesProcessor (i18n)
* fix(trade-republic): localize activity labels in ActivitiesProcessor (i18n)
* fix(trade-republic): add activity labels i18n keys to all locale files
* Fix Trade Republic PR review follow-ups
* fix(trade-republic): i18n-aware category guard and ignore generated graphify cache
- Category matcher skipped core deposit/withdrawal labels; guard now compares
against translated values so German etc skip correctly
- Remove committed graphify-out cache and ignore dir
* Protect holdings from malformed snapshots
* Consolidate Trade Republic migrations
* Address final Trade Republic review comments
* Address final Trade Republic review comments
- Remove hard-coded category matcher (merchant keyword taxonomy) and leave Trade Republic transactions uncategorized when no structured category exists; rely on Sure rules/AI
- Revert shared ProviderImportAdapter# import_trade extra: param; handle Trade Republic trade metadata locally in ActivitiesProcessor via post-import Trade extra merge (preserve existing extra, deep_merge)
- Preserve Trade Republic product distinctions (cash, brokerage/private_markets/interest_products/crypto_wallet via portfolio categories) without collapsing account kinds
---------
Co-authored-by: Aland Baban <snow@iBananaMac.fritz.box>
273 lines
11 KiB
Ruby
273 lines
11 KiB
Ruby
module SettingsHelper
|
|
SETTINGS_ORDER = [
|
|
# General section
|
|
{ name: -> { t("settings.settings_nav.accounts_label") }, path: :accounts_path },
|
|
{ name: -> { t("settings.settings_nav.bank_sync_label") }, path: :settings_providers_path, condition: :admin_user? },
|
|
{ name: -> { t("settings.settings_nav.preferences_label") }, path: :settings_preferences_path },
|
|
{ name: -> { t("settings.settings_nav.appearance_label") }, path: :settings_appearance_path },
|
|
{ name: -> { t("settings.settings_nav.profile_label") }, path: :settings_profile_path },
|
|
{ name: -> { t("settings.settings_nav.security_label") }, path: :settings_security_path },
|
|
{ name: -> { t("settings.settings_nav.payment_label") }, path: :settings_payment_path, condition: :not_self_hosted? },
|
|
# Transactions section
|
|
{ name: -> { t("settings.settings_nav.categories_label") }, path: :categories_path },
|
|
{ name: -> { t("settings.settings_nav.tags_label") }, path: :tags_path },
|
|
{ name: -> { t("settings.settings_nav.rules_label") }, path: :rules_path },
|
|
{ name: -> { t("settings.settings_nav.merchants_label") }, path: :family_merchants_path },
|
|
{ name: -> { t("settings.settings_nav.recurring_transactions_label") }, path: :recurring_transactions_path },
|
|
{ name: -> { t("settings.settings_nav.statement_vault_label") }, path: :account_statements_path, condition: :admin_user? },
|
|
# Advanced section
|
|
{ name: -> { t("settings.settings_nav.ai_prompts_label") }, path: :settings_ai_prompts_path, condition: :admin_user? },
|
|
{ name: -> { t("settings.settings_nav.llm_usage_label") }, path: :settings_llm_usage_path, condition: :admin_user? },
|
|
{ name: -> { t("settings.settings_nav.api_key_label") }, path: :settings_api_keys_path, condition: :admin_user? },
|
|
{ name: -> { t("settings.settings_nav.self_hosting_label") }, path: :settings_hosting_path, condition: :self_hosted_and_admin? },
|
|
{ name: -> { t("settings.settings_nav.imports_label") }, path: :imports_path, condition: :admin_user? },
|
|
{ name: -> { t("settings.settings_nav.exports_label") }, path: :family_exports_path, condition: :admin_user? },
|
|
# More section
|
|
{ name: -> { t("settings.settings_nav.guides_label") }, path: :settings_guides_path },
|
|
{ name: -> { t("settings.settings_nav.whats_new_label") }, path: :changelog_path },
|
|
{ name: -> { t("settings.settings_nav.feedback_label") }, path: :feedback_path }
|
|
]
|
|
|
|
def adjacent_setting(current_path, offset)
|
|
visible_settings = SETTINGS_ORDER.select { |setting| setting[:condition].nil? || send(setting[:condition]) }
|
|
current_index = visible_settings.index { |setting| send(setting[:path]) == current_path }
|
|
return nil unless current_index
|
|
|
|
adjacent_index = current_index + offset
|
|
return nil if adjacent_index < 0 || adjacent_index >= visible_settings.size
|
|
|
|
adjacent = visible_settings[adjacent_index]
|
|
|
|
render partial: "settings/settings_nav_link_large", locals: {
|
|
path: send(adjacent[:path]),
|
|
direction: offset > 0 ? "next" : "previous",
|
|
title: setting_name(adjacent)
|
|
}
|
|
end
|
|
|
|
def settings_section(title: nil, subtitle: nil, collapsible: false, open: true, auto_open_param: nil, status: nil, meta: nil, actions: nil, badge: nil, &block)
|
|
content = capture(&block)
|
|
render partial: "settings/section", locals: { title: title, subtitle: subtitle, content: content, collapsible: collapsible, open: open, auto_open_param: auto_open_param, status: status, meta: meta, actions: actions, badge: badge }
|
|
end
|
|
|
|
def provider_summary(provider_key)
|
|
key = provider_key.to_s.downcase
|
|
|
|
case key
|
|
when "plaid", "plaid_eu"
|
|
configured = @provider_configurations&.find { |c| c.provider_key.to_s.casecmp(key).zero? }&.configured?
|
|
configured ? { status: :ok } : { status: :off }
|
|
when "akahu"
|
|
return { status: :off } unless @akahu_items&.any?
|
|
sync_based_summary(key)
|
|
when "up"
|
|
return { status: :off } unless @up_items&.any?
|
|
sync_based_summary(key)
|
|
when "simplefin"
|
|
return { status: :off } unless @simplefin_items&.any?
|
|
sync_based_summary(key)
|
|
when "lunchflow"
|
|
return { status: :off } unless @lunchflow_items&.any?
|
|
sync_based_summary(key)
|
|
when "enable_banking"
|
|
return { status: :off } unless @enable_banking_items&.any?
|
|
enable_banking_summary
|
|
when "coinstats"
|
|
return { status: :off } unless @coinstats_items&.any?
|
|
sync_based_summary(key)
|
|
when "mercury"
|
|
return { status: :off } unless @mercury_items&.any?
|
|
sync_based_summary(key)
|
|
when "redbark"
|
|
return { status: :off } unless @redbark_items&.any?
|
|
sync_based_summary(key)
|
|
when "brex"
|
|
return { status: :off } unless @brex_items&.any?
|
|
sync_based_summary(key)
|
|
when "coinbase"
|
|
return { status: :off } unless @coinbase_items&.any?
|
|
sync_based_summary(key)
|
|
when "binance"
|
|
return { status: :off } unless @binance_items&.any?
|
|
sync_based_summary(key)
|
|
when "kraken"
|
|
return { status: :off } unless @kraken_items&.any?
|
|
sync_based_summary(key)
|
|
when "onchain_wallet"
|
|
return { status: :off } unless @onchain_wallet_items&.any?
|
|
sync_based_summary(key)
|
|
when "snaptrade"
|
|
configured_item = @snaptrade_items&.find(&:oauth_configured?)
|
|
return { status: :off } unless configured_item
|
|
|
|
sync_based_summary(key)
|
|
when "ibkr"
|
|
return { status: :off } unless @ibkr_items&.any?
|
|
sync_based_summary(key)
|
|
when "trade_republic"
|
|
return { status: :off } unless @trade_republic_items&.any?
|
|
sync_based_summary(key)
|
|
when "indexa_capital"
|
|
return { status: :off } unless @indexa_capital_items&.any?
|
|
sync_based_summary(key)
|
|
when "sophtron"
|
|
return { status: :off } unless @sophtron_items&.any?
|
|
sync_based_summary(key)
|
|
when "questrade"
|
|
return { status: :off } unless @questrade_items&.any?
|
|
sync_based_summary(key)
|
|
else
|
|
{ status: :off }
|
|
end
|
|
end
|
|
|
|
def settings_nav_footer
|
|
previous_setting = adjacent_setting(request.path, -1)
|
|
next_setting = adjacent_setting(request.path, 1)
|
|
|
|
content_tag :div, class: "hidden md:flex flex-row justify-between gap-4" do
|
|
concat(previous_setting)
|
|
concat(next_setting)
|
|
end
|
|
end
|
|
|
|
def settings_nav_footer_mobile
|
|
previous_setting = adjacent_setting(request.path, -1)
|
|
next_setting = adjacent_setting(request.path, 1)
|
|
|
|
content_tag :div, class: "md:hidden flex flex-col gap-4 pb-[env(safe-area-inset-bottom)]" do
|
|
concat(previous_setting)
|
|
concat(next_setting)
|
|
end
|
|
end
|
|
|
|
def yahoo_finance_health_presentation(status)
|
|
status = status.to_sym if status.respond_to?(:to_sym)
|
|
status = :unknown unless %i[healthy rate_limited unavailable unknown].include?(status)
|
|
|
|
presentation = {
|
|
status_class: {
|
|
healthy: "bg-success",
|
|
rate_limited: "bg-warning",
|
|
unavailable: "bg-destructive",
|
|
unknown: "bg-surface-inset"
|
|
}.fetch(status),
|
|
status_text: t("settings.hostings.yahoo_finance_settings.status_#{status}")
|
|
}
|
|
|
|
presentation[:alert] = case status
|
|
when :rate_limited
|
|
{
|
|
title: t("settings.hostings.yahoo_finance_settings.rate_limited_title"),
|
|
message: t("settings.hostings.yahoo_finance_settings.rate_limited_message"),
|
|
variant: :warning
|
|
}
|
|
when :unavailable
|
|
{
|
|
title: t("settings.hostings.yahoo_finance_settings.unavailable_title"),
|
|
message: t("settings.hostings.yahoo_finance_settings.unavailable_message"),
|
|
variant: :warning
|
|
}
|
|
end
|
|
|
|
presentation
|
|
end
|
|
|
|
# Below this many synced accounts, the per-row pills already give the user
|
|
# enough at-a-glance signal and the strip is redundant chrome.
|
|
HEALTH_STRIP_MIN_ACCOUNTS = 10
|
|
|
|
# Slim health-strip data for the providers index. Pulls counts from the
|
|
# already-resolved entry summaries plus the family's distinct synced-account
|
|
# count for the trailing stat. Returns a hash consumed by the
|
|
# `settings/providers/_health_strip` partial, or nil when the family has
|
|
# fewer than HEALTH_STRIP_MIN_ACCOUNTS connected accounts.
|
|
def provider_health_strip(connected:, needs_attention:)
|
|
accounts_count = Current.family.accounts.joins(:account_providers).distinct.count
|
|
return nil if accounts_count < HEALTH_STRIP_MIN_ACCOUNTS
|
|
|
|
active_entries = connected + needs_attention
|
|
last_synced_at = active_entries.map { |e| e[:summary][:last_synced_at] }.compact.max
|
|
|
|
{
|
|
connected: active_entries.size,
|
|
needs_attention: needs_attention.size,
|
|
accounts_syncing: accounts_count,
|
|
last_synced_at: last_synced_at
|
|
}
|
|
end
|
|
|
|
# Strips the leading "about " from `time_ago_in_words` so copy reads as
|
|
# "Synced 6 hours ago" instead of "Synced about 6 hours ago".
|
|
def concise_time_ago(time)
|
|
time_ago_in_words(time).sub(/\Aabout /, "")
|
|
end
|
|
|
|
private
|
|
def sync_based_summary(provider_key)
|
|
health = @provider_sync_health&.dig(provider_key) || {}
|
|
last_synced_at = health[:last_synced_at]
|
|
|
|
base = if health[:error]
|
|
{ status: :err, meta: t("settings.providers.meta.sync_error") }
|
|
elsif health[:stale]
|
|
{ status: :warn, meta: t("settings.providers.meta.no_recent_sync") }
|
|
elsif last_synced_at.present?
|
|
{ status: :ok, meta: t("settings.providers.meta.last_synced", time: concise_time_ago(last_synced_at)) }
|
|
else
|
|
{ status: :ok }
|
|
end
|
|
|
|
base.merge(last_synced_at: last_synced_at)
|
|
end
|
|
|
|
def enable_banking_summary
|
|
health = @provider_sync_health&.dig("enable_banking") || {}
|
|
last_synced_at = health[:last_synced_at]
|
|
|
|
return { status: :err, meta: t("settings.providers.meta.sync_error"), last_synced_at: nil } if health[:error]
|
|
|
|
valid_items = @enable_banking_items&.select(&:session_valid?) || []
|
|
|
|
# All items have expired/missing sessions — need re-authorization
|
|
if valid_items.empty?
|
|
return { status: :warn, meta: t("settings.providers.meta.reconsent_required"), last_synced_at: last_synced_at }
|
|
end
|
|
|
|
expiring = valid_items.find do |item|
|
|
item.session_expires_at.present? && item.session_expires_at < 7.days.from_now
|
|
end
|
|
|
|
if expiring
|
|
days = [ ((expiring.session_expires_at - Time.current) / 1.day).ceil, 1 ].max
|
|
return { status: :warn, meta: t("settings.providers.meta.reconsent_needed", count: days), last_synced_at: last_synced_at }
|
|
end
|
|
|
|
return { status: :warn, meta: t("settings.providers.meta.no_recent_sync"), last_synced_at: last_synced_at } if health[:stale]
|
|
|
|
if last_synced_at.present?
|
|
{ status: :ok, meta: t("settings.providers.meta.last_synced", time: concise_time_ago(last_synced_at)), last_synced_at: last_synced_at }
|
|
else
|
|
{ status: :ok, last_synced_at: nil }
|
|
end
|
|
end
|
|
|
|
def not_self_hosted?
|
|
!self_hosted?
|
|
end
|
|
|
|
def setting_name(setting)
|
|
name = setting[:name]
|
|
name.respond_to?(:call) ? instance_exec(&name) : name
|
|
end
|
|
|
|
# Helper used by SETTINGS_ORDER conditions
|
|
def admin_user?
|
|
Current.user&.admin?
|
|
end
|
|
|
|
def self_hosted_and_admin?
|
|
self_hosted? && admin_user?
|
|
end
|
|
end
|