mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Add "Link to existing" option in SnapTrade Setup Accounts modal (#935)
* Add account linking functionality for SnapTrade items - Introduced UI to link existing accounts when setting up SnapTrade items, preventing duplicate account creation. - Updated controller to fetch linkable accounts. - Added tests to verify proper filtering of accounts and linking behavior. * Add `snaptrade_item_id` to account linking flow for SnapTrade items - Updated controller to allow specifying `snaptrade_item_id` when linking accounts. - Adjusted form and views to include `snaptrade_item_id` as a hidden field. - Enhanced tests to validate behavior with the new parameter.
This commit is contained in:
@@ -154,6 +154,14 @@ class SnaptradeItemsController < ApplicationController
|
||||
@snaptrade_item.sync_later
|
||||
end
|
||||
|
||||
# Existing unlinked, visible investment/crypto accounts that could be linked instead of creating duplicates
|
||||
@linkable_accounts = Current.family.accounts
|
||||
.visible
|
||||
.where(accountable_type: %w[Investment Crypto])
|
||||
.left_joins(:account_providers)
|
||||
.where(account_providers: { id: nil })
|
||||
.order(:name)
|
||||
|
||||
# Determine view state
|
||||
@syncing = @snaptrade_item.syncing?
|
||||
@waiting_for_sync = no_accounts && @syncing
|
||||
@@ -369,9 +377,10 @@ class SnaptradeItemsController < ApplicationController
|
||||
def link_existing_account
|
||||
account_id = params[:account_id]
|
||||
snaptrade_account_id = params[:snaptrade_account_id]
|
||||
snaptrade_item_id = params[:snaptrade_item_id]
|
||||
|
||||
account = Current.family.accounts.find_by(id: account_id)
|
||||
snaptrade_item = Current.family.snaptrade_items.first
|
||||
snaptrade_item = Current.family.snaptrade_items.find_by(id: snaptrade_item_id)
|
||||
snaptrade_account = snaptrade_item&.snaptrade_accounts&.find_by(id: snaptrade_account_id)
|
||||
|
||||
if account && snaptrade_account
|
||||
|
||||
Reference in New Issue
Block a user