/* eslint-disable no-negated-condition */
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { TransactionType } from '../../../../../../shared/constants/transaction';
import { toChecksumHexAddress } from '../../../../../../shared/modules/hexstring-utils';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
import useAddressDetails from '../../../../../hooks/useAddressDetails';
import { getIpfsGateway } from '../../../../../selectors';
import Identicon from '../../../../ui/identicon';
import InfoTooltip from '../../../../ui/info-tooltip';
import NicknamePopovers from '../../../modals/nickname-popovers';
import { ORIGIN_METAMASK } from '../../../../../../shared/constants/app';
import SiteOrigin from '../../../../ui/site-origin';
import { getAssetImageURL } from '../../../../../helpers/utils/util';
const ConfirmPageContainerSummary = (props) => {
const {
action,
titleComponent,
subtitleComponent,
className,
tokenAddress,
toAddress,
nonce,
origin,
image,
transactionType,
} = props;
const [showNicknamePopovers, setShowNicknamePopovers] = useState(false);
const t = useI18nContext();
const ipfsGateway = useSelector(getIpfsGateway);
const contractInitiatedTransactionType = [
TransactionType.contractInteraction,
TransactionType.tokenMethodTransfer,
TransactionType.tokenMethodTransferFrom,
TransactionType.tokenMethodSafeTransferFrom,
];
const isContractTypeTransaction =
contractInitiatedTransactionType.includes(transactionType);
let contractAddress;
if (isContractTypeTransaction) {
// If the transaction is TOKEN_METHOD_TRANSFER or TOKEN_METHOD_TRANSFER_FROM
// the contract address is passed down as tokenAddress, if it is anyother
// type of contract interaction it is passed as toAddress
contractAddress =
transactionType === TransactionType.tokenMethodTransfer ||
transactionType === TransactionType.tokenMethodTransferFrom ||
transactionType === TransactionType.tokenMethodSafeTransferFrom ||
transactionType === TransactionType.tokenMethodSetApprovalForAll
? tokenAddress
: toAddress;
}
const { toName, isTrusted } = useAddressDetails(contractAddress);
const checksummedAddress = toChecksumHexAddress(contractAddress);
const renderImage = () => {
const imagePath = getAssetImageURL(image, ipfsGateway);
if (image) {
return (
);
} else if (contractAddress) {
return (