Skip to content

Commit

Permalink
refactor: ♻️ forward chart
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Nov 14, 2020
1 parent 3e91519 commit 72860f3
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 277 deletions.
14 changes: 7 additions & 7 deletions server/schema/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { gql } from 'apollo-server-micro';

export const transactionTypes = gql`
type Forward {
created_at: String
fee: Int
fee_mtokens: String
incoming_channel: String
mtokens: String
outgoing_channel: String
tokens: Int
created_at: String!
fee: Int!
fee_mtokens: String!
incoming_channel: String!
mtokens: String!
outgoing_channel: String!
tokens: Int!
incoming_node: ForwardNodeType
outgoing_node: ForwardNodeType
}
Expand Down
1 change: 0 additions & 1 deletion server/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const queryTypes = gql`
getForwardsPastDays(days: Int!): [Forward]!
getBitcoinPrice(logger: Boolean, currency: String): String
getBitcoinFees(logger: Boolean): bitcoinFeeType
getForwardReport(time: String): String
getForwardChannelsReport(time: String, order: String, type: String): String
getInOut(time: String): InOutType
getBackups: String
Expand Down
2 changes: 0 additions & 2 deletions server/schema/widgets/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { getForwardChannelsReport } from './resolvers/getForwardChannelsReport';
import { getForwardReport } from './resolvers/getForwardsReport';
import { getInOut } from './resolvers/getInOut';
import { getChannelReport } from './resolvers/getChannelReport';

export const widgetResolvers = {
Query: {
getForwardChannelsReport,
getForwardReport,
getInOut,
getChannelReport,
},
Expand Down
95 changes: 0 additions & 95 deletions server/schema/widgets/resolvers/getForwardsReport.ts

This file was deleted.

33 changes: 1 addition & 32 deletions server/schema/widgets/resolvers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
import { reduce, groupBy } from 'underscore';
import { ForwardType } from 'server/types/ln-service.types';
import {
ReduceObjectProps,
ListProps,
InOutProps,
InOutListProps,
} from './interface';

export const reduceForwardArray = (list: ListProps) => {
const reducedOrder = [];
for (const key in list) {
if (Object.prototype.hasOwnProperty.call(list, key)) {
const element: ForwardType[] = list[key];
const reducedArray: ReduceObjectProps = reduce(
element,
(a: ReduceObjectProps, b: ReduceObjectProps) => {
return {
fee: a.fee + b.fee,
tokens: a.tokens + b.tokens,
};
},
{ fee: 0, tokens: 0 }
);
reducedOrder.push({
period: Number(key),
amount: element.length,
...reducedArray,
});
}
}

return reducedOrder;
};
import { InOutProps, InOutListProps } from './interface';

export const reduceInOutArray = (list: InOutListProps) => {
const reducedOrder = [];
Expand Down
11 changes: 0 additions & 11 deletions server/schema/widgets/resolvers/interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
import { ForwardType } from 'server/types/ln-service.types';

export interface ListProps {
[key: string]: ForwardType[];
}

export interface ReduceObjectProps {
fee: number;
tokens: number;
}

export interface FinalProps {
fee: number;
tokens: number;
Expand Down
47 changes: 0 additions & 47 deletions src/graphql/queries/__generated__/getForwardReport.generated.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/graphql/queries/getForwardReport.ts

This file was deleted.

45 changes: 7 additions & 38 deletions src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ export type Query = {
decodeRequest?: Maybe<DecodeType>;
getWalletInfo?: Maybe<WalletInfoType>;
getResume?: Maybe<GetResumeType>;
getForwards?: Maybe<GetForwardType>;
getForwardsPastDays: Array<Maybe<Forward>>;
getBitcoinPrice?: Maybe<Scalars['String']>;
getBitcoinFees?: Maybe<BitcoinFeeType>;
getForwardReport?: Maybe<Scalars['String']>;
getForwardChannelsReport?: Maybe<Scalars['String']>;
getInOut?: Maybe<InOutType>;
getBackups?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -128,11 +126,6 @@ export type QueryGetResumeArgs = {
};


export type QueryGetForwardsArgs = {
time?: Maybe<Scalars['String']>;
};


export type QueryGetForwardsPastDaysArgs = {
days: Scalars['Int'];
};
Expand All @@ -149,11 +142,6 @@ export type QueryGetBitcoinFeesArgs = {
};


export type QueryGetForwardReportArgs = {
time?: Maybe<Scalars['String']>;
};


export type QueryGetForwardChannelsReportArgs = {
time?: Maybe<Scalars['String']>;
order?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -777,21 +765,15 @@ export type NetworkInfoType = {
totalCapacity?: Maybe<Scalars['String']>;
};

export type GetForwardType = {
__typename?: 'getForwardType';
token?: Maybe<Scalars['String']>;
forwards?: Maybe<Array<Maybe<ForwardType>>>;
};

export type Forward = {
__typename?: 'Forward';
created_at?: Maybe<Scalars['String']>;
fee?: Maybe<Scalars['Int']>;
fee_mtokens?: Maybe<Scalars['String']>;
incoming_channel?: Maybe<Scalars['String']>;
mtokens?: Maybe<Scalars['String']>;
outgoing_channel?: Maybe<Scalars['String']>;
tokens?: Maybe<Scalars['Int']>;
created_at: Scalars['String'];
fee: Scalars['Int'];
fee_mtokens: Scalars['String'];
incoming_channel: Scalars['String'];
mtokens: Scalars['String'];
outgoing_channel: Scalars['String'];
tokens: Scalars['Int'];
incoming_node?: Maybe<ForwardNodeType>;
outgoing_node?: Maybe<ForwardNodeType>;
};
Expand All @@ -807,19 +789,6 @@ export type ForwardNodeType = {
public_key?: Maybe<Scalars['String']>;
};

export type ForwardType = {
__typename?: 'forwardType';
created_at?: Maybe<Scalars['String']>;
fee?: Maybe<Scalars['Int']>;
fee_mtokens?: Maybe<Scalars['String']>;
incoming_channel?: Maybe<Scalars['String']>;
mtokens?: Maybe<Scalars['String']>;
outgoing_channel?: Maybe<Scalars['String']>;
tokens?: Maybe<Scalars['Int']>;
incoming_channel_info?: Maybe<Channel>;
outgoing_channel_info?: Maybe<Channel>;
};

export type PaymentType = {
__typename?: 'PaymentType';
created_at: Scalars['String'];
Expand Down
21 changes: 13 additions & 8 deletions src/views/home/reports/forwardReport/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import { ReportType, ReportDuration, FlowReportType } from './ForwardReport';
interface ButtonProps {
isTime: ReportDuration;
isType: ReportType;
setDays: (days: number) => void;
setIsTime: (text: ReportDuration) => void;
setIsType: (text: ReportType) => void;
}

export const ButtonRow: React.FC<ButtonProps> = ({
isTime,
setIsTime,
setDays,
isType,
setIsType,
}) => {
const timeButton = (time: ReportDuration, title: string) => (
const timeButton = (time: ReportDuration, title: string, days: number) => (
<SingleButton
withPadding={'4px 8px'}
onClick={() => setIsTime(time)}
onClick={() => {
setIsTime(time);
setDays(days);
}}
selected={isTime === time}
>
{title}
Expand All @@ -42,12 +47,12 @@ export const ButtonRow: React.FC<ButtonProps> = ({
return (
<ResponsiveSingle>
<MultiButton>
{timeButton('day', '1D')}
{timeButton('week', '1W')}
{timeButton('month', '1M')}
{timeButton('quarter_year', '3M')}
{timeButton('half_year', '6M')}
{timeButton('year', '1Y')}
{timeButton('day', '1D', 1)}
{timeButton('week', '1W', 7)}
{timeButton('month', '1M', 30)}
{timeButton('quarter_year', '3M', 90)}
{timeButton('half_year', '6M', 180)}
{timeButton('year', '1Y', 360)}
</MultiButton>
<MultiButton>
{typeButton('amount', 'Amount')}
Expand Down
Loading

0 comments on commit 72860f3

Please sign in to comment.