|
| 1 | +import React, { useCallback, useRef } from 'react'; |
| 2 | +import { useNavigation } from '@react-navigation/native'; |
| 3 | +import { |
| 4 | + BottomSheet, |
| 5 | + type BottomSheetRef, |
| 6 | + BottomSheetHeader, |
| 7 | + Text, |
| 8 | + TextVariant, |
| 9 | +} from '@metamask/design-system-react-native'; |
| 10 | +import { |
| 11 | + type TransactionMeta, |
| 12 | + TransactionType, |
| 13 | +} from '@metamask/transaction-controller'; |
| 14 | +import { strings } from '../../../../../../locales/i18n'; |
| 15 | +import { TransactionDetails } from '../../../../Views/confirmations/components/activity/transaction-details/transaction-details'; |
| 16 | +import { useTransactionDetails } from '../../../../Views/confirmations/hooks/activity/useTransactionDetails'; |
| 17 | + |
| 18 | +const TITLE_KEYS: Partial<Record<TransactionType, string>> = { |
| 19 | + [TransactionType.moneyAccountDeposit]: |
| 20 | + 'transaction_details.title.money_account_deposit', |
| 21 | + [TransactionType.moneyAccountWithdraw]: |
| 22 | + 'transaction_details.title.money_account_withdraw', |
| 23 | + [TransactionType.musdConversion]: 'transaction_details.title.musd_conversion', |
| 24 | + [TransactionType.musdClaim]: 'transaction_details.title.musd_claim', |
| 25 | + [TransactionType.perpsDeposit]: 'transaction_details.title.perps_deposit', |
| 26 | + [TransactionType.perpsWithdraw]: 'transaction_details.title.perps_withdraw', |
| 27 | + [TransactionType.predictClaim]: 'transaction_details.title.predict_claim', |
| 28 | + [TransactionType.predictDeposit]: 'transaction_details.title.predict_deposit', |
| 29 | + [TransactionType.predictWithdraw]: |
| 30 | + 'transaction_details.title.predict_withdraw', |
| 31 | +}; |
| 32 | + |
| 33 | +function getTitle(tx: TransactionMeta | undefined): string { |
| 34 | + const type = |
| 35 | + tx?.type === TransactionType.batch |
| 36 | + ? ((tx.nestedTransactions?.find((n) => n.type && n.type in TITLE_KEYS) |
| 37 | + ?.type as TransactionType | undefined) ?? tx.type) |
| 38 | + : tx?.type; |
| 39 | + return strings( |
| 40 | + (type && TITLE_KEYS[type]) ?? 'transaction_details.title.default', |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +const MoneyTransactionDetailsSheet = () => { |
| 45 | + const sheetRef = useRef<BottomSheetRef>(null); |
| 46 | + const navigation = useNavigation(); |
| 47 | + const { transactionMeta } = useTransactionDetails(); |
| 48 | + const title = getTitle(transactionMeta); |
| 49 | + |
| 50 | + const handleClose = useCallback(() => { |
| 51 | + sheetRef.current?.onCloseBottomSheet(); |
| 52 | + }, []); |
| 53 | + |
| 54 | + return ( |
| 55 | + <BottomSheet |
| 56 | + ref={sheetRef} |
| 57 | + isFullscreen |
| 58 | + goBack={navigation.goBack} |
| 59 | + keyboardAvoidingViewEnabled={false} |
| 60 | + > |
| 61 | + <BottomSheetHeader onClose={handleClose}> |
| 62 | + <Text variant={TextVariant.HeadingMd}>{title}</Text> |
| 63 | + </BottomSheetHeader> |
| 64 | + <TransactionDetails /> |
| 65 | + </BottomSheet> |
| 66 | + ); |
| 67 | +}; |
| 68 | + |
| 69 | +export default MoneyTransactionDetailsSheet; |
0 commit comments