Skip to content

Commit de26145

Browse files
authored
fix: disable CTA swap button for Tron when no network fees retrieved (#32717)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until this PR meets the canonical Definition of Ready For Review in `docs/readme/ready-for-review.md`. In short: the template must be materially complete (not just section titles present), all status checks must be currently passing, and the only expected follow-up commits must be reviewer-driven. --> <!-- mms-check directive vocabulary — read by .github/scripts/shared/pr-template-checks.ts at module load to build the validation plan. Directives are invisible in rendered markdown and must NOT be removed or edited without updating the validator registry. type=text Section must contain non-placeholder prose. type=changelog Section must have a valid CHANGELOG entry: line. type=issue-link Section must have a Fixes:/Closes:/Refs: line with a value. type=manual-testing Section must have real testing steps or an explicit N/A. type=screenshot Section must have evidence (image/URL) or an explicit N/A. type=checklist Section must have all checkboxes consciously checked. required=true|false Whether a missing/invalid section runs the validator at all. blocking=true|false Whether a failure of this check fails the CI workflow. Default: false — failures are shown as warnings in the sticky comment but do not block the PR. Sections without a directive are checked for structural presence only. --> ## **Description** <!-- mms-check: type=text required=true --> <!-- 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? --> This pull request updates the logic for determining if a network fee is unavailable for bridge quotes, specifically adding support for Tron chain IDs in addition to Bitcoin. It also expands the test coverage to ensure correct behavior for various Tron-related scenarios. **Logic updates for network fee availability:** * Updated `isQuoteNetworkFeeUnavailable` in `index.ts` to consider both Bitcoin and Tron chain IDs, returning `true` for Tron quotes with missing, zero, or negative network fees. **Test coverage improvements:** * Added multiple test cases in `index.test.ts` to verify that the function correctly handles Tron quotes with zero, negative, missing, and positive network fees, ensuring the new logic is thoroughly tested. * Updated the description of an existing test to clarify that it applies to non-BTC/non-Tron quotes with zero network fee. ## **Changelog** <!-- mms-check: type=changelog required=true blocking=true --> <!-- 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: disable CTA swap button for Tron when no network fees retrieved ## **Related issues** <!-- mms-check: type=issue-link required=true --> Fixes: submit Tron swaps without network fees ## **Manual testing steps** <!-- mms-check: type=manual-testing required=true --> ```gherkin Go to swap page Try a quote pair for Tron network Make the compute fees from the Tron snap failed or throw in the bridge-status controller. When the network fees are not returned, a 0$ network fees is displayed and the CTA button of the quote should not be enabled with the message "insufficient funds" ``` ## **Screenshots/Recordings** <!-- mms-check: type=screenshot required=true --> <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> n/a ### **After** <!-- [screenshots/recordings] --> <img width="300" height="600" alt="tron-fees" src="https://github.com/user-attachments/assets/d12d1b74-aeb5-4f52-8fc5-71b402e0f6d9" /> ## **Pre-merge author checklist** <!-- mms-check: type=checklist required=true --> <!-- Every checklist item must be consciously assessed before marking this PR as "Ready for review". A checked box means you deliberately considered that responsibility, not that you literally performed every action listed. Unchecked boxes are ambiguous: they are not an implicit "N/A" and they are not a silent "skip". See `docs/readme/ready-for-review.md` for the full checklist semantics. --> - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. #### Performance checks (if applicable) - [X] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [X] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [X] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example For performance guidelines and tooling, see the [Performance Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers). ## **Pre-merge reviewer checklist** <!-- Reviewer checklist items follow the same semantics as the author checklist: an unchecked box is ambiguous, a checked box means the reviewer consciously assessed that responsibility. See `docs/readme/ready-for-review.md`. --> - [ ] 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** > Changes swap submission gating for Tron bridge flows; incorrect fee detection could block valid swaps or still allow bad ones, though behavior mirrors existing Bitcoin safeguards. > > **Overview** > Tron bridge quotes are now treated like Bitcoin when **network fees are missing or invalid**, so users cannot confirm a swap while fees show as $0 after a failed fee fetch. > > `isQuoteNetworkFeeUnavailable` applies the existing BTC rules (missing, zero, or non-positive `totalNetworkFee`) to **Tron source chains** via `isTronChainId`, which keeps the swap CTA disabled in `BridgeView` and `SwapsConfirmButton` instead of allowing submission with bogus fees. Unit tests cover Tron zero, negative, missing, and valid fee cases. > > `@metamask/tron-wallet-snap` is bumped **1.28.0 → 1.29.0** in lockfile alongside the logic change. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3859859. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent cbb9b31 commit de26145

4 files changed

Lines changed: 76 additions & 9 deletions

File tree

app/components/UI/Bridge/hooks/useIsNetworkFeeUnavailable/index.test.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('isQuoteNetworkFeeUnavailable', () => {
6767
expect(isQuoteNetworkFeeUnavailable(createQuote())).toBe(false);
6868
});
6969

70-
it('returns false for a non-BTC quote with zero network fee', () => {
70+
it('returns false for a non-BTC/non-Tron quote with zero network fee', () => {
7171
expect(
7272
isQuoteNetworkFeeUnavailable(
7373
createQuote({
@@ -84,6 +84,70 @@ describe('isQuoteNetworkFeeUnavailable', () => {
8484
).toBe(false);
8585
});
8686

87+
it('returns true for a Tron quote with zero network fee', () => {
88+
expect(
89+
isQuoteNetworkFeeUnavailable(
90+
createQuote({
91+
quote: {
92+
...mockQuoteWithMetadata.quote,
93+
srcChainId: ChainId.TRON,
94+
},
95+
totalNetworkFee: {
96+
...mockQuoteWithMetadata.totalNetworkFee,
97+
amount: '0',
98+
},
99+
}),
100+
),
101+
).toBe(true);
102+
});
103+
104+
it('returns true for a Tron quote with negative network fee', () => {
105+
expect(
106+
isQuoteNetworkFeeUnavailable(
107+
createQuote({
108+
quote: {
109+
...mockQuoteWithMetadata.quote,
110+
srcChainId: ChainId.TRON,
111+
},
112+
totalNetworkFee: {
113+
...mockQuoteWithMetadata.totalNetworkFee,
114+
amount: '-1',
115+
},
116+
}),
117+
),
118+
).toBe(true);
119+
});
120+
121+
it('returns true for a Tron quote with missing network fee amount', () => {
122+
expect(
123+
isQuoteNetworkFeeUnavailable(
124+
createQuote({
125+
quote: {
126+
...mockQuoteWithMetadata.quote,
127+
srcChainId: ChainId.TRON,
128+
},
129+
totalNetworkFee: {
130+
...mockQuoteWithMetadata.totalNetworkFee,
131+
amount: undefined,
132+
} as unknown as NonNullable<ActiveQuote>['totalNetworkFee'],
133+
}),
134+
),
135+
).toBe(true);
136+
});
137+
138+
it('returns false for a Tron quote with positive network fee', () => {
139+
expect(
140+
isQuoteNetworkFeeUnavailable(
141+
createQuote({
142+
quote: {
143+
...mockQuoteWithMetadata.quote,
144+
srcChainId: ChainId.TRON,
145+
},
146+
}),
147+
),
148+
).toBe(false);
149+
});
150+
87151
it('returns false when the quote has no source chain', () => {
88152
expect(
89153
isQuoteNetworkFeeUnavailable(

app/components/UI/Bridge/hooks/useIsNetworkFeeUnavailable/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react';
22
import { BigNumber } from 'bignumber.js';
3-
import { isBitcoinChainId } from '@metamask/bridge-controller';
3+
import { isBitcoinChainId, isTronChainId } from '@metamask/bridge-controller';
44
import { useBridgeQuoteData } from '../useBridgeQuoteData';
55

66
type ActiveQuote = ReturnType<typeof useBridgeQuoteData>['activeQuote'];
@@ -10,7 +10,10 @@ export const isQuoteNetworkFeeUnavailable = (
1010
): boolean => {
1111
const sourceChainId = activeQuote?.quote?.srcChainId;
1212

13-
if (!sourceChainId || !isBitcoinChainId(sourceChainId)) {
13+
if (
14+
!sourceChainId ||
15+
(!isBitcoinChainId(sourceChainId) && !isTronChainId(sourceChainId))
16+
) {
1417
return false;
1518
}
1619

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
"@metamask/swappable-obj-proxy": "^2.1.0",
357357
"@metamask/transaction-controller": "^68.2.0",
358358
"@metamask/transaction-pay-controller": "^23.17.4",
359-
"@metamask/tron-wallet-snap": "^1.28.0",
359+
"@metamask/tron-wallet-snap": "^1.29.0",
360360
"@metamask/utils": "^11.11.0",
361361
"@metamask/wallet": "^6.0.0",
362362
"@myx-trade/sdk": "^0.1.265",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10545,10 +10545,10 @@ __metadata:
1054510545
languageName: node
1054610546
linkType: hard
1054710547

10548-
"@metamask/tron-wallet-snap@npm:^1.28.0":
10549-
version: 1.28.0
10550-
resolution: "@metamask/tron-wallet-snap@npm:1.28.0"
10551-
checksum: 10/e8fe563735e0fca306cd1caa2cde45b193d0f09f7a3da545be24eee55a64f1ff239a7460ad9c4a0c6b67552a1423ef18328350a4b76a2409a1fbe609f69b8769
10548+
"@metamask/tron-wallet-snap@npm:^1.29.0":
10549+
version: 1.29.0
10550+
resolution: "@metamask/tron-wallet-snap@npm:1.29.0"
10551+
checksum: 10/8afc50c84215f63ae1d8ab985ff682f2a5d3b16cf15bb50f12c7d1d95df8e60d29881dbe13858941655e2163410dccba6b609307a4a3fb85458c042f799a6bb8
1055210552
languageName: node
1055310553
linkType: hard
1055410554

@@ -35617,7 +35617,7 @@ __metadata:
3561735617
"@metamask/test-dapp-solana": "npm:^0.3.0"
3561835618
"@metamask/transaction-controller": "npm:^68.2.0"
3561935619
"@metamask/transaction-pay-controller": "npm:^23.17.4"
35620-
"@metamask/tron-wallet-snap": "npm:^1.28.0"
35620+
"@metamask/tron-wallet-snap": "npm:^1.29.0"
3562135621
"@metamask/utils": "npm:^11.11.0"
3562235622
"@metamask/wallet": "npm:^6.0.0"
3562335623
"@myx-trade/sdk": "npm:^0.1.265"

0 commit comments

Comments
 (0)