You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: bitcoin fee calc for display and error handling (#6932)
## Explanation
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:
* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
Fix Bitcoin network fee computation in bridge quotes
Problem:
Bitcoin bridge quotes were not computing network fees, causing them to
always show $0 for gas costs.
Root Cause:
The appendNonEvmFees function only called the snap's computeFee method
when trade was a string. This worked for Solana (which has string
trades), but Bitcoin trades are objects with structure {
unsignedPsbtBase64: string, inputsToSign: null }.
Fix:
Remove the typeof trade === 'string' check
Extract unsignedPsbtBase64 from Bitcoin trade objects before passing to
snap
Support both 'base' (Solana) and 'priority' (Bitcoin) fee types in snap
response
Add error handling to return quotes with nonEvmFeesInNative: undefined
if snap fails.
> snap fails on bitcoin when the account does not have enough for gas.
we added this error handling to allow 'quote shopping' on bitcoin
without a runtime error causing the quote to fail.
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
Draft client PR:
MetaMask/metamask-extension#37137
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Fix Bitcoin fee computation in bridge quotes by normalizing trade data
for snaps, supporting 'priority' fees, and adding graceful error
handling.
>
> - **Bridge fees (non‑EVM)**:
> - Normalize trade data for snap fee computation: use string directly
(Solana) or extract `unsignedPsbtBase64` from `BitcoinTradeData`
(Bitcoin).
> - Support `'priority'` fee type (Bitcoin) in addition to `'base'`;
fallback to first returned fee.
> - Add guards for missing snap/trade; wrap in try/catch and set
`nonEvmFeesInNative` to `undefined` on failures; improved error logging
with `quote.requestId`.
> - **Types/exports**:
> - Export `BitcoinTradeData`; consume it in `quote-fees`.
> - **Changelog**:
> - Document fix for Bitcoin network fee computation under Unreleased.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
45987f7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Micaela <[email protected]>
Copy file name to clipboardExpand all lines: packages/bridge-controller/CHANGELOG.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Changed
11
11
12
-
- Clean up SSE stream reader after use ([#6965](https://github.com/MetaMask/core/pull/6965))p
12
+
- Clean up SSE stream reader after use ([#6965](https://github.com/MetaMask/core/pull/6965))
13
+
14
+
### Fixed
15
+
16
+
- Fix Bitcoin network fee computation by extracting `unsignedPsbtBase64` from Bitcoin trade objects and supporting `'priority'` fee type from Bitcoin snap ([#XXXX](https://github.com/MetaMask/core/pull/XXXX))
0 commit comments