|
| 1 | +import { CHAIN_IDS, TransactionMeta } from '@metamask/transaction-controller'; |
| 2 | +import React from 'react'; |
| 3 | +import { View } from 'react-native'; |
| 4 | +import { useSelector } from 'react-redux'; |
| 5 | +import { strings } from '../../../../../../../locales/i18n'; |
| 6 | +import { AvatarSize } from '../../../../../../component-library/components/Avatars/Avatar'; |
| 7 | +import Badge, { BadgeVariant } from '../../../../../../component-library/components/Badges/Badge'; |
| 8 | +import Text from '../../../../../../component-library/components/Texts/Text'; |
| 9 | +import { useStyles } from '../../../../../../component-library/hooks'; |
| 10 | +import images from '../../../../../../images/image-icons'; |
| 11 | +import { selectSelectedInternalAccountFormattedAddress } from '../../../../../../selectors/accountsController'; |
| 12 | +import Name from '../../../../../UI/Name'; |
| 13 | +import { NameType } from '../../../../../UI/Name/Name.types'; |
| 14 | +import { useTransactionMetadataRequest } from '../../../hooks/useTransactionMetadataRequest'; |
| 15 | +import InfoRow from '../../UI/InfoRow'; |
| 16 | +import InfoRowDivider from '../InfoRowDivider'; |
| 17 | +import styleSheet from './ContractInteractionDetails.styles'; |
| 18 | + |
| 19 | +export enum ContractInteractionDetailsVariant { |
| 20 | + StakingDeposit = 'staking_deposit', |
| 21 | + StakingWithdrawal = 'staking_withdrawal', |
| 22 | + StakingClaim = 'staking_claim', |
| 23 | +} |
| 24 | + |
| 25 | +const ContractInteractionDetails = ( |
| 26 | + { variant }: { variant: ContractInteractionDetailsVariant } |
| 27 | + ) => { |
| 28 | + const transactionMeta = useTransactionMetadataRequest(); |
| 29 | + const { styles } = useStyles(styleSheet, {}); |
| 30 | + const address = useSelector(selectSelectedInternalAccountFormattedAddress); |
| 31 | + |
| 32 | + return ( |
| 33 | + <> |
| 34 | + {variant === ContractInteractionDetailsVariant.StakingDeposit && ( |
| 35 | + <InfoRow |
| 36 | + label={strings('stake.staking_from')} |
| 37 | + > |
| 38 | + <Name |
| 39 | + type={NameType.EthereumAddress} |
| 40 | + value={(transactionMeta as TransactionMeta).txParams.from} |
| 41 | + variation={CHAIN_IDS.MAINNET} |
| 42 | + /> |
| 43 | + </InfoRow> |
| 44 | + )} |
| 45 | + {variant === ContractInteractionDetailsVariant.StakingWithdrawal && ( |
| 46 | + <InfoRow |
| 47 | + label={strings('stake.unstaking_to')} |
| 48 | + > |
| 49 | + <Name |
| 50 | + type={NameType.EthereumAddress} |
| 51 | + value={address as string} |
| 52 | + variation={CHAIN_IDS.MAINNET} |
| 53 | + /> |
| 54 | + </InfoRow> |
| 55 | + )} |
| 56 | + <InfoRow |
| 57 | + label={strings('confirm.label.interacting_with')} |
| 58 | + > |
| 59 | + <Name |
| 60 | + type={NameType.EthereumAddress} |
| 61 | + value={(transactionMeta as TransactionMeta).txParams.to as string} |
| 62 | + variation={CHAIN_IDS.MAINNET} |
| 63 | + /> |
| 64 | + </InfoRow> |
| 65 | + <InfoRowDivider /> |
| 66 | + <InfoRow |
| 67 | + label={strings('confirm.label.network')} |
| 68 | + > |
| 69 | + <View style={styles.networkContainer}> |
| 70 | + <Badge |
| 71 | + size={AvatarSize.Xs} |
| 72 | + imageSource={images.ETHEREUM} |
| 73 | + variant={BadgeVariant.Network} |
| 74 | + isScaled={false} |
| 75 | + /> |
| 76 | + <Text>{' '}</Text> |
| 77 | + <Text>{strings('stake.ethereum_mainnet')}</Text> |
| 78 | + </View> |
| 79 | + </InfoRow> |
| 80 | + </> |
| 81 | + ) |
| 82 | + } |
| 83 | + |
| 84 | +export default ContractInteractionDetails; |
0 commit comments