import { utils as coinUtils } from '@lamassu/coins' import { makeStyles, Box } from '@material-ui/core' import BigNumber from 'bignumber.js' import classnames from 'classnames' import * as R from 'ramda' import React from 'react' import DataTable from 'src/components/tables/DataTable' import { H3, H4, Label1, Label2, P } from 'src/components/typography' import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg' import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg' import { ifNotNull } from 'src/utils/nullCheck' import { formatDate } from 'src/utils/timezones' import CopyToClipboard from '../../Transactions/CopyToClipboard' import mainStyles from '../CustomersList.styles' const useStyles = makeStyles(mainStyles) const TransactionsList = ({ customer, data, loading, locale }) => { const classes = useStyles() const LastTxIcon = customer.lastTxClass === 'cashOut' ? TxOutIcon : TxInIcon const hasData = !(R.isEmpty(data) || R.isNil(data)) const timezone = locale.timezone const tableSpacingClasses = { [classes.titleAndButtonsContainer]: loading || (!loading && !hasData), [classes.txTableSpacing]: !loading && hasData } const summaryElements = [ { header: 'Transactions', size: 127, value: ifNotNull( customer.totalTxs, `${Number.parseInt(customer.totalTxs)}` ) }, { header: 'Transaction volume', size: 167, value: ifNotNull( customer.totalSpent, `${Number.parseFloat(customer.totalSpent)} ${customer.lastTxFiatCode}` ) }, { header: 'Last active', size: 142, value: !R.isNil(timezone) && ((customer.lastActive && formatDate(customer.lastActive, timezone, 'yyyy-MM-dd')) ?? '') }, { header: 'Last transaction', size: 198, value: ifNotNull( customer.lastTxFiat, <> {`${Number.parseFloat(customer.lastTxFiat)} ${customer.lastTxFiatCode}`} ) } ] const tableElements = [ { width: 40, view: it => ( <> {it.txClass === 'cashOut' ? ( ) : ( )} ) }, { header: 'Machine', width: 160, view: R.path(['machineName']) }, { header: 'Transaction ID', width: 145, view: it => ( {it.id} ) }, { header: 'Cash', width: 155, textAlign: 'right', view: it => ( <> {`${Number.parseFloat(it.fiat)} `} {it.fiatCode} ) }, { header: 'Crypto', width: 145, textAlign: 'right', view: it => ( <> {`${coinUtils .toUnit(new BigNumber(it.cryptoAtoms), it.cryptoCode) .toFormat(5)} `} {it.cryptoCode} ) }, { header: 'Date', width: 100, view: it => formatDate(it.created, timezone, 'yyyy-MM-dd') }, { header: 'Time (h:m:s)', width: 130, view: it => formatDate(it.created, timezone, 'HH:mm:ss') } ] return ( <>

Transactions

{summaryElements.map(({ size, header }, idx) => ( {header} ))} {summaryElements.map(({ size, value }, idx) => (

{value}

))}
{loading ? (

Loading

) : hasData ? ( '' ) : (

No transactions so far

)}
{hasData && } ) } export default TransactionsList