Skip to content

Commit 9432aa0

Browse files
authored
fix(MUSD-701): use Money Account balance in Add money sheet (MetaMask#29734)
## **Description** The "Move mUSD" row in the Add money sheet was showing a balance that did not match the Money Account balance displayed at the top of the screen. The two figures were sourced from different places, which surfaced as an obvious mismatch whenever the selected EVM account was not the same as the Money Account. Root cause: the sheet was reading from `useMusdBalance().fiatBalanceAggregatedFormatted`, which aggregates mUSD across the currently selected EVM account. The screen header, by contrast, uses `useMoneyAccountBalance`, which is the canonical Money Account balance. Fix: switch the sheet to consume `useMoneyAccountBalance().totalFiatFormatted` so the "Move mUSD" amount and the header always agree. Tests were updated to mock the new hook and assert the same fallback behaviour (no-amount copy when the balance is unavailable, locale fiat prefix preserved). Credit to Matthew Grainger for diagnosing the source-of-truth mismatch on the Jira ticket. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: MUSD-701 ## **Manual testing steps** ```gherkin Feature: Add money sheet balance consistency Scenario: user opens the Add money sheet with a funded Money Account Given the user has a non-zero Money Account balance And the selected EVM account is not the Money Account When the user opens the Add money sheet Then the "Move mUSD" row shows the same fiat amount as the Money Account header Scenario: user opens the Add money sheet with no mUSD Given the user's Money Account balance is unavailable or zero When the user opens the Add money sheet Then the "Move mUSD" row shows the no-amount copy ``` ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [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 - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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) - [ ] I've tested on Android - [ ] I've tested with a power user scenario - [ ] I've instrumented key operations with Sentry traces for production performance metrics ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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] > **Low Risk** > Low risk UI data-source swap: the “Move mUSD” row now reads from the canonical Money Account balance, which could only affect displayed copy if the previous EVM-account-aggregated value differed or was undefined. > > **Overview** > Updates the Add Money bottom sheet so the “Move mUSD” option displays the **Money Account** fiat balance (via `useMoneyAccountBalance().totalFiatFormatted`) instead of the previously EVM-account-aggregated `useMusdBalance()` value, eliminating mismatches with the header balance. > > Adjusts `MoneyAddMoneySheet` tests to mock the new hook and keep the same behaviors for locale-prefixed amounts and the no-amount fallback copy. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 88dd0bc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 2e4b3d7 commit 9432aa0

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

app/components/UI/Money/components/MoneyAddMoneySheet/MoneyAddMoneySheet.test.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import MoneyAddMoneySheet from './MoneyAddMoneySheet';
55
import { MoneyAddMoneySheetTestIds } from './MoneyAddMoneySheet.testIds';
66
import { useMusdConversionFlowData } from '../../../Earn/hooks/useMusdConversionFlowData';
77
import { useRampNavigation } from '../../../Ramp/hooks/useRampNavigation';
8-
import { useMusdBalance } from '../../../Earn/hooks/useMusdBalance';
8+
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
99
import { useMoneyAccountDeposit } from '../../hooks/useMoneyAccount';
1010
import {
1111
MUSD_CONVERSION_DEFAULT_CHAIN_ID,
@@ -38,8 +38,9 @@ jest.mock('../../../Ramp/hooks/useRampNavigation', () => ({
3838
useRampNavigation: jest.fn(),
3939
}));
4040

41-
jest.mock('../../../Earn/hooks/useMusdBalance', () => ({
42-
useMusdBalance: jest.fn(),
41+
jest.mock('../../hooks/useMoneyAccountBalance', () => ({
42+
__esModule: true,
43+
default: jest.fn(),
4344
}));
4445

4546
jest.mock('../../hooks/useMoneyAccount', () => ({
@@ -86,8 +87,8 @@ describe('MoneyAddMoneySheet', () => {
8687
(useRampNavigation as jest.Mock).mockReturnValue({
8788
goToBuy: mockGoToBuy,
8889
});
89-
(useMusdBalance as jest.Mock).mockReturnValue({
90-
fiatBalanceAggregatedFormatted: '$1,203.89',
90+
(useMoneyAccountBalance as jest.Mock).mockReturnValue({
91+
totalFiatFormatted: '$1,203.89',
9192
});
9293
(useMoneyAccountDeposit as jest.Mock).mockReturnValue({
9394
initiateDeposit: mockInitiateDeposit,
@@ -110,17 +111,17 @@ describe('MoneyAddMoneySheet', () => {
110111
});
111112

112113
it('preserves the locale fiat prefix in the Move mUSD row', () => {
113-
(useMusdBalance as jest.Mock).mockReturnValue({
114-
fiatBalanceAggregatedFormatted: 'CA$1,500.00',
114+
(useMoneyAccountBalance as jest.Mock).mockReturnValue({
115+
totalFiatFormatted: 'CA$1,500.00',
115116
});
116117
const { getByText } = renderWithProvider(<MoneyAddMoneySheet />);
117118

118119
expect(getByText('Move your CA$1,500.00 mUSD')).toBeOnTheScreen();
119120
});
120121

121122
it('falls back to the no-amount copy when the mUSD balance is unavailable', () => {
122-
(useMusdBalance as jest.Mock).mockReturnValue({
123-
fiatBalanceAggregatedFormatted: undefined,
123+
(useMoneyAccountBalance as jest.Mock).mockReturnValue({
124+
totalFiatFormatted: undefined,
124125
});
125126
const { getByText } = renderWithProvider(<MoneyAddMoneySheet />);
126127

app/components/UI/Money/components/MoneyAddMoneySheet/MoneyAddMoneySheet.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
import Tag from '../../../../../component-library/components/Tags/Tag';
1818
import { strings } from '../../../../../../locales/i18n';
1919
import { useStyles } from '../../../../../component-library/hooks';
20-
import { useMusdBalance } from '../../../Earn/hooks/useMusdBalance';
2120
import { useMusdConversionFlowData } from '../../../Earn/hooks/useMusdConversionFlowData';
21+
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
2222
import {
2323
MUSD_CONVERSION_DEFAULT_CHAIN_ID,
2424
MUSD_TOKEN_ASSET_ID_BY_CHAIN,
@@ -40,7 +40,7 @@ const MoneyAddMoneySheet: React.FC = () => {
4040
const navigation = useNavigation();
4141
const { styles } = useStyles(styleSheet, {});
4242

43-
const { fiatBalanceAggregatedFormatted } = useMusdBalance();
43+
const { totalFiatFormatted } = useMoneyAccountBalance();
4444
const { getChainIdForBuyFlow } = useMusdConversionFlowData();
4545
const { goToBuy } = useRampNavigation();
4646
const { initiateDeposit } = useMoneyAccountDeposit();
@@ -94,9 +94,9 @@ const MoneyAddMoneySheet: React.FC = () => {
9494
testID: MoneyAddMoneySheetTestIds.DEPOSIT_FUNDS_OPTION,
9595
},
9696
{
97-
label: fiatBalanceAggregatedFormatted
97+
label: totalFiatFormatted
9898
? strings('money.add_money_sheet.move_musd', {
99-
amount: fiatBalanceAggregatedFormatted,
99+
amount: totalFiatFormatted,
100100
})
101101
: strings('money.add_money_sheet.move_musd_no_amount'),
102102
icon: IconName.Add,

0 commit comments

Comments
 (0)