Files
sure/app/models/account_provider.rb
Ethan 3b4ab735b0 Add (beta) CoinStats Crypto Wallet Integration with Balance and Transaction Syncing (#512)
* Feat(CoinStats): Scaffold implementation, not yet functional

* Feat(CoinStats): Implement crypto wallet balance and transactions

* Feat(CoinStats): Add tests, Minor improvements

* Feat(CoinStats): Utilize bulk fetch API endpoints

* Feat(CoinStats): Migrate strings to i8n

* Feat(CoinStats): Fix error handling in wallet link modal

* Feat(CoinStats): Implement hourly provider sync job

* Feat(CoinStats): Generate docstrings

* Fix(CoinStats): Validate API Key on provider update

* Fix(Providers): Safely handle race condition in merchance creation

* Fix(CoinStats): Don't catch system signals in account processor

* Fix(CoinStats): Preload before iterating accounts

* Fix(CoinStats): Add no opener / referrer to API dashboard link

* Fix(CoinStats): Use strict matching for symbols

* Fix(CoinStats): Remove dead code in transactions importer

* Fix(CoinStats): Avoid transaction fallback ID collisions

* Fix(CoinStats): Improve Blockchains fetch error handling

* Fix(CoinStats): Enforce NOT NULL constraint for API Key schema

* Fix(CoinStats): Migrate sync status strings to i8n

* Fix(CoinStats): Use class name rather than hardcoded string

* Fix(CoinStats): Use account currency rather than hardcoded USD

* Fix(CoinStats): Migrate from standalone to Provider class

* Fix(CoinStats): Fix test failures due to string changes
2026-01-07 15:59:04 +01:00

36 lines
1.1 KiB
Ruby

class AccountProvider < ApplicationRecord
belongs_to :account
belongs_to :provider, polymorphic: true
has_many :holdings, dependent: :nullify
validates :account_id, uniqueness: { scope: :provider_type }
validates :provider_id, uniqueness: { scope: :provider_type }
# When unlinking a CoinStats account, also destroy the CoinstatsAccount record
# so it doesn't remain orphaned and count as "needs setup".
# Other providers may legitimately enter a "needs setup" state.
after_destroy :destroy_coinstats_provider_account, if: :coinstats_provider?
# Returns the provider adapter for this connection
def adapter
Provider::Factory.create_adapter(provider, account: account)
end
# Convenience method to get provider name
# Delegates to the adapter for consistency, falls back to underscored provider_type
def provider_name
adapter&.provider_name || provider_type.underscore
end
private
def coinstats_provider?
provider_type == "CoinstatsAccount"
end
def destroy_coinstats_provider_account
provider&.destroy
end
end