Skip to content

Conversation

@Linhead
Copy link
Collaborator

@Linhead Linhead commented Oct 7, 2025

fix: correct amount calculation for self-transfer transactions in BTC, DASH, and DOGE and changes for transaction icon and text

Description

Fixed a bug where transactions sent to the user's own address displayed amount: 0 in the transaction list. Also change and add new color styles for transaction direction icon and amount text.

Changes

1. Self-transfer amount calculation fix

Root cause:
The normalizeTransaction() function in BTC/DASH/DOGE indexers incorrectly calculated the amount for self-transfer transactions. When a user sent funds to their own address, the transaction was classified as "outgoing" (direction = 'from'), but the amount calculation logic expected it to behave like an "incoming" transaction. This resulted in all outputs being excluded from the sum, producing amount = 0.

Fix applied:

  • Added isSelfTransfer detection in normalizeTransaction()
  • Modified amount calculation to handle self-transfers by summing outputs that target the owner's address
  • Applied fix consistently across all Bitcoin-like currencies:
    • src/lib/nodes/btc-indexer/utils.ts
    • src/lib/nodes/dash/utils.ts
    • src/lib/nodes/doge-indexer/utils.ts

2. Changes color in transaction text and icon

Added visual distinction for transaction types through color-coded plane icons:

  • Incoming transactions: Green plane icon and amount (good color)
  • Outgoing transactions: Red plane icon and amount (danger color)
  • Self-transfers: Grey-transparent plane icon and amount (rgba(255, 255, 255, 0.7))

Implementation:

  • Modified TransactionListItem.vue to apply directionClass to the prepend icon
  • Extended theme-specific styles for both light and dark themes
  • Reused existing color palette for consistency

3. Fixed duplicate senders bug

Root cause:
When a transaction had multiple inputs (UTXOs) from the same address, the senders array contained duplicate addresses. This caused the UI to incorrectly display "Me and 1 more address" instead of just "Me" for the sender.

Fix applied:

  • Added deduplication using new Set() for both senders and recipients arrays
  • Ensures each address appears only once in the arrays
  • Applied across BTC, DASH, and DOGE normalizers

4. Improved self-transfer detection logic

Root cause:
Previous implementation used .includes() to detect self-transfers, which incorrectly identified transactions as self-transfers even when only some (not all) addresses matched the owner.

Fix applied:

  • Changed detection logic from .includes() to .every()
  • Now correctly identifies self-transfer only when ALL senders and ALL recipients are the owner's address
  • For true self-transfers, amount is now taken from first output only (following Bitcoin wallet convention)

5. Added comprehensive unit tests

Added unit tests for all three cryptocurrencies to prevent regression:

  • src/lib/nodes/btc-indexer/utils.spec.ts
  • src/lib/nodes/dash/utils.spec.ts
  • src/lib/nodes/doge-indexer/utils.spec.ts

Test coverage:

  • Duplicate senders bug: Verifies senders array deduplication and correct direction display
  • Self-transfer amount bug: Verifies correct amount calculation (first output only, not sum of all outputs)
  • Detailed English comments explaining Bitcoin UTXO model and transaction structure
  • Complete type-safe mock transaction objects

Impact

  • Amount calculation fix: Only affects the self-transfer edge case. Normal incoming/outgoing transaction logic remains unchanged, minimizing regression risk.
  • Visual enhancement: Improved UX through consistent color coding across transaction amounts and direction icons.
  • Duplicate senders fix: Resolves UI display issue for transactions with multiple inputs from same address.
  • Self-transfer detection: More accurate detection prevents incorrect amount calculations.
  • Test coverage: Comprehensive tests ensure these bugs won't reoccur.

Related issue

Closes 889

External links (optional)

N/A

Screenshots or videos (optional)

image

Breaking changes

No breaking changes.

How to test

Prerequisites:

  • Test account with BTC/DASH/DOGE balance
  • Access to wallet functionality

Test steps:

Self-transfer amount calculation fix

  1. Create self-transfer transaction:

    • Log in as user
    • Send a small amount of BTC/DASH/DOGE to your own address
    • Wait for blockchain confirmation
  2. Verify transaction display:

    • Open the BTC/DASH/DOGE transaction list
    • Locate the self-transfer transaction
    • Expected: Amount field shows the actual transferred amount (e.g., 0.001 BTC)
    • Before fix: Amount field showed 0

Changes color in transaction text and icon

  1. Verify incoming transaction colors:

    • Locate any incoming transaction in the list
    • Expected: Plane icon (landing) and amount text are both green
  2. Verify outgoing transaction colors:

    • Locate any outgoing transaction in the list
    • Expected: Plane icon (takeoff) and amount text are both red
  3. Verify self-transfer transaction colors:

    • Use the self-transfer transaction from previous test
    • Expected: Plane icon and amount text are both grey-transparent (rgba(255, 255, 255, 0.7))
  4. Test theme switching:

    • Switch between light and dark themes
    • Expected: Color coding remains consistent and visible in both themes

Duplicate senders fix

  1. Create transaction with multiple UTXOs:

    • Make several small incoming transactions to build up UTXOs
    • Send an amount that requires using multiple UTXOs from the same address
  2. Verify sender display:

    • Check transaction list for the transaction
    • Expected: Sender shows just your address (e.g., "Me")
    • Before fix: Showed "Me and 1 more address"

Run unit tests

npm run test -- btc-indexer/utils.spec.ts
npm run test -- dash/utils.spec.ts
npm run test -- doge-indexer/utils.spec.ts

Checklist

  • Code is formatted
  • Tests added/updated (if needed) — No existing test infrastructure for this function
  • Documentation updated (if needed) — Added inline comments explaining self-transfer logic
  • Changes tested in all relevant environments — Requires manual testing with real blockchain data

@Linhead Linhead requested a review from a team as a code owner October 7, 2025 08:38
@Linhead Linhead added the bug Something isn't working label Oct 7, 2025
@vercel
Copy link

vercel bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
adamant-im Ready Ready Preview Comment Oct 14, 2025 8:20am

@Linhead Linhead linked an issue Oct 7, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Deployed to https://msg-adamant-pr-890.surge.sh 🚀

@dev-adamant-im dev-adamant-im added JavaScript Frontend or backend code in JavaScript UX/UI User interface and experience improvements labels Oct 8, 2025
Copy link
Member

@dev-adamant-im dev-adamant-im left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failed.

image

Amount is incorrect.

See this transaction: https://www.blockchain.com/explorer/transactions/btc/d9dc71624543a28df63c2a10455f3b35fe78b4f4fb9a8ba271a07e750019b572

image

First output is the amount.
The last one is receiving the change.

@dev-adamant-im
Copy link
Member

dev-adamant-im commented Oct 9, 2025

Connected issue: Colors.
Let's fix it in this pr.

  1. Dark theme
image

For self-transaction, let's color "Plane" icon and the amount in 'grey-transparent': rgba(255, 255, 255, 0.7).
Additionally, color income and outcome planes to good and danger colors (as their amounts):

image
  1. Light theme
image

For self-transaction, let's color "Plane" icon and the amount in 'regular': #4a4a4a.
Additionally, color income and outcome planes and their amounts to good and danger colors:

image

@dev-adamant-im
Copy link
Member

Connected issue: Wrong transfer direction and amount.
Let's fix it in this pr.

image

See this transaction:
https://www.blockchain.com/explorer/transactions/btc/795190ac15ab1c402fd9dd117e41a2fee8c38b2b1c720fca1b73582d19595393

image

It's outcome transfer, not income.
Recipient is 18Yva8fgQyMxsSfYHpM2wqSnft814tPZxg.
Amount is 0.00000600 BTC.
And 0.00091534 BTC is the change to own wallet.

@dev-adamant-im
Copy link
Member

@Linhead @skranee

Probably all BTC-based are affected.
After fixes, verify also transfer details are correctly shown in the Details screen.
Note: iOS app shows these transfers correctly.

@dev-adamant-im
Copy link
Member

dev-adamant-im commented Oct 9, 2025

Another issue
[Bug] Pagination for BTC, DASH, ETH & ERC20 tx list doesn't work #896
But we'll fix it separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working JavaScript Frontend or backend code in JavaScript UX/UI User interface and experience improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Incorrect amount in BTC, DOGE, DASH Tx (Sending to own address)

5 participants