-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: [MUSD-816] show transfers in money account activity #30537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { StyleSheet } from 'react-native'; | ||
| import { Theme } from '../../../../../util/theme/models'; | ||
|
|
||
| const styleSheet = (_params: { theme: Theme }) => | ||
| StyleSheet.create({ | ||
| container: { | ||
| paddingInline: 16, | ||
| }, | ||
| hero: { | ||
| marginVertical: 12, | ||
| }, | ||
| }); | ||
|
|
||
| export default styleSheet; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import React from 'react'; | ||
| import { | ||
| type TransactionMeta, | ||
| TransactionStatus, | ||
| TransactionType, | ||
| CHAIN_IDS, | ||
| } from '@metamask/transaction-controller'; | ||
| import { merge } from 'lodash'; | ||
| import renderWithProvider from '../../../../../util/test/renderWithProvider'; | ||
| import { useTransactionDetails } from '../../../../Views/confirmations/hooks/activity/useTransactionDetails'; | ||
| import { otherControllersMock } from '../../../../Views/confirmations/__mocks__/controllers/other-controllers-mock'; | ||
| import { MUSD_TOKEN_ADDRESS } from '../../../Earn/constants/musd'; | ||
| import { MoneyReceivedDetails } from './MoneyReceivedDetails'; | ||
|
|
||
| jest.mock( | ||
| '../../../../Views/confirmations/hooks/activity/useTransactionDetails', | ||
| ); | ||
| jest.mock( | ||
| '../../../../Views/confirmations/components/activity/transaction-details-status-row', | ||
| () => ({ | ||
| TransactionDetailsStatusRow: jest.fn(() => null), | ||
| }), | ||
| ); | ||
| jest.mock( | ||
| '../../../../Views/confirmations/components/activity/transaction-details-date-row', | ||
| () => ({ | ||
| TransactionDetailsDateRow: jest.fn(() => null), | ||
| }), | ||
| ); | ||
| jest.mock('../../../Name/Name', () => { | ||
| const { Text } = jest.requireActual('react-native'); | ||
| // eslint-disable-next-line react/display-name | ||
| return ({ value }: { value: string }) => ( | ||
| <Text testID="name-mock">{value}</Text> | ||
| ); | ||
| }); | ||
| jest.mock('../../../../Views/confirmations/components/token-icon', () => ({ | ||
| TokenIcon: () => null, | ||
| TokenIconVariant: { Row: 'row' }, | ||
| })); | ||
|
|
||
| const FROM_MOCK = '0x1111111111111111111111111111111111111111'; | ||
| const RECIPIENT_MOCK = '0x2222222222222222222222222222222222222222'; | ||
|
|
||
| const baseTransactionMeta = { | ||
| id: 'tx-1', | ||
| chainId: CHAIN_IDS.MONAD, | ||
| status: TransactionStatus.confirmed, | ||
| time: Date.UTC(2026, 4, 21, 14, 16), | ||
| type: TransactionType.incoming, | ||
| txParams: { | ||
| from: FROM_MOCK, | ||
| to: RECIPIENT_MOCK, | ||
| }, | ||
| transferInformation: { | ||
| contractAddress: MUSD_TOKEN_ADDRESS, | ||
| decimals: 6, | ||
| symbol: 'mUSD', | ||
| amount: '500000', | ||
| }, | ||
| } as unknown as TransactionMeta; | ||
|
|
||
| function render(overrides: Partial<TransactionMeta> = {}) { | ||
| const useTransactionDetailsMock = jest.mocked(useTransactionDetails); | ||
| useTransactionDetailsMock.mockReturnValue({ | ||
| transactionMeta: { | ||
| ...baseTransactionMeta, | ||
| ...overrides, | ||
| } as TransactionMeta, | ||
| }); | ||
| return renderWithProvider(<MoneyReceivedDetails />, { | ||
| state: merge({}, otherControllersMock), | ||
| }); | ||
| } | ||
|
|
||
| describe('MoneyReceivedDetails', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders the From row with the sender address for an incoming transfer', () => { | ||
| const { getByTestId } = render(); | ||
| expect(getByTestId('name-mock').props.children).toBe(FROM_MOCK); | ||
| }); | ||
|
|
||
| it('renders the token received label with the mUSD symbol', () => { | ||
| const { getByText } = render(); | ||
| expect(getByText('Token received')).toBeTruthy(); | ||
| expect(getByText('mUSD')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders the fiat hero when buildMoneyActivityFiatLine returns a value', () => { | ||
| const { queryByTestId } = render(); | ||
| expect(queryByTestId('money-received-hero')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('omits the From row when txParams.from is missing', () => { | ||
| const { queryByTestId, queryByText } = render({ | ||
| txParams: { to: RECIPIENT_MOCK } as TransactionMeta['txParams'], | ||
| }); | ||
| expect(queryByText('From')).toBeNull(); | ||
| expect(queryByTestId('name-mock')).toBeNull(); | ||
| }); | ||
|
|
||
| it('omits the token received row when no mUSD transfer meta can be resolved', () => { | ||
| const { queryByText } = render({ | ||
| transferInformation: undefined, | ||
| txParams: { | ||
| from: FROM_MOCK, | ||
| to: RECIPIENT_MOCK, | ||
| data: '0x', | ||
| } as TransactionMeta['txParams'], | ||
| }); | ||
| expect(queryByText('Token received')).toBeNull(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import React from 'react'; | ||
| import { ScrollView } from 'react-native'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ScrollView from react-native inside BottomSheet breaks scrollingMedium Severity
Additional Locations (1)Triggered by learned rule: ScrollView inside BottomSheet must be imported from react-native-gesture-handler Reviewed by Cursor Bugbot for commit 7e966e7. Configure here. |
||
| import { useSelector } from 'react-redux'; | ||
| import { type Hex } from '@metamask/utils'; | ||
| import { Text, TextVariant } from '@metamask/design-system-react-native'; | ||
| import { strings } from '../../../../../../locales/i18n'; | ||
| import { useStyles } from '../../../../../component-library/hooks'; | ||
| import { | ||
| selectCurrencyRates, | ||
| selectCurrentCurrency, | ||
| } from '../../../../../selectors/currencyRateController'; | ||
| import { selectTokenMarketData } from '../../../../../selectors/tokenRatesController'; | ||
| import { Box } from '../../../Box/Box'; | ||
| import { AlignItems, FlexDirection } from '../../../Box/box.types'; | ||
| import Name from '../../../Name/Name'; | ||
| import { NameType } from '../../../Name/Name.types'; | ||
| import { TransactionDetailDivider } from '../../../../Views/confirmations/components/activity/transaction-detail-divider/transaction-detail-divider'; | ||
| import { TransactionDetailsDateRow } from '../../../../Views/confirmations/components/activity/transaction-details-date-row'; | ||
| import { TransactionDetailsRow } from '../../../../Views/confirmations/components/activity/transaction-details-row/transaction-details-row'; | ||
| import { TransactionDetailsStatusRow } from '../../../../Views/confirmations/components/activity/transaction-details-status-row'; | ||
| import { | ||
| TokenIcon, | ||
| TokenIconVariant, | ||
| } from '../../../../Views/confirmations/components/token-icon'; | ||
| import { useTransactionDetails } from '../../../../Views/confirmations/hooks/activity/useTransactionDetails'; | ||
| import { resolveMusdTransferMeta } from '../../constants/activityStyles'; | ||
| import { buildMoneyActivityFiatLine } from '../../utils/moneyActivityFiat'; | ||
| import styleSheet from './MoneyReceivedDetails.styles'; | ||
|
|
||
| export function MoneyReceivedDetails() { | ||
| const { styles } = useStyles(styleSheet, {}); | ||
| const { transactionMeta } = useTransactionDetails(); | ||
| const currentCurrency = useSelector(selectCurrentCurrency); | ||
| const currencyRates = useSelector(selectCurrencyRates); | ||
| const tokenMarketData = useSelector(selectTokenMarketData); | ||
|
|
||
| const fiatAmount = buildMoneyActivityFiatLine( | ||
| transactionMeta, | ||
| currencyRates, | ||
| currentCurrency, | ||
| tokenMarketData, | ||
| ); | ||
| const tokenMeta = resolveMusdTransferMeta(transactionMeta); | ||
| const from = transactionMeta.txParams?.from; | ||
| const chainId = transactionMeta.chainId as Hex; | ||
|
|
||
| return ( | ||
| <ScrollView> | ||
| <Box style={styles.container} gap={12}> | ||
| {fiatAmount ? ( | ||
| <Box | ||
| testID="money-received-hero" | ||
| alignItems={AlignItems.center} | ||
| gap={12} | ||
| style={styles.hero} | ||
| > | ||
| <Text variant={TextVariant.DisplayLg}>{fiatAmount}</Text> | ||
| </Box> | ||
| ) : null} | ||
| <TransactionDetailsStatusRow /> | ||
| <TransactionDetailsDateRow /> | ||
| <TransactionDetailDivider /> | ||
| {from ? ( | ||
| <TransactionDetailsRow | ||
| label={strings('transaction_details.label.from')} | ||
| > | ||
| <Name | ||
| type={NameType.EthereumAddress} | ||
| value={from} | ||
| variation={chainId} | ||
| /> | ||
| </TransactionDetailsRow> | ||
| ) : null} | ||
| {tokenMeta ? ( | ||
| <TransactionDetailsRow | ||
| label={strings('transaction_details.label.token_received')} | ||
| > | ||
| <Box | ||
| flexDirection={FlexDirection.Row} | ||
| gap={6} | ||
| alignItems={AlignItems.center} | ||
| > | ||
| <TokenIcon | ||
| chainId={chainId} | ||
| address={tokenMeta.contractAddress as Hex} | ||
| symbol={tokenMeta.symbol} | ||
| variant={TokenIconVariant.Row} | ||
| /> | ||
| <Text>{tokenMeta.symbol}</Text> | ||
| </Box> | ||
| </TransactionDetailsRow> | ||
| ) : null} | ||
| </Box> | ||
| </ScrollView> | ||
| ); | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests use toBeTruthy instead of toBeOnTheScreen
Low Severity
Several new test assertions use
toBeTruthy()to verify element presence (e.g.,expect(getByText('Token received')).toBeTruthy()andexpect(getByTestId('money-received-details')).toBeTruthy()). The unit testing guidelines mandatetoBeOnTheScreen()for element presence checks —toBeTruthy()is listed as a banned weak matcher for this purpose.Additional Locations (1)
app/components/UI/Money/components/MoneyTransactionDetailsSheet/MoneyTransactionDetailsSheet.test.tsx#L69-L81Triggered by project rule: Unit Testing Guidelines
Reviewed by Cursor Bugbot for commit 7e966e7. Configure here.