feat: Support multiple crypto wallets with same token (#676)

* feat: Support multiple crypto wallets with same token

Allows users to import multiple wallets containing the same
cryptocurrency (e.g., ETH on different wallet addresses).

Changes:
- Add wallet_address column to coinstats_accounts
- Update uniqueness validation to include wallet_address
- Extract and store wallet address in WalletLinker
- Add composite unique index on [item_id, account_id, wallet_address]
- Add tests for multi-wallet support and backwards compatibility

Users can now have:
- ETH (0xAAA...) → "Ethereum (0xAA...AA)"
- ETH (0xBBB...) → "Ethereum (0xBB...BB)"

Backwards compatible: existing accounts with wallet_address: nil
continue to work.

* style: Fix array bracket spacing in migration

* chore: Update schema.rb with wallet_address column and index

Add the missing wallet_address column and composite unique index
to db/schema.rb for CI compatibility with db:schema:load

* test: Add test for wallet deletion with same token different addresses

Verifies that deleting one wallet does not affect other wallets
that share the same token but have different addresses.

Addresses review comment from @EthanC via @jjmata

---------

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
foXaCe
2026-01-18 11:27:09 +01:00
committed by GitHub
parent 79d14c142f
commit 302fb84086
6 changed files with 124 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ class CoinstatsAccount < ApplicationRecord
has_one :account, through: :account_provider, source: :account
validates :name, :currency, presence: true
validates :account_id, uniqueness: { scope: :coinstats_item_id, allow_nil: true }
validates :account_id, uniqueness: { scope: [ :coinstats_item_id, :wallet_address ], allow_nil: true }
# Alias for compatibility with provider adapter pattern
alias_method :current_account, :account

View File

@@ -85,7 +85,8 @@ class CoinstatsItem::WalletLinker
name: account_name,
currency: "USD",
current_balance: current_balance,
account_id: token_id
account_id: token_id,
wallet_address: address
)
# Store wallet metadata for future syncs