import * as React from 'react'; import styled from 'styled-components'; import { getCurrencyPreSymbol, formatPriceDisplay, formatAmount } from '../../utils/cashtab-helpers'; import colors from '../../styles/colors'; import CashtabBase from '../../hoc/CashtabBase'; import type { ButtonStates, CashtabBaseProps } from '../../hoc/CashtabBase'; import PriceDisplay from '../PriceDisplay'; import Button from '../../atoms/Button'; import ButtonQR from '../../atoms/ButtonQR'; import Small from '../../atoms/Small'; import Text from '../../atoms/Text'; const Outer = styled.div` display: grid; grid-template-columns: max-content; `; const Wrapper = styled('div')<{ hasBorder?: boolean }>` display: grid; grid-gap: 5px; font-family: sans-serif; grid-template-columns: max-content; grid-template-rows: max-content max-content max-content; color: ${colors.fg500}; padding: 6px; border: ${props => (props.hasBorder ? `1px dashed ${colors.brand700}` : 'none')}; border-radius: 4px; `; // Cashtab Button Props type CashtabButtonProps = CashtabBaseProps & { text?: string; showAmount?: boolean; showBorder?: boolean; showQR?: boolean; coinSymbol: string; coinDecimals?: number; coinName?: string; handleClick: Function; step: ButtonStates; }; class CashtabButton extends React.PureComponent { static defaultProps = { showAmount: true, showBorder: false }; render() { const { to, step, handleClick, currency, price, coinType, coinSymbol, coinDecimals, coinName, amount, showAmount, text, showBorder, showQR } = this.props; // buttonPriceDisplay if no price, or if a bip70 invoice is set from a server without supported websocket updates let buttonPriceDisplay = Cashtab Pay; // buttonPriceDisplay of price set in props and no invoice is set if (price) { buttonPriceDisplay = ( {getCurrencyPreSymbol(currency)} {formatPriceDisplay(price)} {currency} ); } let determinedShowAmount = ( ); if (!showAmount) { determinedShowAmount = ; } return ( {text} {showQR ? ( {buttonPriceDisplay} ) : ( )} {determinedShowAmount} ); } } export type { CashtabButtonProps }; export default CashtabBase(CashtabButton);