mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
* feat: add Binance support (Items, Accounts, Importers, Processor, and Sync) * refactor: deduplicate 'stablecoins' constant and push stale_rate filter to SQL --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
37 lines
1000 B
Ruby
37 lines
1000 B
Ruby
# frozen_string_literal: true
|
|
|
|
module BinanceItem::Unlinking
|
|
extend ActiveSupport::Concern
|
|
|
|
def unlink_all!(dry_run: false)
|
|
results = []
|
|
|
|
binance_accounts.find_each do |provider_account|
|
|
links = AccountProvider.where(provider_type: BinanceAccount.name, provider_id: provider_account.id).to_a
|
|
link_ids = links.map(&:id)
|
|
result = {
|
|
provider_account_id: provider_account.id,
|
|
name: provider_account.name,
|
|
provider_link_ids: link_ids
|
|
}
|
|
results << result
|
|
|
|
next if dry_run
|
|
|
|
begin
|
|
ActiveRecord::Base.transaction do
|
|
if link_ids.any?
|
|
Holding.where(account_provider_id: link_ids).update_all(account_provider_id: nil)
|
|
end
|
|
links.each(&:destroy!)
|
|
end
|
|
rescue StandardError => e
|
|
Rails.logger.warn("BinanceItem Unlinker: failed to unlink ##{provider_account.id}: #{e.class} - #{e.message}")
|
|
result[:error] = e.message
|
|
end
|
|
end
|
|
|
|
results
|
|
end
|
|
end
|