import PropTypes from 'prop-types'; import React, { useContext } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { I18nContext } from '../../../contexts/i18n'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { NETWORK_TO_NAME_MAP, BUYABLE_CHAINS_MAP, } from '../../../../shared/constants/network'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; import LogoMoonPay from '../../ui/logo/logo-moonpay'; import LogoWyre from '../../ui/logo/logo-wyre'; import LogoTransak from '../../ui/logo/logo-transak'; import LogoCoinbasePay from '../../ui/logo/logo-coinbasepay'; import LogoDepositEth from '../../ui/logo/logo-deposit-eth'; import Popover from '../../ui/popover'; import { buy, showModal, hideWarning } from '../../../store/actions'; import { getIsTestnet, getCurrentChainId, getSelectedAddress, getIsBuyableTransakChain, getIsBuyableMoonPayChain, getIsBuyableCoinbasePayChain, getIsBuyableCoinbasePayToken, getIsBuyableTransakToken, getIsBuyableMoonpayToken, getIsBuyableWyreToken, } from '../../../selectors/selectors'; import OnRampItem from './on-ramp-item'; const DepositPopover = ({ onClose, token }) => { const isTokenDeposit = Boolean(token); const t = useContext(I18nContext); const trackEvent = useContext(MetaMetricsContext); const dispatch = useDispatch(); const chainId = useSelector(getCurrentChainId); const isTestnet = useSelector(getIsTestnet); const address = useSelector(getSelectedAddress); const isBuyableTransakChain = useSelector(getIsBuyableTransakChain); const isBuyableMoonPayChain = useSelector(getIsBuyableMoonPayChain); const isBuyableWyreChain = false; const isBuyableCoinbasePayChain = useSelector(getIsBuyableCoinbasePayChain); const isTokenBuyableCoinbasePay = useSelector((state) => getIsBuyableCoinbasePayToken(state, token?.symbol), ); const isTokenBuyableTransak = useSelector((state) => getIsBuyableTransakToken(state, token?.symbol), ); const isTokenBuyableMoonpay = useSelector((state) => getIsBuyableMoonpayToken(state, token?.symbol), ); const isTokenBuyableWyre = useSelector((state) => getIsBuyableWyreToken(state, token?.symbol), ); const networkName = NETWORK_TO_NAME_MAP[chainId]; const symbol = token ? token.symbol : BUYABLE_CHAINS_MAP[chainId].nativeCurrency; const showAccountDetailModal = () => { dispatch(showModal({ name: 'ACCOUNT_DETAILS' })); }; const hideWarningMessage = () => { dispatch(hideWarning()); }; const toCoinbasePay = () => { dispatch( buy({ service: 'coinbase', address, chainId, symbol: token?.symbol }), ); }; const toTransak = () => { dispatch( buy({ service: 'transak', address, chainId, symbol: token?.symbol }), ); }; const toMoonPay = () => { dispatch( buy({ service: 'moonpay', address, chainId, symbol: token?.symbol }), ); }; const toWyre = () => { dispatch(buy({ service: 'wyre', address, chainId, symbol: token?.symbol })); }; const toFaucet = () => dispatch(buy({ chainId })); const goToAccountDetailsModal = () => { hideWarningMessage(); showAccountDetailModal(); onClose(); }; return ( ); }; DepositPopover.propTypes = { onClose: PropTypes.func.isRequired, token: PropTypes.shape({ address: PropTypes.string.isRequired, decimals: PropTypes.number, symbol: PropTypes.string, image: PropTypes.string, aggregators: PropTypes.array, isERC721: PropTypes.bool, }), }; export default DepositPopover;