2018-12-19 09:20:56 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2018-12-19 09:20:56 -08:00
|
|
|
import React from 'react';
|
2019-02-16 19:34:12 -08:00
|
|
|
import styled, { withTheme } from 'styled-components';
|
2018-12-19 09:20:56 -08:00
|
|
|
import dateFns from 'date-fns';
|
2019-01-29 14:18:06 -08:00
|
|
|
import { BigNumber } from 'bignumber.js';
|
2018-12-19 09:20:56 -08:00
|
|
|
|
2019-01-29 16:28:10 -08:00
|
|
|
import { ZCASH_EXPLORER_BASE_URL } from '../constants/explorer';
|
2019-02-16 19:34:12 -08:00
|
|
|
import { DARK } from '../constants/themes';
|
2019-01-29 16:28:10 -08:00
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
import SentIconDark from '../assets/images/transaction_sent_icon_dark.svg';
|
|
|
|
import ReceivedIconDark from '../assets/images/transaction_received_icon_dark.svg';
|
|
|
|
import SentIconLight from '../assets/images/transaction_sent_icon_light.svg';
|
|
|
|
import ReceivedIconLight from '../assets/images/transaction_received_icon_light.svg';
|
2018-12-19 09:20:56 -08:00
|
|
|
import CloseIcon from '../assets/images/close_icon.svg';
|
|
|
|
|
|
|
|
import { TextComponent } from './text';
|
|
|
|
import { RowComponent } from './row';
|
|
|
|
import { ColumnComponent } from './column';
|
|
|
|
|
2019-01-29 07:36:13 -08:00
|
|
|
import { formatNumber } from '../utils/format-number';
|
2019-01-29 16:28:10 -08:00
|
|
|
import { openExternal } from '../utils/open-external';
|
2018-12-19 09:20:56 -08:00
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
2019-01-10 19:30:46 -08:00
|
|
|
width: 460px;
|
2019-02-16 19:34:12 -08:00
|
|
|
background-color: ${props => props.theme.colors.transactionDetailsBg};
|
2018-12-19 09:20:56 -08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
border-radius: 6px;
|
2019-02-16 19:34:12 -08:00
|
|
|
box-shadow: ${props => props.theme.colors.transactionDetailsShadow};
|
2019-01-10 19:30:46 -08:00
|
|
|
position: relative;
|
2018-12-19 09:20:56 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const TitleWrapper = styled.div`
|
|
|
|
margin-top: 20px;
|
2019-01-10 19:30:46 -08:00
|
|
|
margin-bottom: 30px;
|
2018-12-19 09:20:56 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Icon = styled.img`
|
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
margin: 20px 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CloseIconWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
align-items: flex-end;
|
|
|
|
justify-content: flex-end;
|
2019-01-10 19:30:46 -08:00
|
|
|
position: absolute;
|
2018-12-19 09:20:56 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const CloseIconImg = styled.img`
|
2019-01-10 19:30:46 -08:00
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
margin-top: 12px;
|
|
|
|
margin-right: 12px;
|
2018-12-19 09:20:56 -08:00
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const InfoRow = styled(RowComponent)`
|
|
|
|
justify-content: space-between;
|
2018-12-19 10:30:38 -08:00
|
|
|
align-items: center;
|
2018-12-19 11:06:19 -08:00
|
|
|
width: 100%;
|
2018-12-19 10:30:38 -08:00
|
|
|
height: 80px;
|
|
|
|
padding: 0 30px;
|
2019-01-10 19:30:46 -08:00
|
|
|
|
|
|
|
&first-child {
|
|
|
|
margin-top: 30px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
2019-02-16 19:34:12 -08:00
|
|
|
background: ${props => props.theme.colors.transactionDetailsRowHover};
|
2019-01-10 19:30:46 -08:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DetailsWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
margin-bottom: 30px;
|
2018-12-19 09:20:56 -08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const Divider = styled.div`
|
|
|
|
width: 100%;
|
2019-02-16 19:34:12 -08:00
|
|
|
background-color: ${props => props.theme.colors.transactionDetailsDivider};
|
2018-12-19 10:30:38 -08:00
|
|
|
height: 1px;
|
2018-12-19 09:20:56 -08:00
|
|
|
opacity: 0.5;
|
|
|
|
`;
|
|
|
|
|
2018-12-19 10:30:38 -08:00
|
|
|
const Label = styled(TextComponent)`
|
2019-02-07 08:31:59 -08:00
|
|
|
font-weight: ${props => String(props.theme.fontWeight.bold)};
|
2019-02-16 19:34:12 -08:00
|
|
|
color: ${props => props.theme.colors.transactionDetailsLabel};
|
2018-12-19 10:30:38 -08:00
|
|
|
margin-bottom: 5px;
|
2019-01-10 19:30:46 -08:00
|
|
|
letter-spacing: 0.25px;
|
2018-12-19 10:30:38 -08:00
|
|
|
`;
|
|
|
|
|
2018-12-19 11:06:19 -08:00
|
|
|
const Ellipsis = styled(TextComponent)`
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2019-01-10 06:05:54 -08:00
|
|
|
width: 100%;
|
2018-12-19 11:06:19 -08:00
|
|
|
`;
|
|
|
|
|
2019-01-29 16:28:10 -08:00
|
|
|
const TransactionId = styled.button`
|
|
|
|
width: 100%;
|
2019-02-07 08:31:59 -08:00
|
|
|
color: ${props => props.theme.colors.text};
|
2019-01-29 16:28:10 -08:00
|
|
|
padding: 0;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-12-19 09:20:56 -08:00
|
|
|
type Props = {
|
|
|
|
amount: number,
|
|
|
|
type: 'send' | 'receive',
|
|
|
|
zecPrice: number,
|
|
|
|
date: string,
|
|
|
|
transactionId: string,
|
2019-02-19 08:06:34 -08:00
|
|
|
address: string,
|
|
|
|
fees: number | string,
|
2018-12-19 09:21:42 -08:00
|
|
|
handleClose: () => void,
|
2019-02-16 19:34:12 -08:00
|
|
|
theme: AppTheme,
|
2018-12-19 09:20:56 -08:00
|
|
|
};
|
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
const Component = ({
|
2018-12-19 09:20:56 -08:00
|
|
|
amount,
|
|
|
|
type,
|
|
|
|
zecPrice,
|
|
|
|
date,
|
|
|
|
transactionId,
|
2019-02-19 08:06:34 -08:00
|
|
|
address,
|
|
|
|
fees,
|
2018-12-19 09:21:42 -08:00
|
|
|
handleClose,
|
2019-02-16 19:34:12 -08:00
|
|
|
theme,
|
2018-12-19 09:20:56 -08:00
|
|
|
}: Props) => {
|
|
|
|
const isReceived = type === 'receive';
|
2019-02-19 08:06:34 -08:00
|
|
|
const receivedIcon = theme.mode === DARK ? ReceivedIconDark : ReceivedIconLight;
|
|
|
|
const sentIcon = theme.mode === DARK ? SentIconDark : SentIconLight;
|
2019-01-10 19:30:46 -08:00
|
|
|
|
2018-12-19 09:20:56 -08:00
|
|
|
return (
|
|
|
|
<Wrapper>
|
|
|
|
<CloseIconWrapper>
|
2019-02-19 08:06:34 -08:00
|
|
|
<CloseIconImg src={CloseIcon} onClick={handleClose} />
|
2018-12-19 09:20:56 -08:00
|
|
|
</CloseIconWrapper>
|
|
|
|
<TitleWrapper>
|
2019-02-06 19:06:48 -08:00
|
|
|
<TextComponent value='Transaction Details' align='center' />
|
2018-12-19 09:20:56 -08:00
|
|
|
</TitleWrapper>
|
2019-01-10 19:30:46 -08:00
|
|
|
<DetailsWrapper>
|
2019-02-19 08:06:34 -08:00
|
|
|
<Icon src={isReceived ? receivedIcon : sentIcon} alt='Transaction Type Icon' />
|
2019-01-10 19:30:46 -08:00
|
|
|
<TextComponent
|
|
|
|
isBold
|
|
|
|
size={2.625}
|
|
|
|
value={formatNumber({
|
|
|
|
append: `${isReceived ? '+' : '-'}ZEC `,
|
|
|
|
value: amount,
|
|
|
|
})}
|
2019-02-20 07:02:23 -08:00
|
|
|
color={
|
|
|
|
isReceived
|
|
|
|
? theme.colors.transactionReceived({ theme })
|
|
|
|
: theme.colors.transactionSent({ theme })
|
|
|
|
}
|
2019-01-10 19:30:46 -08:00
|
|
|
/>
|
|
|
|
<TextComponent
|
|
|
|
value={formatNumber({
|
|
|
|
append: `${isReceived ? '+' : '-'}USD `,
|
2019-01-29 14:18:06 -08:00
|
|
|
value: new BigNumber(amount).times(zecPrice).toNumber(),
|
2019-01-10 19:30:46 -08:00
|
|
|
})}
|
|
|
|
size={1.5}
|
2019-02-20 07:02:23 -08:00
|
|
|
color={theme.colors.transactionDetailsLabel({ theme })}
|
2019-01-10 19:30:46 -08:00
|
|
|
/>
|
|
|
|
</DetailsWrapper>
|
2018-12-19 09:20:56 -08:00
|
|
|
<InfoRow>
|
|
|
|
<ColumnComponent>
|
2018-12-19 10:30:38 -08:00
|
|
|
<Label value='DATE' />
|
2019-02-06 19:06:48 -08:00
|
|
|
<TextComponent value={dateFns.format(new Date(date), 'MMMM D, YYYY HH:MMA')} />
|
2018-12-19 09:20:56 -08:00
|
|
|
</ColumnComponent>
|
|
|
|
<ColumnComponent>
|
2019-02-20 07:02:23 -08:00
|
|
|
<TextComponent
|
|
|
|
value='FEES'
|
|
|
|
isBold
|
|
|
|
color={theme.colors.transactionDetailsLabel({ theme })}
|
|
|
|
/>
|
2019-01-29 14:18:06 -08:00
|
|
|
<TextComponent
|
2019-02-19 08:06:34 -08:00
|
|
|
value={
|
|
|
|
fees === 'N/A'
|
|
|
|
? 'N/A'
|
|
|
|
: formatNumber({
|
|
|
|
value: new BigNumber(fees).toFormat(4),
|
|
|
|
append: 'ZEC ',
|
|
|
|
})
|
|
|
|
}
|
2019-01-29 14:18:06 -08:00
|
|
|
/>
|
2018-12-19 09:20:56 -08:00
|
|
|
</ColumnComponent>
|
|
|
|
</InfoRow>
|
|
|
|
<Divider />
|
|
|
|
<InfoRow>
|
2019-01-10 06:05:54 -08:00
|
|
|
<ColumnComponent width='100%'>
|
2018-12-19 10:30:38 -08:00
|
|
|
<Label value='TRANSACTION ID' />
|
2019-02-13 10:27:36 -08:00
|
|
|
<TransactionId
|
|
|
|
onClick={
|
2019-02-19 08:06:34 -08:00
|
|
|
address !== '(Shielded)'
|
2019-02-13 10:27:36 -08:00
|
|
|
? () => openExternal(ZCASH_EXPLORER_BASE_URL + transactionId)
|
|
|
|
: () => {}
|
|
|
|
}
|
|
|
|
>
|
2019-01-29 16:28:10 -08:00
|
|
|
<Ellipsis value={transactionId} />
|
|
|
|
</TransactionId>
|
2018-12-19 09:20:56 -08:00
|
|
|
</ColumnComponent>
|
|
|
|
</InfoRow>
|
|
|
|
<Divider />
|
|
|
|
<InfoRow>
|
2019-01-10 06:05:54 -08:00
|
|
|
<ColumnComponent width='100%'>
|
2019-02-19 08:06:34 -08:00
|
|
|
<Label value='Address' />
|
|
|
|
<Ellipsis value={address} />
|
2018-12-19 09:20:56 -08:00
|
|
|
</ColumnComponent>
|
|
|
|
</InfoRow>
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
};
|
2019-02-16 19:34:12 -08:00
|
|
|
|
|
|
|
export const TransactionDetailsComponent = withTheme(Component);
|