diff --git a/app/controllers/simplefin_items_controller.rb b/app/controllers/simplefin_items_controller.rb index 91b04a66b..52c44feae 100644 --- a/app/controllers/simplefin_items_controller.rb +++ b/app/controllers/simplefin_items_controller.rb @@ -52,7 +52,7 @@ class SimplefinItemsController < ApplicationController end def setup_accounts - @simplefin_accounts = @simplefin_item.simplefin_accounts + @simplefin_accounts = @simplefin_item.simplefin_accounts.includes(:account).where(accounts: { id: nil }) @account_type_options = [ [ "Checking or Savings Account", "Depository" ], [ "Credit Card", "CreditCard" ], @@ -69,8 +69,9 @@ class SimplefinItemsController < ApplicationController options: Depository::SUBTYPES.map { |k, v| [ v[:long], k ] } }, "CreditCard" => { - label: "Credit Card Type:", - options: CreditCard::SUBTYPES.map { |k, v| [ v[:long], k ] } + label: "", + options: [], + message: "Credit cards will be automatically set up as credit card accounts." }, "Investment" => { label: "Investment Type:", @@ -98,6 +99,9 @@ class SimplefinItemsController < ApplicationController simplefin_account = @simplefin_item.simplefin_accounts.find(simplefin_account_id) selected_subtype = account_subtypes[simplefin_account_id] + + # Default subtype for CreditCard since it only has one option + selected_subtype = "credit_card" if selected_type == "CreditCard" && selected_subtype.blank? # Create account with user-selected type and subtype account = Account.create_from_simplefin_account( diff --git a/app/models/account.rb b/app/models/account.rb index f71a95262..001756dba 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -93,7 +93,6 @@ class Account < ApplicationRecord def build_simplefin_accountable_attributes(simplefin_account, account_type, subtype) attributes = {} - attributes[:balance] = simplefin_account.current_balance if %w[CreditCard Loan].include?(account_type) attributes[:subtype] = subtype if subtype.present? attributes end diff --git a/app/models/simplefin_account.rb b/app/models/simplefin_account.rb index 56af534f2..5d8bee90b 100644 --- a/app/models/simplefin_account.rb +++ b/app/models/simplefin_account.rb @@ -15,8 +15,8 @@ class SimplefinAccount < ApplicationRecord current_balance: parse_balance(snapshot[:balance]), available_balance: parse_balance(snapshot[:"available-balance"]), currency: parse_currency(snapshot[:currency]), - account_type: snapshot[:type] || "unknown", - account_subtype: snapshot[:subtype], + account_type: snapshot["type"] || "unknown", + account_subtype: snapshot["subtype"], name: snapshot[:name], account_id: snapshot[:id], raw_payload: account_snapshot diff --git a/app/models/simplefin_item/syncer.rb b/app/models/simplefin_item/syncer.rb index 3243e14f5..cf20a9912 100644 --- a/app/models/simplefin_item/syncer.rb +++ b/app/models/simplefin_item/syncer.rb @@ -9,8 +9,9 @@ class SimplefinItem::Syncer # Loads item metadata, accounts, transactions from SimpleFin API simplefin_item.import_latest_simplefin_data - # Check if this is the first sync and we have new accounts to set up - if simplefin_item.accounts.empty? && simplefin_item.simplefin_accounts.any? + # Check if we have new SimpleFin accounts that need setup + unlinked_accounts = simplefin_item.simplefin_accounts.includes(:account).where(accounts: { id: nil }) + if unlinked_accounts.any? # Mark as pending account setup so user can choose account types simplefin_item.update!(pending_account_setup: true) return diff --git a/app/views/simplefin_items/_simplefin_item.html.erb b/app/views/simplefin_items/_simplefin_item.html.erb index 552be10d0..e537054b7 100644 --- a/app/views/simplefin_items/_simplefin_item.html.erb +++ b/app/views/simplefin_items/_simplefin_item.html.erb @@ -72,18 +72,20 @@
Accounts ready to set up
-Choose account types for your imported SimpleFin accounts.
+New accounts ready to set up
+Choose account types for your newly imported SimpleFin accounts.
<%= render DS::Link.new( - text: "Set Up Accounts", + text: "Set Up New Accounts", icon: "settings", variant: "primary", href: setup_accounts_simplefin_item_path(simplefin_item) ) %>No accounts found
This connection doesn't have any synchronized accounts yet.
diff --git a/app/views/simplefin_items/_subtype_select.html.erb b/app/views/simplefin_items/_subtype_select.html.erb index 47fa52949..a19509825 100644 --- a/app/views/simplefin_items/_subtype_select.html.erb +++ b/app/views/simplefin_items/_subtype_select.html.erb @@ -7,7 +7,7 @@ simplefin_account.name.downcase.include?("savings") ? "savings" : "") : "" %> <%= select_tag "account_subtypes[#{simplefin_account.id}]", options_for_select([["Select #{account_type == 'Depository' ? 'subtype' : 'type'}", ""]] + subtype_config[:options], selected_value), - { class: "w-full px-3 py-2 border border-primary rounded-lg focus:ring-2 focus:ring-blue-600 focus:border-blue-600" } %> + { class: "w-full px-3 py-2 border border-primary rounded-lg focus:ring-2 focus:ring-primary focus:border-primary" } %> <% else %><%= subtype_config[:message] %>
<% end %> diff --git a/app/views/simplefin_items/setup_accounts.html.erb b/app/views/simplefin_items/setup_accounts.html.erb index 7b357e2d3..3a9851853 100644 --- a/app/views/simplefin_items/setup_accounts.html.erb +++ b/app/views/simplefin_items/setup_accounts.html.erb @@ -4,7 +4,7 @@ <% dialog.with_header(title: "Set Up Your SimpleFin Accounts") do %>Syncing accounts...
+ <%= icon "loader-2", class: "w-5 h-5 text-primary animate-spin mr-2" %> +Syncing accounts...
<%= simplefin_account.account_type.humanize %>
-+
+ <% if simplefin_account.account %> + <%= simplefin_account.account.accountable_type.humanize %> + <% else %> + <%= simplefin_account.account_type.humanize %> + <% end %> +
+Balance: <%= number_to_currency(simplefin_account.current_balance || 0) %> <% if simplefin_account.currency != "USD" %> <%= simplefin_account.currency %> @@ -47,9 +53,9 @@
No accounts found. Try syncing again.
+No accounts found. Try syncing again.
<%= button_to "Sync Now", sync_simplefin_item_path(@simplefin_item), method: :post, class: "mt-4 btn btn--secondary" %>