Merge pull request #21 from andrerfneves/feature/transactions-details

Feature/transactions details
This commit is contained in:
George Lima 2018-12-20 15:21:30 -02:00 committed by GitHub
commit 486f03f4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 285 additions and 46 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 24 24" height="24px" id="Layer_1" version="1.1" viewBox="0 0 24 24" width="24px" xml:space="preserve"><path xmlns="http://www.w3.org/2000/svg" fill="#777777" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>

After

Width:  |  Height:  |  Size: 839 B

View File

@ -46,20 +46,23 @@ export const TransactionDailyComponent = ({
<Wrapper>
<Day value={transactionsDate} />
<TransactionsWrapper>
{transactions.map(({
date, type, address, amount,
}, idx) => (
<Fragment key={`${address}-${type}-${amount}-${date}`}>
<TransactionItemComponent
type={type}
date={date}
address={address || ''}
amount={amount}
zecPrice={zecPrice}
/>
{idx < transactions.length - 1 && <Divider />}
</Fragment>
))}
{transactions.map(
({
date, type, address, amount, transactionId,
}, idx) => (
<Fragment key={`${address}-${type}-${amount}-${date}`}>
<TransactionItemComponent
transactionId={transactionId}
type={type}
date={date}
address={address || ''}
amount={amount}
zecPrice={zecPrice}
/>
{idx < transactions.length - 1 && <Divider />}
</Fragment>
),
)}
</TransactionsWrapper>
</Wrapper>
);

View File

@ -0,0 +1,176 @@
// @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 CloseIcon from '../assets/images/close_icon.svg';
import { TextComponent } from './text';
import { RowComponent } from './row';
import { ColumnComponent } from './column';
import theme from '../theme';
import formatNumber from '../utils/formatNumber';
import truncateAddress from '../utils/truncateAddress';
const Wrapper = styled.div`
width: 30vw;
background-color: ${props => props.theme.colors.background};
display: flex;
flex-direction: column;
align-items: center;
border-radius: 6px;
box-shadow: 0px 0px 30px 0px black;
`;
const TitleWrapper = styled.div`
margin-top: 20px;
`;
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;
`;
const CloseIconImg = styled.img`
width: 12.5px;
height: 12.5px;
margin-top: 10px;
margin-right: 10px;
cursor: pointer;
`;
const InfoRow = styled(RowComponent)`
justify-content: space-between;
align-items: center;
width: 100%;
height: 80px;
padding: 0 30px;
`;
const Divider = styled.div`
width: 100%;
background-color: ${props => props.theme.colors.transactionsDetailsLabel};
height: 1px;
opacity: 0.5;
`;
const Label = styled(TextComponent)`
font-weight: ${props => props.theme.fontWeight.bold};
color: ${props => props.theme.colors.transactionsDetailsLabel};
margin-bottom: 5px;
`;
const Ellipsis = styled(TextComponent)`
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: calc(30vw - 60px);
`;
type Props = {
amount: number,
type: 'send' | 'receive',
zecPrice: number,
date: string,
transactionId: string,
from: string,
to: string,
handleClose: () => void,
};
export const TransactionDetailsComponent = ({
amount,
type,
zecPrice,
date,
transactionId,
from,
to,
handleClose,
}: Props) => {
const isReceived = type === 'receive';
return (
<Wrapper>
<CloseIconWrapper>
<CloseIconImg src={CloseIcon} onClick={handleClose} />
</CloseIconWrapper>
<TitleWrapper>
<TextComponent value='Transaction Details' align='center' />
</TitleWrapper>
<Icon
src={isReceived ? ReceivedIcon : SentIcon}
alt='Transaction Type Icon'
/>
<TextComponent
value={formatNumber({
append: `${isReceived ? '+' : '-'}ZEC `,
value: amount,
})}
color={
isReceived
? theme.colors.transactionReceived
: theme.colors.transactionSent
}
isBold
size={2.625}
/>
<TextComponent
value={formatNumber({
append: `${isReceived ? '+' : '-'}USD `,
value: amount * zecPrice,
})}
size={1.5}
color={theme.colors.transactionsDetailsLabel}
/>
<InfoRow>
<ColumnComponent>
<Label value='DATE' />
<TextComponent value={dateFns.format(date, 'MMMM D, YYYY HH:MMA')} />
</ColumnComponent>
<ColumnComponent>
<TextComponent
value='FEES'
isBold
color={theme.colors.transactionsDetailsLabel}
/>
<TextComponent
value={formatNumber({ value: amount * 0.1, append: 'ZEC ' })}
/>
</ColumnComponent>
</InfoRow>
<Divider />
<InfoRow>
<ColumnComponent>
<Label value='TRANSACTION ID' />
<Ellipsis value={transactionId} />
</ColumnComponent>
</InfoRow>
<Divider />
<InfoRow>
<ColumnComponent>
<Label value='FROM' />
<TextComponent value={truncateAddress(from)} />
</ColumnComponent>
</InfoRow>
<Divider />
<InfoRow>
<ColumnComponent>
<Label value='TO' />
<TextComponent value={truncateAddress(to)} />
</ColumnComponent>
</InfoRow>
</Wrapper>
);
};

View File

@ -0,0 +1,32 @@
---
name: Transaction Details
---
import { Playground, PropsTable } from 'docz'
import { TransactionDetails } from './transaction-details.js'
import { DoczWrapper } from '../theme.js'
# Transaction Details
## Properties
<PropsTable of={TransactionDetails} />
## Basic Usage
<Playground>
<DoczWrapper>
{() => (
<TransactionDetails
type="receive"
amount={2851}
zecPrice={56}
transactionId="asdh8233uhd89as283dhuashd23-493iskdfdnhdufhs"
from="WKSJniasnxusiuhd898ns13umdoioj93287yhnjknxU"
to="WKSJniasnxusiuhd898ns13umdoioj93287yhnjknxU"
date={new Date().toISOString()}
/>
)}
</DoczWrapper>
</Playground>

View File

@ -9,6 +9,8 @@ import ReceivedIcon from '../assets/images/transaction_received_icon.svg';
import { RowComponent } from './row';
import { ColumnComponent } from './column';
import { TextComponent } from './text';
import { ModalComponent } from './modal';
import { TransactionDetailsComponent } from './transaction-details';
import theme from '../theme';
@ -53,6 +55,7 @@ export type Transaction = {
address: string,
amount: number,
zecPrice: number,
transactionId: string,
};
export const TransactionItemComponent = ({
@ -61,6 +64,7 @@ export const TransactionItemComponent = ({
address,
amount,
zecPrice,
transactionId,
}: Transaction) => {
const isReceived = type === 'receive';
const transactionTime = dateFns.format(new Date(date), 'HH:mm A');
@ -75,34 +79,55 @@ export const TransactionItemComponent = ({
const transactionAddress = truncateAddress(address);
return (
<Wrapper alignItems='center' justifyContent='space-between'>
<RowComponent alignItems='center'>
<RowComponent alignItems='center'>
<Icon
src={isReceived ? ReceivedIcon : SentIcon}
alt='Transaction Type Icon'
/>
<TransactionColumn>
<TransactionTypeLabel isReceived={isReceived} value={type} />
<TransactionTime value={transactionTime} />
</TransactionColumn>
</RowComponent>
<TextComponent value={transactionAddress} align='left' />
</RowComponent>
<ColumnComponent alignItems='flex-end'>
<TextComponent
value={transactionValueInZec}
color={
isReceived
? theme.colors.transactionReceived
: theme.colors.transactionSent
}
<ModalComponent
renderTrigger={toggleVisibility => (
<Wrapper
alignItems='center'
justifyContent='space-between'
onClick={toggleVisibility}
>
<RowComponent alignItems='center'>
<RowComponent alignItems='center'>
<Icon
src={isReceived ? ReceivedIcon : SentIcon}
alt='Transaction Type Icon'
/>
<TransactionColumn>
<TransactionTypeLabel isReceived={isReceived} value={type} />
<TransactionTime value={transactionTime} />
</TransactionColumn>
</RowComponent>
<TextComponent value={transactionAddress} align='left' />
</RowComponent>
<ColumnComponent alignItems='flex-end'>
<TextComponent
value={transactionValueInZec}
color={
isReceived
? theme.colors.transactionReceived
: theme.colors.transactionSent
}
/>
<TextComponent
value={transactionValueInUsd}
color={theme.colors.inactiveItem}
/>
</ColumnComponent>
</Wrapper>
)}
>
{toggleVisibility => (
<TransactionDetailsComponent
amount={amount}
date={date}
from={address}
to=''
transactionId={transactionId}
handleClose={toggleVisibility}
type={type}
zecPrice={zecPrice}
/>
<TextComponent
value={transactionValueInUsd}
color={theme.colors.inactiveItem}
/>
</ColumnComponent>
</Wrapper>
)}
</ModalComponent>
);
};

View File

@ -41,9 +41,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
// eslint-disable-next-line
if (addressesErr) return dispatch(loadWalletSummaryError({ error: addressesErr.message }));
const [transactionsErr, transactions = []] = await eres(
rpc.listtransactions(),
);
const [transactionsErr, transactions] = await eres(rpc.listtransactions());
if (transactionsErr) {
return dispatch(
@ -59,6 +57,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
addresses,
transactions: flow([
arr => arr.map(transaction => ({
transactionId: transaction.txid,
type: transaction.category,
date: new Date(transaction.time * 1000).toISOString(),
address: transaction.address,

View File

@ -42,6 +42,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
loadTransactionsSuccess({
list: flow([
arr => arr.map(transaction => ({
transactionId: transaction.txid,
type: transaction.category,
date: new Date(transaction.time * 1000).toISOString(),
address: transaction.address,

View File

@ -23,6 +23,7 @@ const transactionSent = '#FF6C6C';
const transactionReceived = '#6AEAC0';
const transactionsDate = '#777777';
const transactionsItemHovered = '#222222';
const transactionsDetailsLabel = transactionsDate;
const appTheme = {
mode: DARK,
@ -61,6 +62,7 @@ const appTheme = {
transactionReceived,
transactionsDate,
transactionsItemHovered,
transactionsDetailsLabel,
},
sidebarWidth: '200px',
headerHeight: '60px',

View File

@ -1,3 +1,3 @@
// @flow
export default ({ value, append = '' }: { value: number, append?: string }) => `${append}${(value || 0).toLocaleString('de-DE')}`;
export default ({ value, append = '' }: { value: number, append?: string }) => `${append}${(value || 0).toLocaleString()}`;