import React, { useContext, useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { isEqual } from 'lodash'; import { useHistory } from 'react-router-dom'; import PulseLoader from '../../../components/ui/pulse-loader'; import { CUSTODY_ACCOUNT_ROUTE } from '../../../helpers/constants/routes'; import { AlignItems, Display, TextColor, TextAlign, FlexDirection, } from '../../../helpers/constants/design-system'; import { BUILT_IN_NETWORKS } from '../../../../shared/constants/network'; import { I18nContext } from '../../../contexts/i18n'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { getMostRecentOverviewPage } from '../../../ducks/history/history'; import { setProviderType } from '../../../store/actions'; import { mmiActionsFactory } from '../../../store/institutional/institution-background'; import { Label, ButtonLink, Button, BUTTON_SIZES, BUTTON_VARIANT, Box, Text, } from '../../../components/component-library'; import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { getInstitutionalConnectRequests } from '../../../ducks/institutional/institutional'; const ConfirmAddCustodianToken = () => { const t = useContext(I18nContext); const dispatch = useDispatch(); const history = useHistory(); const trackEvent = useContext(MetaMetricsContext); const mmiActions = mmiActionsFactory(); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); const connectRequests = useSelector(getInstitutionalConnectRequests, isEqual); const [showMore, setShowMore] = useState(false); const [isLoading, setIsLoading] = useState(false); const [connectError, setConnectError] = useState(''); const connectRequest = connectRequests ? connectRequests[0] : undefined; useEffect(() => { if (!connectRequest) { history.push(mostRecentOverviewPage); setIsLoading(false); } }, [connectRequest, history, mostRecentOverviewPage]); if (!connectRequest) { return null; } trackEvent({ category: MetaMetricsEventCategory.MMI, event: MetaMetricsEventName.TokenAdded, properties: { actions: 'Custodian RPC request', custodian: connectRequest.custodian, apiUrl: connectRequest.apiUrl, }, }); let custodianLabel = ''; if ( connectRequest.labels && connectRequest.labels.some((label) => label.key === 'service') ) { custodianLabel = connectRequest.labels.find( (label) => label.key === 'service', ).value; } return ( {t('custodianAccount')} {t('mmiAddToken', [connectRequest.origin])} {custodianLabel && ( <> {t('custodian')} )} {t('token')} {showMore && connectRequest?.token ? connectRequest?.token : `...${connectRequest?.token.slice(-9)}`} {!showMore && ( { setShowMore(true); }} > {t('showMore')} )} {connectRequest.apiUrl && ( {t('apiUrl')} {connectRequest.apiUrl} )} {connectError} {isLoading ? ( ) : ( )} ); }; export default ConfirmAddCustodianToken;