Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Account < ApplicationRecord

accepts_nested_attributes_for :accountable, update_only: true

def institution_domain
return nil unless plaid_account&.plaid_item&.institution_url.present?
URI.parse(plaid_account.plaid_item.institution_url).host.gsub(/^www\./, "")
end

class << self
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
Expand Down
14 changes: 14 additions & 0 deletions app/models/plaid_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ def fetch_and_load_plaid_data
item = plaid_provider.get_item(access_token).item
update!(available_products: item.available_products, billed_products: item.billed_products)

# Fetch and store institution details
if item.institution_id.present?
begin
institution = plaid_provider.get_institution(item.institution_id)
update!(
institution_id: item.institution_id,
institution_url: institution.institution.url,
institution_color: institution.institution.primary_color
)
rescue Plaid::ApiError => e
Rails.logger.warn("Error fetching institution details for item #{id}: #{e.message}")
end
end

fetched_accounts = plaid_provider.get_item_accounts(self).accounts
data[:accounts] = fetched_accounts || []

Expand Down
11 changes: 11 additions & 0 deletions app/models/provider/plaid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def get_item_liabilities(item)
response.liabilities
end

def get_institution(institution_id)
request = Plaid::InstitutionsGetByIdRequest.new({
institution_id: institution_id,
country_codes: country_codes,
options: {
include_optional_metadata: true
}
})
client.institutions_get_by_id(request)
end

private
TransactionSyncResponse = Struct.new :added, :modified, :removed, :cursor, keyword_init: true
InvestmentsResponse = Struct.new :holdings, :transactions, :securities, keyword_init: true
Expand Down
4 changes: 1 addition & 3 deletions app/views/accounts/_account.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<%= turbo_frame_tag dom_id(account) do %>
<div class="p-4 flex items-center justify-between gap-3 group/account">
<div class="flex items-center gap-3">
<div class="w-8 h-8 flex items-center justify-center rounded-full text-xs font-medium <%= account.is_active ? "bg-blue-500/10 text-blue-500" : "bg-gray-500/10 text-gray-500" %>">
<%= account.name[0].upcase %>
</div>
<%= render "accounts/logo", account: account, size: "md" %>

<div>
<% if account.scheduled_for_deletion? %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/accounts/_logo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"full" => "w-full h-full"
} %>

<% if account.logo.attached? %>
<%= image_tag account.logo, class: size_classes[size] %>
<% if account.plaid_account_id? && account.institution_domain.present? %>
<%= image_tag "https://logo.synthfinance.com/#{account.institution_domain}", class: "rounded-full #{size_classes[size]}" %>
<% elsif account.logo.attached? %>
<%= image_tag account.logo, class: "rounded-full #{size_classes[size]}" %>
<% else %>
<%= circle_logo(account.name, hex: account.accountable.color, size: size) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddInstitutionDetailsToPlaidItems < ActiveRecord::Migration[7.2]
def change
add_column :plaid_items, :institution_url, :string
add_column :plaid_items, :institution_id, :string
add_column :plaid_items, :institution_color, :string
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.