import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { FormattedMessage } from 'react-intl'; import Icon from 'soapbox/components/icon'; import blockExplorers from '../utils/block_explorers.json'; import CoinDB from '../utils/coin_db'; import { getCoinIcon } from '../utils/coin_icons'; import { openModal } from 'soapbox/actions/modal'; const getExplorerUrl = (ticker, address) => { const template = blockExplorers[ticker]; if (!template) return false; return template.replace('{address}', address); }; export default @connect() class CryptoAddress extends ImmutablePureComponent { static propTypes = { address: PropTypes.string.isRequired, ticker: PropTypes.string.isRequired, note: PropTypes.string, } setInputRef = c => { this.input = c; } handleCopyClick = e => { if (!this.input) return; this.input.select(); this.input.setSelectionRange(0, 99999); document.execCommand('copy'); } handleModalClick = e => { this.props.dispatch(openModal('CRYPTO_DONATE', this.props)); e.preventDefault(); } render() { const { address, ticker, note } = this.props; const title = CoinDB.getIn([ticker, 'name']); const explorerUrl = getExplorerUrl(ticker, address); return (
{title}
{title}
{note &&
{note}
}
); } }