Skip to content

fix(bitcoin): sync and amount formatting - #543

Merged
taran-a merged 5 commits into
mainfrom
fix/bitcoin-sync-and-amount-formatting
Nov 3, 2026
Merged

taran-a merged 5 commits into
mainfrom
fix/bitcoin-sync-and-amount-formatting

Conversation

@taran-a

@taran-a taran-a commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Explanation

Run normal synchronization and publish balance/activity updates before repair scans, preventing slow repairs from delaying those updates. Preserve repair retries and sync coalescing.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@taran-a
taran-a requested review from a team as code owners November 2, 2026 08:26
@taran-a
taran-a force-pushed the fix/bitcoin-sync-and-amount-formatting branch from 3b78067 to 89e16e5 Compare November 2, 2026 08:28
@taran-a
taran-a added this pull request to stack #544 November 2, 2026 08:29
@taran-a

taran-a commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.2.0-preview-89e16e5
@metamask-previews/snap-networks-utils@3.1.0-preview-89e16e5
@metamask-previews/solana-wallet-snap@7.2.0-preview-89e16e5
@metamask-previews/stellar-wallet-snap@2.0.0-preview-89e16e5
@metamask-previews/tron-wallet-snap@4.3.0-preview-89e16e5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Repair and regular sync runs can overlap for the same account, allowing stale balances and transaction statuses to overwrite newer published data.

1 open issue
What changed in this PR

This PR separates Bitcoin repair scans from regular synchronization and uses exact decimal formatting for balances, transaction amounts, fees, and UI displays.

Changes:

  • Schedules repairs independently while preserving retry behavior and sync coalescing.
  • Replaces floating-point BTC formatting with a shared integer-based formatter.
  • Adds regression tests and changelog entries for synchronization and amount formatting.
File Description
packages/​bitcoin-wallet-snap/​src/​utils/​format-btc.ts Adds exact satoshi-to-BTC decimal formatting.
packages/​bitcoin-wallet-snap/​src/​utils/​format-btc.test.ts Tests small amounts, precision boundaries, and balance validation.
packages/​bitcoin-wallet-snap/​src/​infra/​SnapClientAdapter.ts Formats emitted balances with the shared helper.
packages/​bitcoin-wallet-snap/​src/​infra/​SnapClientAdapter.test.ts Tests small-balance event formatting.
packages/​bitcoin-wallet-snap/​src/​infra/​jsx/​format.ts Uses exact formatting for displayed BTC amounts.
packages/​bitcoin-wallet-snap/​src/​infra/​jsx/​format.test.ts Tests decimal display and currency suffixes.
packages/​bitcoin-wallet-snap/​src/​handlers/​RpcHandler.test.ts Updates the fee mock to provide satoshis.
packages/​bitcoin-wallet-snap/​src/​handlers/​mappings.ts Formats transaction amounts and fees exactly.
packages/​bitcoin-wallet-snap/​src/​handlers/​mappings.test.ts Adds precision and transaction-validation coverage.
packages/​bitcoin-wallet-snap/​src/​handlers/​KeyringHandler.ts Returns exact decimal account balances.
packages/​bitcoin-wallet-snap/​src/​handlers/​KeyringHandler.test.ts Tests small balances and updates amount mocks.
packages/​bitcoin-wallet-snap/​src/​handlers/​CronHandler.ts Separates repair execution from regular synchronization.
packages/​bitcoin-wallet-snap/​src/​handlers/​CronHandler.test.ts Tests repair scheduling, overlap, retries, and client-state checks.
packages/​bitcoin-wallet-snap/​snap.manifest.json Adds a dedicated 45-second repair schedule.
packages/​bitcoin-wallet-snap/​CHANGELOG.md Documents independent repairs and formatting fixes.

Review effort: Balanced

@taran-a
taran-a requested a review from Battambang November 2, 2026 16:05
Base automatically changed from refactor/bitcoin-shared-state to main November 2, 2026 16:11
@taran-a
taran-a force-pushed the fix/bitcoin-sync-and-amount-formatting branch from a8f5dea to 2a031d5 Compare November 2, 2026 16:55

@stanleyyconsensys stanleyyconsensys left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM, left some design comments

@stanleyyconsensys stanleyyconsensys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, Approved with a small comment on accountUseCases

@taran-a
taran-a force-pushed the fix/bitcoin-sync-and-amount-formatting branch from 6fc6f74 to e1da187 Compare November 3, 2026 12:26
@taran-a
taran-a enabled stacked auto-merge November 3, 2026 12:32
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@taran-a
taran-a disabled stacked auto-merge November 3, 2026 12:36
@taran-a
taran-a added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 1fa453e Nov 3, 2026
56 checks passed
@taran-a
taran-a deleted the fix/bitcoin-sync-and-amount-formatting branch November 3, 2026 12:41
n3ps pushed a commit to n3ps/metamask-extension that referenced this pull request Nov 4, 2026
…aMask#47621)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

# Bitcoin [3.3.0]

### Changed

- Retry transient Bitcoin indexer, price API, and signed transaction
broadcast failures with the shared fetch policy, and treat duplicate
broadcasts as successful.
([MetaMask#530](MetaMask/internal-snaps#530))
### Fixed
- Fix formatting of small Bitcoin balances to avoid scientific notation.
([MetaMask#543](MetaMask/internal-snaps#543))

# Tron [4.3.1]

### Fixed

- Allow transaction confirmation after remote simulation failures while
retaining security warnings and checks for locally invalid transactions.
([MetaMask#552](MetaMask/internal-snaps#552))

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Changelog**

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry: null

## **Related issues**

n/a

## **Manual testing steps**

n/a

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [X] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [X] I've completed the PR template to the best of my ability
- [X] I’ve included tests if applicable
- [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Patch bumps change Bitcoin broadcast/retry behavior and Tron
confirmation when remote simulation fails, both on transaction-critical
paths.
> 
> **Overview**
> Bumps **`@metamask/bitcoin-wallet-snap`** to **3.3.0** and
**`@metamask/tron-wallet-snap`** to **4.3.1** in `package.json`, with
matching **`yarn.lock`** resolutions. No extension source
changes—behavior comes from the new snap builds.
> 
> With **Bitcoin 3.3.0**, users get more resilient
indexer/price/broadcast calls (shared fetch retries, duplicate
broadcasts treated as success) and corrected display of very small
balances (no scientific notation).
> 
> With **Tron 4.3.1**, confirmation can proceed when **remote**
simulation fails, while locally invalid transactions still block
approval and security warnings remain.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4bd1b01. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants