bigbuffet-rw/app/soapbox/features/crypto_donate/components/crypto_address.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-03-25 14:55:48 -07:00
import React from 'react';
import { useDispatch } from 'react-redux';
import { openModal } from 'soapbox/actions/modals';
import CopyableInput from 'soapbox/components/copyable-input';
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 { getExplorerUrl } from '../utils/block_explorer';
import { getTitle } from '../utils/coin_db';
import CryptoIcon from './crypto_icon';
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}>
<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'>
<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>
)}
<CopyableInput value={address} />
2022-03-25 15:47:19 -07:00
</Stack>
2022-03-25 14:55:48 -07:00
);
};
export default CryptoAddress;