import React, { useCallback, useContext, useState } from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import log from 'loglevel'; import ActionableMessage from '../../ui/actionable-message'; import Popover from '../../ui/popover'; import Checkbox from '../../ui/check-box'; import { I18nContext } from '../../../contexts/i18n'; import { PageContainerFooter } from '../../ui/page-container'; import { accountsWithSendEtherInfoSelector, getSubjectMetadata, } from '../../../selectors'; import { getAccountByAddress } from '../../../helpers/utils/util'; import { formatMessageParams } from '../../../../shared/modules/siwe'; import { Icon } from '../../component-library/icon/icon'; import { COLORS } from '../../../helpers/constants/design-system'; import Header from './signature-request-siwe-header'; import Message from './signature-request-siwe-message'; export default function SignatureRequestSIWE({ txData, cancelPersonalMessage, signPersonalMessage, }) { const allAccounts = useSelector(accountsWithSendEtherInfoSelector); const subjectMetadata = useSelector(getSubjectMetadata); const { msgParams: { from, origin, siwe: { parsedMessage }, }, } = txData; const fromAccount = getAccountByAddress(allAccounts, from); const targetSubjectMetadata = subjectMetadata[origin]; const t = useContext(I18nContext); const isMatchingAddress = from.toLowerCase() === parsedMessage.address.toLowerCase(); const checkSIWEDomain = () => { let isSIWEDomainValid = false; if (origin) { const { host } = new URL(origin); isSIWEDomainValid = parsedMessage.domain === host; } return isSIWEDomainValid; }; const isSIWEDomainValid = checkSIWEDomain(); const [isShowingDomainWarning, setIsShowingDomainWarning] = useState(false); const [agreeToDomainWarning, setAgreeToDomainWarning] = useState(false); const onSign = useCallback( async (event) => { try { await signPersonalMessage(event); } catch (e) { log.error(e); } }, [signPersonalMessage], ); const onCancel = useCallback( async (event) => { try { await cancelPersonalMessage(event); } catch (e) { log.error(e); } }, [cancelPersonalMessage], ); return (
{t('SIWEDomainInvalidTitle')}
{' '} {t('SIWEDomainInvalidText')} > } iconFillColor="var(--color-error-default)" useIcon withRightButton icon={