Skip to content

Commit

Permalink
refactor: ♻️ forward report
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Jul 12, 2020
1 parent 77b597d commit 5dd94af
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 168 deletions.
2 changes: 1 addition & 1 deletion server/schema/widgets/resolvers/getInOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getInOut = async (
} else if (params.time === 'quarter_year') {
periods = 90;
} else if (params.time === 'month') {
periods = 150;
periods = 30;
} else if (params.time === 'day') {
periods = 24;
difference = (date: string) => differenceInHours(endDate, new Date(date));
Expand Down
6 changes: 5 additions & 1 deletion src/components/buttons/multiButton/MultiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
interface StyledSingleProps {
selected?: boolean;
buttonColor?: string;
withPadding?: string;
}

const StyledSingleButton = styled.button<StyledSingleProps>`
Expand All @@ -17,7 +18,7 @@ const StyledSingleButton = styled.button<StyledSingleProps>`
outline: none;
border: none;
text-decoration: none;
padding: 8px 16px;
padding: ${({ withPadding }) => (withPadding ? withPadding : '8px 16px')};
background-color: transparent;
color: ${multiSelectColor};
flex-grow: 1;
Expand All @@ -35,19 +36,22 @@ const StyledSingleButton = styled.button<StyledSingleProps>`
interface SingleButtonProps {
selected?: boolean;
color?: string;
withPadding?: string;
onClick?: () => void;
}

export const SingleButton: React.FC<SingleButtonProps> = ({
children,
selected,
color,
withPadding,
onClick,
}) => {
return (
<StyledSingleButton
selected={selected}
buttonColor={color}
withPadding={withPadding}
onClick={() => {
onClick && onClick();
}}
Expand Down
4 changes: 1 addition & 3 deletions src/views/home/reports/flow/FlowReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FlowReport = ({
const format = getPrice(currency, displayValues, priceContext);

let domain = 24;
let barWidth = 3;
let barWidth = 1;
if (isTime === 'week') {
domain = 7;
barWidth = 15;
Expand All @@ -38,10 +38,8 @@ export const FlowReport = ({
domain = 90;
} else if (isTime === 'half_year') {
domain = 180;
barWidth = 1;
} else if (isTime === 'year') {
domain = 360;
barWidth = 1;
}

return (
Expand Down
15 changes: 13 additions & 2 deletions src/views/home/reports/forwardReport/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ import { ResponsiveSingle } from 'src/components/generic/Styled';
interface ButtonProps {
isTime: string;
isType: string;
withFee?: boolean;
setIsTime: (text: string) => void;
setIsType: (text: string) => void;
}

export const ButtonRow = ({
withFee,
isTime,
setIsTime,
isType,
setIsType,
}: ButtonProps) => {
const timeButton = (time: string, title: string) => (
<SingleButton onClick={() => setIsTime(time)} selected={isTime === time}>
<SingleButton
withPadding={'4px 8px'}
onClick={() => setIsTime(time)}
selected={isTime === time}
>
{title}
</SingleButton>
);

const typeButton = (type: string, title: string) => (
<SingleButton onClick={() => setIsType(type)} selected={isType === type}>
<SingleButton
withPadding={'4px 8px'}
onClick={() => setIsType(type)}
selected={isType === type}
>
{title}
</SingleButton>
);
Expand All @@ -43,6 +53,7 @@ export const ButtonRow = ({
<MultiButton>
{typeButton('amount', 'Amount')}
{typeButton('tokens', 'Tokens')}
{withFee && typeButton('fee', 'Fees')}
</MultiButton>
</ResponsiveSingle>
);
Expand Down
91 changes: 21 additions & 70 deletions src/views/home/reports/forwardReport/ForwardChannelReport.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, { useState } from 'react';
import { toast } from 'react-toastify';
import { GitCommit, ArrowDown, ArrowUp } from 'react-feather';
import styled, { css } from 'styled-components';
import styled from 'styled-components';
import { useAccountState } from 'src/context/AccountContext';
import { useGetForwardChannelsReportQuery } from 'src/graphql/queries/__generated__/getForwardChannelsReport.generated';
import {
MultiButton,
SingleButton,
} from 'src/components/buttons/multiButton/MultiButton';
import { getErrorContent } from '../../../../utils/error';
import {
DarkSubTitle,
SmallButton,
SingleLine,
} from '../../../../components/generic/Styled';
import { LoadingCard } from '../../../../components/loading/LoadingCard';
Expand All @@ -23,36 +26,6 @@ const ChannelRow = styled.div`
align-items: center;
`;

const ButtonRow = styled.div`
display: flex;
margin-bottom: 5px;
`;

type TriButtonProps = {
selected: boolean;
};

const TriButton = styled(SmallButton)<TriButtonProps>`
margin: 0;
border-radius: 0;
${({ selected }) =>
selected &&
css`
color: white;
`}
`;

const LeftButton = styled(TriButton)`
border-bottom-left-radius: 5px;
border-top-left-radius: 5px;
`;

const RightButton = styled(TriButton)`
border-bottom-right-radius: 5px;
border-top-right-radius: 5px;
`;

const TableLine = styled.div`
width: 35%;
white-space: nowrap;
Expand All @@ -68,10 +41,9 @@ const LastTableLine = styled(TableLine)`
interface Props {
isTime: string;
isType: string;
color: string;
}

export const ForwardChannelsReport = ({ isTime, isType, color }: Props) => {
export const ForwardChannelsReport = ({ isTime, isType }: Props) => {
const [type, setType] = useState('route');

const { currency, displayValues } = useConfigState();
Expand All @@ -92,28 +64,7 @@ export const ForwardChannelsReport = ({ isTime, isType, color }: Props) => {

const report = data.getForwardChannelsReport;

const fillArray = (array: {}[]) => {
const lengthMissing = 10 - array.length;
if (lengthMissing === 10) {
return [];
}
if (lengthMissing > 0) {
for (let i = 0; i < lengthMissing; i += 1) {
array.push({
aliasIn: '-',
aliasOut: '-',
alias: '-',
name: '-',
amount: '',
fee: '',
tokens: '',
});
}
}
return array;
};

const parsed = fillArray(JSON.parse(report));
const parsed = JSON.parse(report);

const getFormatString = (amount: number | string) => {
if (typeof amount === 'string') return amount;
Expand Down Expand Up @@ -179,29 +130,29 @@ export const ForwardChannelsReport = ({ isTime, isType, color }: Props) => {
};

const renderButtons = () => (
<ButtonRow>
<LeftButton
color={color}
<MultiButton>
<SingleButton
withPadding={'4px 8px'}
selected={type === 'incoming'}
onClick={() => setType('incoming')}
>
<ArrowDown size={18} />
</LeftButton>
<TriButton
<ArrowDown size={14} />
</SingleButton>
<SingleButton
withPadding={'4px 8px'}
selected={type === 'route'}
onClick={() => setType('route')}
color={color}
>
<GitCommit size={18} />
</TriButton>
<RightButton
<GitCommit size={14} />
</SingleButton>
<SingleButton
withPadding={'4px 8px'}
selected={type === 'outgoing'}
color={color}
onClick={() => setType('outgoing')}
>
<ArrowUp size={18} />
</RightButton>
</ButtonRow>
<ArrowUp size={14} />
</SingleButton>
</MultiButton>
);

const renderTop = (title: string) => (
Expand Down
Loading

0 comments on commit 5dd94af

Please sign in to comment.