2018-12-12 13:14:58 -08:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import dateFns from 'date-fns';
|
|
|
|
|
|
|
|
import SentIcon from '../assets/images/transaction_sent_icon.svg';
|
|
|
|
import ReceivedIcon from '../assets/images/transaction_received_icon.svg';
|
|
|
|
|
|
|
|
import { RowComponent } from './row';
|
|
|
|
import { ColumnComponent } from './column';
|
|
|
|
import { TextComponent } from './text';
|
|
|
|
|
|
|
|
import theme from '../theme';
|
|
|
|
|
|
|
|
import formatNumber from '../utils/formatNumber';
|
|
|
|
|
|
|
|
const Wrapper = styled(RowComponent)`
|
|
|
|
background-color: ${props => props.theme.colors.cardBackgroundColor};
|
2018-12-13 12:19:37 -08:00
|
|
|
padding: 15px 17px;
|
2018-12-12 13:14:58 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Icon = styled.img`
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TransactionTypeLabel = styled(TextComponent)`
|
|
|
|
color: ${props => (props.isReceived ? props.theme.colors.transactionReceived : props.theme.colors.transactionSent)};
|
|
|
|
text-transform: capitalize;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TransactionTime = styled(TextComponent)`
|
|
|
|
color: ${props => props.theme.colors.inactiveItem};
|
|
|
|
`;
|
|
|
|
|
2018-12-12 13:19:45 -08:00
|
|
|
const TransactionColumn = styled(ColumnComponent)`
|
2018-12-12 13:14:58 -08:00
|
|
|
margin-left: 10px;
|
2018-12-12 13:19:45 -08:00
|
|
|
margin-right: 80px;
|
2018-12-13 09:19:53 -08:00
|
|
|
min-width: 60px;
|
2018-12-12 13:14:58 -08:00
|
|
|
`;
|
|
|
|
|
2018-12-13 09:19:53 -08:00
|
|
|
export type Transaction = {
|
2018-12-13 12:19:37 -08:00
|
|
|
type: 'send' | 'receive',
|
2018-12-12 13:14:58 -08:00
|
|
|
date: string,
|
|
|
|
address: string,
|
|
|
|
amount: number,
|
2018-12-13 13:37:15 -08:00
|
|
|
zecPrice: number,
|
2018-12-12 13:14:58 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* eslint-disable-next-line max-len */
|
|
|
|
const truncateAddress = (address: string) => `${address.substr(0, 20)}...${address.substr(address.length - 10, address.length)}`;
|
|
|
|
|
|
|
|
export const TransactionItemComponent = ({
|
2018-12-13 13:37:15 -08:00
|
|
|
type, date, address, amount, zecPrice,
|
2018-12-13 09:19:53 -08:00
|
|
|
}: Transaction) => {
|
2018-12-13 12:19:37 -08:00
|
|
|
const isReceived = type === 'receive';
|
2018-12-12 13:14:58 -08:00
|
|
|
return (
|
|
|
|
<Wrapper alignItems='center' justifyContent='space-between'>
|
2018-12-13 09:19:53 -08:00
|
|
|
<RowComponent alignItems='center'>
|
2018-12-12 13:19:45 -08:00
|
|
|
<RowComponent alignItems='center'>
|
|
|
|
<Icon src={isReceived ? ReceivedIcon : SentIcon} alt='Transaction Type Icon' />
|
|
|
|
<TransactionColumn>
|
|
|
|
<TransactionTypeLabel isReceived={isReceived} value={type} />
|
2018-12-13 12:19:37 -08:00
|
|
|
<TransactionTime value={dateFns.format(new Date(date), 'HH:mm A')} />
|
2018-12-12 13:19:45 -08:00
|
|
|
</TransactionColumn>
|
|
|
|
</RowComponent>
|
|
|
|
<TextComponent value={truncateAddress(address)} align='left' />
|
2018-12-12 13:14:58 -08:00
|
|
|
</RowComponent>
|
2018-12-13 12:19:37 -08:00
|
|
|
<ColumnComponent alignItems='flex-end'>
|
2018-12-12 13:14:58 -08:00
|
|
|
<TextComponent
|
2018-12-13 12:19:37 -08:00
|
|
|
value={formatNumber({ value: amount, append: `${isReceived ? '+' : '-'}ZEC ` })}
|
2018-12-12 13:14:58 -08:00
|
|
|
color={isReceived ? theme.colors.transactionReceived : theme.colors.transactionSent}
|
|
|
|
/>
|
|
|
|
<TextComponent
|
2018-12-13 13:37:15 -08:00
|
|
|
value={formatNumber({ value: amount * zecPrice, append: `${isReceived ? '+' : '-'}USD $` })}
|
2018-12-12 13:14:58 -08:00
|
|
|
color={theme.colors.inactiveItem}
|
|
|
|
/>
|
|
|
|
</ColumnComponent>
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
};
|