2022-03-25 14:55:48 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
import { openModal } from 'soapbox/actions/modals';
|
2022-03-25 15:47:19 -07:00
|
|
|
import { Text, Icon, Stack, HStack } from 'soapbox/components/ui';
|
2022-03-25 14:55:48 -07:00
|
|
|
import { CopyableInput } from 'soapbox/features/forms';
|
|
|
|
|
|
|
|
import { getExplorerUrl } from '../utils/block_explorer';
|
|
|
|
import { getTitle } from '../utils/coin_db';
|
|
|
|
|
|
|
|
import CryptoIcon from './crypto_icon';
|
|
|
|
|
2022-06-12 07:14:46 -07:00
|
|
|
export interface ICryptoAddress {
|
2022-03-25 14:55:48 -07:00
|
|
|
address: string,
|
|
|
|
ticker: string,
|
|
|
|
note?: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
const CryptoAddress: React.FC<ICryptoAddress> = (props): JSX.Element => {
|
|
|
|
const { address, ticker, note } = props;
|
|
|
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const handleModalClick = (e: React.MouseEvent<HTMLElement>): void => {
|
|
|
|
dispatch(openModal('CRYPTO_DONATE', props));
|
|
|
|
e.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
const title = getTitle(ticker);
|
|
|
|
const explorerUrl = getExplorerUrl(ticker, address);
|
|
|
|
|
|
|
|
return (
|
2022-03-25 15:47:19 -07:00
|
|
|
<Stack>
|
|
|
|
<HStack alignItems='center' className='mb-1'>
|
2022-03-25 14:55:48 -07:00
|
|
|
<CryptoIcon
|
2022-03-25 15:47:19 -07:00
|
|
|
className='flex items-start justify-center w-6 mr-2.5'
|
2022-03-25 14:55:48 -07:00
|
|
|
ticker={ticker}
|
|
|
|
title={title}
|
|
|
|
/>
|
2022-03-25 15:47:19 -07:00
|
|
|
|
|
|
|
<Text weight='bold'>{title || ticker.toUpperCase()}</Text>
|
|
|
|
|
|
|
|
<HStack alignItems='center' className='ml-auto'>
|
|
|
|
<a className='text-gray-500 ml-1' href='#' onClick={handleModalClick}>
|
2022-07-09 09:20:02 -07:00
|
|
|
<Icon src={require('@tabler/icons/qrcode.svg')} size={20} />
|
2022-03-25 14:55:48 -07:00
|
|
|
</a>
|
2022-03-25 15:47:19 -07:00
|
|
|
|
|
|
|
{explorerUrl && (
|
|
|
|
<a className='text-gray-500 ml-1' href={explorerUrl} target='_blank'>
|
2022-07-09 09:20:02 -07:00
|
|
|
<Icon src={require('@tabler/icons/external-link.svg')} size={20} />
|
2022-03-25 15:47:19 -07:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</HStack>
|
|
|
|
</HStack>
|
|
|
|
|
|
|
|
{note && (
|
|
|
|
<Text>{note}</Text>
|
|
|
|
)}
|
|
|
|
|
2022-03-25 14:55:48 -07:00
|
|
|
<div className='crypto-address__address simple_form'>
|
|
|
|
<CopyableInput value={address} />
|
|
|
|
</div>
|
2022-03-25 15:47:19 -07:00
|
|
|
</Stack>
|
2022-03-25 14:55:48 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CryptoAddress;
|