import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { NETWORK_TO_NAME_MAP, BUYABLE_CHAINS_MAP, } from '../../../../../shared/constants/network'; import Button from '../../../ui/button'; import LogoMoonPay from '../../../ui/logo/logo-moonpay'; import LogoWyre from '../../../ui/logo/logo-wyre'; import LogoTransak from '../../../ui/logo/logo-transak'; import LogoDepositEth from '../../../ui/logo/logo-deposit-eth'; export default class DepositEtherModal extends Component { static contextTypes = { t: PropTypes.func, trackEvent: PropTypes.func.isRequired, }; static propTypes = { chainId: PropTypes.string.isRequired, isTestnet: PropTypes.bool.isRequired, isMainnet: PropTypes.bool.isRequired, isBuyableTransakChain: PropTypes.bool.isRequired, isBuyableMoonPayChain: PropTypes.bool.isRequired, toWyre: PropTypes.func.isRequired, toTransak: PropTypes.func.isRequired, toMoonPay: PropTypes.func.isRequired, address: PropTypes.string.isRequired, toFaucet: PropTypes.func.isRequired, hideWarning: PropTypes.func.isRequired, hideModal: PropTypes.func.isRequired, showAccountDetailModal: PropTypes.func.isRequired, }; goToAccountDetailsModal = () => { this.props.hideWarning(); this.props.hideModal(); this.props.showAccountDetailModal(); }; renderRow({ logo, title, text, buttonLabel, onButtonClick, hide, className, hideButton, hideTitle, onBackClick, showBackButton, }) { if (hide) { return null; } return (
{onBackClick && showBackButton && (
)}
{logo}
{!hideTitle && (
{title}
)}
{text}
{!hideButton && (
)}
); } render() { const { chainId, toWyre, toTransak, toMoonPay, address, toFaucet, isTestnet, isMainnet, isBuyableTransakChain, isBuyableMoonPayChain, } = this.props; const { t } = this.context; const networkName = NETWORK_TO_NAME_MAP[chainId]; const symbol = BUYABLE_CHAINS_MAP[chainId].nativeCurrency; return (
{t('depositCrypto', [symbol])}
{t('needCryptoInWallet', [symbol])}
{ this.props.hideWarning(); this.props.hideModal(); }} />
{this.renderRow({ logo: , title: t('buyCryptoWithTransak', [symbol]), text: t('buyCryptoWithTransakDescription', [symbol]), buttonLabel: t('continueToTransak'), onButtonClick: () => { this.context.trackEvent({ category: 'Accounts', event: 'Click buy Ether via Transak', properties: { action: 'Deposit Ether', legacy_event: true, }, }); toTransak(address, chainId); }, hide: !isBuyableTransakChain, })} {this.renderRow({ logo: , title: t('buyCryptoWithMoonPay', [symbol]), text: t('buyCryptoWithMoonPayDescription', [symbol]), buttonLabel: t('continueToMoonPay'), onButtonClick: () => { this.context.metricsEvent({ eventOpts: { category: 'Accounts', action: 'Deposit tokens', name: 'Click buy tokens via MoonPay', }, }); toMoonPay(address, chainId); }, hide: !isBuyableMoonPayChain, })} {this.renderRow({ logo: , title: t('buyWithWyre'), text: t('buyWithWyreDescription'), buttonLabel: t('continueToWyre'), onButtonClick: () => { this.context.metricsEvent({ eventOpts: { category: 'Accounts', action: 'Deposit Ether', name: 'Click buy Ether via Wyre', }, }); toWyre(address); }, hide: !isMainnet, })} {this.renderRow({ logo: ( ), title: t('directDepositCrypto', [symbol]), text: t('directDepositCryptoExplainer', [symbol]), buttonLabel: t('viewAccount'), onButtonClick: () => this.goToAccountDetailsModal(), })} {networkName && this.renderRow({ logo: , title: t('testFaucet'), text: t('getEtherFromFaucet', [networkName]), buttonLabel: t('getEther'), onButtonClick: () => toFaucet(chainId), hide: !isTestnet, })}
); } }