Skip to content

Commit 05613a5

Browse files
committed
fix(money): show projected 1-year balance in USD (MUSD-1173)
1 parent 9f499fb commit 05613a5

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import { fireEvent, render } from '@testing-library/react-native';
3-
import BigNumber from 'bignumber.js';
43
import { BalanceProjection } from './BalanceProjection';
54
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
6-
import useFiatFormatter from '../../../SimulationDetails/FiatDisplay/useFiatFormatter';
75
import { strings } from '../../../../../../locales/i18n';
86
import {
97
MONEY_TOOLTIP_NAMES,
@@ -12,7 +10,6 @@ import {
1210
import Routes from '../../../../../constants/navigation/Routes';
1311

1412
jest.mock('../../hooks/useMoneyAccountBalance');
15-
jest.mock('../../../SimulationDetails/FiatDisplay/useFiatFormatter');
1613

1714
const mockTrackTooltipClicked = jest.fn();
1815

@@ -35,7 +32,6 @@ jest.mock('@react-navigation/native', () => {
3532
});
3633

3734
const useMoneyAccountBalanceMock = jest.mocked(useMoneyAccountBalance);
38-
const useFiatFormatterMock = jest.mocked(useFiatFormatter);
3935

4036
const ONE_YEAR_LABEL = strings('confirm.custom_amount.projected_balance', {
4137
projectedYears: 1,
@@ -58,13 +54,8 @@ function mockBalance({
5854
}
5955

6056
describe('BalanceProjection', () => {
61-
const formatFiat = jest.fn(
62-
(value: BigNumber) => `$${value.toFixed(2, BigNumber.ROUND_HALF_UP)}`,
63-
);
64-
6557
beforeEach(() => {
6658
jest.clearAllMocks();
67-
useFiatFormatterMock.mockReturnValue(formatFiat);
6859
});
6960

7061
it('renders label and projected balance for $1,000 at apyDecimal 0.04 over 1 year (~$1,040.00)', () => {
@@ -76,7 +67,7 @@ describe('BalanceProjection', () => {
7667

7768
expect(getByTestId('balance-projection')).toBeOnTheScreen();
7869
expect(getByText(ONE_YEAR_LABEL, { exact: false })).toBeOnTheScreen();
79-
expect(getByText('$1040.00')).toBeOnTheScreen();
70+
expect(getByText('$1,040.00')).toBeOnTheScreen();
8071
});
8172

8273
it('compounds the projection over multiple years', () => {
@@ -86,7 +77,7 @@ describe('BalanceProjection', () => {
8677
<BalanceProjection amountFiat="1000" projectedYears={5} />,
8778
);
8879

89-
expect(getByText('$1216.65')).toBeOnTheScreen();
80+
expect(getByText('$1,216.65')).toBeOnTheScreen();
9081
});
9182

9283
it('renders the APY pitch when amountFiat is "0"', () => {
@@ -303,14 +294,14 @@ describe('BalanceProjection', () => {
303294
expect(queryByTestId('balance-projection-apy-pitch')).toBeNull();
304295
});
305296

306-
it('passes a BigNumber to the fiat formatter when projecting', () => {
307-
mockBalance({ apyDecimal: 0.04, apyPercent: 4 });
297+
it('renders the projected balance in dollars regardless of the preferred currency', () => {
298+
mockBalance({ apyDecimal: 0.05, apyPercent: 5 });
308299

309-
render(<BalanceProjection amountFiat="1000" projectedYears={1} />);
300+
const { getByText, queryByText } = render(
301+
<BalanceProjection amountFiat="100" projectedYears={1} />,
302+
);
310303

311-
expect(formatFiat).toHaveBeenCalledTimes(1);
312-
const passed = formatFiat.mock.calls[0][0];
313-
expect(BigNumber.isBigNumber(passed)).toBe(true);
314-
expect(passed.toFixed(2)).toBe('1040.00');
304+
expect(getByText('$105.00')).toBeOnTheScreen();
305+
expect(queryByText(//)).toBeNull();
315306
});
316307
});

app/components/UI/Money/components/BalanceProjection/BalanceProjection.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
TextVariant,
1717
} from '@metamask/design-system-react-native';
1818
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
19-
import useFiatFormatter from '../../../SimulationDetails/FiatDisplay/useFiatFormatter';
2019
import { strings } from '../../../../../../locales/i18n';
2120
import { Skeleton } from '../../../../../component-library/components-temp/Skeleton';
2221
import { isPositiveNumberOrZero } from '../../utils/number';
22+
import { moneyFormatUsd } from '../../utils/moneyFormatFiat';
2323
import { useMoneyAnalytics } from '../../hooks/useMoneyAnalytics';
2424
import {
2525
MONEY_TOOLTIP_NAMES,
@@ -39,7 +39,6 @@ export function BalanceProjection({
3939
}: BalanceProjectionProps) {
4040
const navigation = useNavigation();
4141
const { vaultApyQuery, apyDecimal, apyPercent } = useMoneyAccountBalance();
42-
const formatFiat = useFiatFormatter();
4342
const { trackTooltipClicked } = useMoneyAnalytics({
4443
screen_name: SCREEN_NAMES.MONEY_DEPOSIT,
4544
});
@@ -112,7 +111,7 @@ export function BalanceProjection({
112111
projectedYears,
113112
})}{' '}
114113
<Text variant={TextVariant.BodyMd} color={TextColor.SuccessDefault}>
115-
{formatFiat(projected)}
114+
{moneyFormatUsd(projected)}
116115
</Text>
117116
</Text>
118117
<ButtonIcon

0 commit comments

Comments
 (0)