diff --git a/src/client/src/views/dashboard/widgets/lightning/invoiceGraph.tsx b/src/client/src/views/dashboard/widgets/lightning/invoiceGraph.tsx
index c941b9ba..92659505 100644
--- a/src/client/src/views/dashboard/widgets/lightning/invoiceGraph.tsx
+++ b/src/client/src/views/dashboard/widgets/lightning/invoiceGraph.tsx
@@ -40,7 +40,7 @@ const S = {
};
const typeOptions = [
- { label: 'Count', value: 'amount' },
+ { label: 'Count', value: 'count' },
{ label: 'Amount', value: 'tokens' },
];
diff --git a/src/client/src/views/dashboard/widgets/lightning/paymentGraph.tsx b/src/client/src/views/dashboard/widgets/lightning/paymentGraph.tsx
index 0dc2e037..14d99199 100644
--- a/src/client/src/views/dashboard/widgets/lightning/paymentGraph.tsx
+++ b/src/client/src/views/dashboard/widgets/lightning/paymentGraph.tsx
@@ -40,7 +40,7 @@ const S = {
};
const typeOptions = [
- { label: 'Count', value: 'amount' },
+ { label: 'Count', value: 'count' },
{ label: 'Amount', value: 'tokens' },
];
diff --git a/src/client/src/views/forwards/ForwardTable.tsx b/src/client/src/views/forwards/ForwardTable.tsx
index b953d65a..64c25a34 100644
--- a/src/client/src/views/forwards/ForwardTable.tsx
+++ b/src/client/src/views/forwards/ForwardTable.tsx
@@ -1,95 +1,91 @@
import { FC } from 'react';
import { toast } from 'react-toastify';
-import { ProgressBar } from '../../components/generic/CardGeneric';
-import { SingleLine } from '../../components/generic/Styled';
-import { getPrice } from '../../components/price/Price';
-import { useConfigState } from '../../context/ConfigContext';
-import { usePriceState } from '../../context/PriceContext';
+import { Price } from '../../components/price/Price';
import { useGetForwardsQuery } from '../../graphql/queries/__generated__/getForwards.generated';
-import { Forward } from '../../graphql/types';
import { getErrorContent } from '../../utils/error';
-import { sortByNode } from './helpers';
import Table from '../../components/table';
+import { getChannelLink, getNodeLink } from '../../components/generic/helpers';
+import { numberWithCommas } from '../../utils/number';
-const getBar = (top: number, bottom: number) => {
- const percent = (top / bottom) * 100;
- return Math.min(percent, 100);
-};
-
-const SingleBar = ({ value, height }: { value: number; height: number }) => {
- const opposite = 100 - value;
-
- return (
-
-
-
-
- );
-};
-
-export const ForwardTable: FC<{ days: number; order: string }> = ({
- days,
- order,
-}) => {
+export const ForwardTable: FC<{ days: number }> = ({ days }) => {
const { data, loading } = useGetForwardsQuery({
- ssr: false,
variables: { days },
onError: error => toast.error(getErrorContent(error)),
});
- const { currency, displayValues } = useConfigState();
- const priceContext = usePriceState();
- const format = getPrice(currency, displayValues, priceContext);
-
- if (loading || !data?.getForwards?.length) {
+ if (loading || !data?.getForwards?.list.length) {
return null;
}
- const { final, maxIn, maxOut } = sortByNode(
- order,
- data.getForwards as Forward[]
- );
+ const tableData = data.getForwards.by_channel || [];
const columns = [
{
header: 'Alias',
accessorKey: 'alias',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ {getNodeLink(
+ row.original.channel_info.node2_info.public_key,
+ row.original.channel_info.node2_info.alias
+ )}
+
+ ),
},
{
header: 'Channel',
accessorKey: 'channel',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ {getChannelLink(row.original.channel)}
+
+ ),
},
{
header: 'Incoming',
- accessorKey: 'incoming',
- cell: ({ cell }: any) => cell.renderValue(),
+ columns: [
+ {
+ header: 'Count',
+ accessorKey: 'incoming.count',
+ cell: ({ row }: any) => numberWithCommas(row.original.incoming.count),
+ },
+ {
+ header: 'Fee (sats)',
+ accessorKey: 'incoming.fee',
+ cell: ({ row }: any) => ,
+ },
+ {
+ header: 'Amount (sats)',
+ accessorKey: 'incoming.tokens',
+ cell: ({ row }: any) => (
+
+ ),
+ },
+ ],
},
{
header: 'Outgoing',
- accessorKey: 'outgoing',
- cell: ({ cell }: any) => cell.renderValue(),
- },
- {
- header: 'Incoming',
- accessorKey: 'incomingBar',
- cell: ({ cell }: any) => cell.renderValue(),
- },
- {
- header: 'Outgoing',
- accessorKey: 'outgoingBar',
- cell: ({ cell }: any) => cell.renderValue(),
+ columns: [
+ {
+ header: 'Count',
+ accessorKey: 'outgoing.count',
+ cell: ({ row }: any) => numberWithCommas(row.original.outgoing.count),
+ },
+ {
+ header: 'Fee (sats)',
+ accessorKey: 'outgoing.fee',
+ cell: ({ row }: any) => ,
+ },
+ {
+ header: 'Amount (sats)',
+ accessorKey: 'outgoing.tokens',
+ cell: ({ row }: any) => (
+
+ ),
+ },
+ ],
},
];
- const tableData = final.map(f => ({
- ...f,
- incoming: format({ amount: f.incoming, noUnit: order === 'amount' }),
- outgoing: format({ amount: f.outgoing, noUnit: order === 'amount' }),
- incomingBar: ,
- outgoingBar: ,
- }));
-
return ;
};
diff --git a/src/client/src/views/forwards/forwardSankey.tsx b/src/client/src/views/forwards/forwardSankey.tsx
index a5aec13b..0d7df8ca 100644
--- a/src/client/src/views/forwards/forwardSankey.tsx
+++ b/src/client/src/views/forwards/forwardSankey.tsx
@@ -5,7 +5,8 @@ import styled from 'styled-components';
import { mediaWidths } from '../../styles/Themes';
import { useGetForwardsQuery } from '../../graphql/queries/__generated__/getForwards.generated';
import { Sankey, SankeyData } from '../../components/sankey';
-import { groupBy, orderBy, reduce, uniq } from 'lodash';
+import { orderBy, reduce, uniq } from 'lodash';
+import { AggregatedRouteForwards } from '../../graphql/types';
const Wrapper = styled.div<{ $height: number }>`
height: ${props => props.$height}px;
@@ -17,9 +18,22 @@ const Wrapper = styled.div<{ $height: number }>`
}
`;
+const getValue = (item: AggregatedRouteForwards, type: string) => {
+ switch (type) {
+ case 'count':
+ return item.count;
+ case 'tokens':
+ return item.tokens;
+ case 'fee':
+ return item.fee;
+ default:
+ return 0;
+ }
+};
+
export const ForwardSankey: FC<{
days: number;
- type: 'amount' | 'fee' | 'tokens';
+ type: string;
}> = ({ days, type }) => {
const { data, loading } = useGetForwardsQuery({
ssr: false,
@@ -28,54 +42,22 @@ export const ForwardSankey: FC<{
});
const sankeyData: SankeyData = useMemo(() => {
- if (loading || !data || !data.getForwards.length) {
+ if (loading || !data || !data.getForwards.by_route.length) {
return { links: [], nodes: [] };
}
- const mapped = data.getForwards.map(d => ({
- ...d,
- group: `${d.incoming_channel}-${d.outgoing_channel}`,
- groupAlias: `${d.incoming_channel_info?.node2_info.alias || 'Unknown'}-${
- d.outgoing_channel_info?.node2_info.alias || 'Unknown'
- }`,
- }));
-
- const grouped = groupBy(mapped, 'groupAlias');
-
- const aggregated: {
- incoming_channel: string;
- outgoing_channel: string;
- fee: number;
- tokens: number;
- amount: number;
- }[] = [];
-
- Object.entries(grouped).forEach(([, value]) => {
- const totalFees = value.map(v => v.fee).reduce((p, c) => p + c, 0);
- const totalTokens = value.map(v => v.tokens).reduce((p, c) => p + c, 0);
- const totalAmount = value.length;
-
- const firstValue = value[0];
-
- aggregated.push({
- incoming_channel:
- firstValue.incoming_channel_info?.node2_info.alias || 'Unknown',
- outgoing_channel:
- firstValue.outgoing_channel_info?.node2_info.alias || 'Unknown',
- fee: totalFees,
- tokens: totalTokens,
- amount: totalAmount,
- });
- });
-
const finalData = reduce(
- aggregated,
+ data.getForwards.by_route,
(p, c) => {
- const source = `source: ${c.incoming_channel}`;
- const target = `target: ${c.outgoing_channel}`;
+ const source = `source: ${
+ c.incoming_channel_info?.node2_info.alias || 'Unknown'
+ } (${c.incoming_channel})`;
+ const target = `target: ${
+ c.outgoing_channel_info?.node2_info.alias || 'Unknown'
+ } (${c.outgoing_channel})`;
return {
- links: [...p.links, { source, target, value: c[type] || 0 }],
+ links: [...p.links, { source, target, value: getValue(c, type) }],
nodes: [...p.nodes, source, target],
};
},
@@ -91,7 +73,7 @@ export const ForwardSankey: FC<{
};
}, [data, loading, type]);
- if (loading || !data?.getForwards?.length) {
+ if (loading || !data?.getForwards.by_route.length) {
return null;
}
diff --git a/src/client/src/views/forwards/helpers.tsx b/src/client/src/views/forwards/helpers.tsx
deleted file mode 100644
index f148b45b..00000000
--- a/src/client/src/views/forwards/helpers.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { sortBy, uniqBy } from 'lodash';
-import { Forward } from '../../graphql/types';
-
-export const sortByNode = (order: string, forwardArray: Forward[]) => {
- const cleaned = forwardArray.map(f => {
- let value = 1;
-
- if (order === 'fee') {
- value = f.fee;
- } else if (order === 'tokens') {
- value = f.tokens;
- }
-
- return {
- incoming_alias: f.incoming_channel_info?.node2_info.alias || 'Unknown',
- incoming_channel: f.incoming_channel,
- outgoing_alias: f.outgoing_channel_info?.node2_info.alias || 'Unknown',
- outgoing_channel: f.outgoing_channel,
- value,
- };
- });
-
- const incomingNodes = cleaned.map(f => ({
- alias: f.incoming_alias,
- channel: f.incoming_channel,
- }));
- const outgoingNodes = cleaned.map(f => ({
- alias: f.outgoing_alias,
- channel: f.outgoing_channel,
- }));
-
- const uniqueNodes = uniqBy([...incomingNodes, ...outgoingNodes], 'channel');
- const nodeLength = uniqueNodes.length;
-
- const incoming: number[] = new Array(nodeLength).fill(0);
- const outgoing: number[] = new Array(nodeLength).fill(0);
-
- cleaned.forEach(f => {
- const inIndex = uniqueNodes.findIndex(
- n => n.channel === f.incoming_channel
- );
- const outIndex = uniqueNodes.findIndex(
- n => n.channel === f.outgoing_channel
- );
-
- const currentIncoming = incoming[inIndex];
- const currentOutgoing = outgoing[outIndex];
-
- incoming[inIndex] = currentIncoming + f.value;
- outgoing[outIndex] = currentOutgoing + f.value;
- });
-
- let maxIn = 0;
- let maxOut = 0;
-
- const final = uniqueNodes.map((n, index) => {
- const incomingValue = incoming[index];
- const outgoingValue = outgoing[index];
-
- maxIn = Math.max(maxIn, incomingValue);
- maxOut = Math.max(maxOut, outgoingValue);
-
- return {
- alias: n.alias,
- channel: n.channel,
- incoming: incomingValue,
- outgoing: outgoingValue,
- };
- });
-
- return {
- final: sortBy(final, f => f.incoming + f.outgoing).reverse(),
- maxIn,
- maxOut,
- };
-};
diff --git a/src/client/src/views/forwards/index.tsx b/src/client/src/views/forwards/index.tsx
index eafb4974..46f93171 100644
--- a/src/client/src/views/forwards/index.tsx
+++ b/src/client/src/views/forwards/index.tsx
@@ -1,17 +1,30 @@
import { FC, useMemo } from 'react';
import { toast } from 'react-toastify';
-import { getDateDif } from '../../components/generic/helpers';
+import {
+ getChannelLink,
+ getDateDif,
+ getNodeLink,
+} from '../../components/generic/helpers';
import { DarkSubTitle } from '../../components/generic/Styled';
import { LoadingCard } from '../../components/loading/LoadingCard';
import { Price } from '../../components/price/Price';
import { useGetForwardsQuery } from '../../graphql/queries/__generated__/getForwards.generated';
import { getErrorContent } from '../../utils/error';
import Table from '../../components/table';
+import { useChannelInfo } from '../../hooks/UseChannelInfo';
type ForwardProps = {
days: number;
};
+const ChannelPeer: FC<{ channel: string }> = ({ channel }) => {
+ const {
+ peer: { alias, pubkey },
+ } = useChannelInfo(channel);
+
+ return {getNodeLink(pubkey, alias)}
;
+};
+
export const ForwardsList: FC = ({ days }) => {
const { loading, data } = useGetForwardsQuery({
variables: { days },
@@ -19,13 +32,11 @@ export const ForwardsList: FC = ({ days }) => {
});
const tableData = useMemo(() => {
- const channelData = data?.getForwards || [];
+ const channelData = data?.getForwards.list || [];
return channelData.map(c => {
return {
...c,
- incoming_name: c.incoming_channel_info?.node2_info.alias || 'Unknown',
- outgoing_name: c.outgoing_channel_info?.node2_info.alias || 'Unknown',
};
});
}, [data]);
@@ -70,12 +81,16 @@ export const ForwardsList: FC = ({ days }) => {
{
header: 'Incoming',
accessorKey: 'incoming_name',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ ),
},
{
header: 'Outgoing',
accessorKey: 'outgoing_name',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ ),
},
],
},
@@ -85,12 +100,14 @@ export const ForwardsList: FC = ({ days }) => {
{
header: 'Incoming',
accessorKey: 'incoming_channel',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) =>
+ getChannelLink(row.original.incoming_channel),
},
{
header: 'Outgoing',
accessorKey: 'outgoing_channel',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) =>
+ getChannelLink(row.original.outgoing_channel),
},
],
},
@@ -102,7 +119,7 @@ export const ForwardsList: FC = ({ days }) => {
return ;
}
- if (!data || !data.getForwards?.length) {
+ if (!data || !data.getForwards.list.length) {
return No forwards found;
}
diff --git a/src/client/src/views/home/reports/flow/TransactionGraph.tsx b/src/client/src/views/home/reports/flow/TransactionGraph.tsx
index 776258da..fc06abcf 100644
--- a/src/client/src/views/home/reports/flow/TransactionGraph.tsx
+++ b/src/client/src/views/home/reports/flow/TransactionGraph.tsx
@@ -87,7 +87,7 @@ export const TransactionsGraph: FC = ({
const invoicesByDate = getByTime(filtered, difference);
return invoicesByDate;
- }, [invoiceData, showPay]);
+ }, [invoiceData]);
const paymentsByDate = useMemo(() => {
const payments = paymentsData?.getPayments.payments || [];
@@ -107,7 +107,7 @@ export const TransactionsGraph: FC = ({
const paymentsByDate = getByTime(filtered, difference);
return paymentsByDate;
- }, [paymentsData, showPay]);
+ }, [paymentsData]);
if (loading || paymentsLoading) {
return (
diff --git a/src/client/src/views/home/reports/flow/index.tsx b/src/client/src/views/home/reports/flow/index.tsx
index 34690bfe..832063c3 100644
--- a/src/client/src/views/home/reports/flow/index.tsx
+++ b/src/client/src/views/home/reports/flow/index.tsx
@@ -42,7 +42,7 @@ const options = [
];
const typeOptions = [
- { label: 'Count', value: 'amount' },
+ { label: 'Count', value: 'count' },
{ label: 'Volume', value: 'tokens' },
];
diff --git a/src/client/src/views/home/reports/forwardReport/ForwardChannelReport.tsx b/src/client/src/views/home/reports/forwardReport/ForwardChannelReport.tsx
index 46d9716b..343cc906 100644
--- a/src/client/src/views/home/reports/forwardReport/ForwardChannelReport.tsx
+++ b/src/client/src/views/home/reports/forwardReport/ForwardChannelReport.tsx
@@ -5,31 +5,23 @@ import {
MultiButton,
SingleButton,
} from '../../../../components/buttons/multiButton/MultiButton';
-import { Forward } from '../../../../graphql/types';
import styled from 'styled-components';
import { useGetForwardsQuery } from '../../../../graphql/queries/__generated__/getForwards.generated';
import { getErrorContent } from '../../../../utils/error';
import { SingleLine, SubTitle } from '../../../../components/generic/Styled';
import { LoadingCard } from '../../../../components/loading/LoadingCard';
-import { orderForwardChannels } from './helpers';
-import {
- ChannelTable,
- RouteTable,
- RouteType,
- ChannelType,
-} from './ForwardReportTables';
+import { ChannelTable, RouteTable } from './ForwardReportTables';
import { CardContent } from '.';
type Props = {
days: number;
- order: string;
};
const Spacing = styled.div`
margin-bottom: 16px;
`;
-export const ForwardChannelsReport = ({ days, order }: Props) => {
+export const ForwardChannelsReport = ({ days }: Props) => {
const [type, setType] = useState<'route' | 'incoming' | 'outgoing'>('route');
const { data, loading } = useGetForwardsQuery({
@@ -38,26 +30,27 @@ export const ForwardChannelsReport = ({ days, order }: Props) => {
onError: error => toast.error(getErrorContent(error)),
});
- if (!data?.getForwards || loading) {
+ if (loading) {
return ;
}
- const forwardArray = orderForwardChannels(
- type,
- order,
- data.getForwards as Forward[]
- );
+ if (!data?.getForwards.list.length) {
+ return null;
+ }
+
+ const renderContent = () => {
+ if (loading || !data?.getForwards.list.length) return null;
+ const { by_incoming, by_outgoing, by_route } = data.getForwards;
- const renderContent = (parsed: (ChannelType | RouteType)[]) => {
switch (type) {
case 'route':
- return (
-
- );
+ return ;
+ case 'incoming':
+ return ;
+ case 'outgoing':
+ return ;
default:
- return (
-
- );
+ return null;
}
};
@@ -103,14 +96,10 @@ export const ForwardChannelsReport = ({ days, order }: Props) => {
}
};
- if (forwardArray.length <= 0) {
- return null;
- }
-
return (
{renderTitle()}
- {renderContent(forwardArray)}
+ {renderContent()}
);
};
diff --git a/src/client/src/views/home/reports/forwardReport/ForwardReportTables.tsx b/src/client/src/views/home/reports/forwardReport/ForwardReportTables.tsx
index c8e43542..3637c903 100644
--- a/src/client/src/views/home/reports/forwardReport/ForwardReportTables.tsx
+++ b/src/client/src/views/home/reports/forwardReport/ForwardReportTables.tsx
@@ -1,5 +1,12 @@
import { FC } from 'react';
import Table from '../../../../components/table';
+import {
+ AggregatedChannelSideForwards,
+ AggregatedRouteForwards,
+} from '../../../../graphql/types';
+import { getNodeLink } from '../../../../components/generic/helpers';
+import { Price } from '../../../../components/price/Price';
+import { numberWithCommas } from '../../../../utils/number';
export type RouteType = {
route: string;
@@ -19,100 +26,92 @@ export type ChannelType = {
};
type RouteTableProps = {
- order: string;
- forwardArray: RouteType[];
+ forwardArray: AggregatedRouteForwards[];
};
type ChannelTableProps = {
- order: string;
- forwardArray: ChannelType[];
+ forwardArray: AggregatedChannelSideForwards[];
};
-export const RouteTable: FC = ({ order, forwardArray }) => {
- const getTitle = () => {
- switch (order) {
- case 'fee':
- return 'Fee (sats)';
- case 'tokens':
- return 'Amount (sats)';
- default:
- return 'Count';
- }
- };
-
- const getAccesor = () => {
- switch (order) {
- case 'fee':
- return 'fee';
- case 'tokens':
- return 'tokens';
- default:
- return 'amount';
- }
- };
-
+export const RouteTable: FC = ({ forwardArray }) => {
const columns = [
{
header: 'In',
accessorKey: 'incoming_alias',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ {getNodeLink(
+ row.original.incoming_channel_info.node2_info.public_key,
+ row.original.incoming_channel_info.node2_info.alias
+ )}
+
+ ),
},
{
header: 'Out',
accessorKey: 'outgoing_alias',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ {getNodeLink(
+ row.original.outgoing_channel_info.node2_info.public_key,
+ row.original.outgoing_channel_info.node2_info.alias
+ )}
+
+ ),
+ },
+ {
+ header: 'Count',
+ accessorKey: 'count',
+ cell: ({ row }: any) => numberWithCommas(row.original.count),
+ },
+ {
+ header: 'Fee (sats)',
+ accessorKey: 'fee',
+ cell: ({ row }: any) => ,
},
{
- header: getTitle(),
- accessorKey: getAccesor(),
- cell: ({ cell }: any) => cell.renderValue(),
+ header: 'Amount (sats)',
+ accessorKey: 'tokens',
+ cell: ({ row }: any) => ,
},
];
return ;
};
-export const ChannelTable: FC = ({
- order,
- forwardArray,
-}) => {
- const getTitle = () => {
- switch (order) {
- case 'fee':
- return 'Fee (sats)';
- case 'tokens':
- return 'Amount (sats)';
- default:
- return 'Count';
- }
- };
-
- const getAccesor = () => {
- switch (order) {
- case 'fee':
- return 'fee';
- case 'tokens':
- return 'tokens';
- default:
- return 'amount';
- }
- };
-
+export const ChannelTable: FC = ({ forwardArray }) => {
const columns = [
{
header: 'Alias',
accessorKey: 'alias',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => (
+
+ {getNodeLink(
+ row.original.channel_info.node2_info.public_key,
+ row.original.channel_info.node2_info.alias
+ )}
+
+ ),
},
{
header: 'Id',
accessorKey: 'name',
- cell: ({ cell }: any) => cell.renderValue(),
+ cell: ({ row }: any) => row.original.channel,
+ },
+ {
+ header: 'Count',
+ accessorKey: 'count',
+ cell: ({ row }: any) => numberWithCommas(row.original.count),
+ },
+ {
+ header: 'Fee (sats)',
+ accessorKey: 'fee',
+ cell: ({ row }: any) => ,
},
{
- header: getTitle(),
- accessorKey: getAccesor(),
- cell: ({ cell }: any) => cell.renderValue(),
+ header: 'Amount (sats)',
+ accessorKey: 'tokens',
+ cell: ({ row }: any) => ,
},
];
diff --git a/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx b/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx
index 6d47370e..6e8da9f6 100644
--- a/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx
+++ b/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx
@@ -1,10 +1,10 @@
import { FC, useMemo } from 'react';
-import { useGetBasicForwardsQuery } from '../../../../graphql/queries/__generated__/getForwards.generated';
import styled from 'styled-components';
import { differenceInDays } from 'date-fns';
import { Price } from '../../../../components/price/Price';
import { mediaWidths } from '../../../../styles/Themes';
import { DarkSubTitle } from '../../../../components/generic/Styled';
+import { useGetForwardsListQuery } from '../../../../graphql/queries/__generated__/getForwards.generated';
type ArrayType = { fee: number; fee_mtokens: string; tokens: number };
@@ -37,7 +37,7 @@ type ForwardResumeProps = {
};
export const ForwardResume: FC = ({ type }) => {
- const { data, loading } = useGetBasicForwardsQuery({
+ const { data, loading } = useGetForwardsListQuery({
ssr: false,
variables: { days: 365 },
errorPolicy: 'ignore',
@@ -48,7 +48,7 @@ export const ForwardResume: FC = ({ type }) => {
const week: ArrayType[] = [];
const month: ArrayType[] = [];
- const forwards = data?.getForwards || [];
+ const forwards = data?.getForwards.list || [];
if (!forwards.length) return { day: 0, week: 0, month: 0, year: 0 };
@@ -123,7 +123,7 @@ export const ForwardResume: FC = ({ type }) => {
}
const renderValue = (value: number) => {
- if (type.value === 'amount') {
+ if (type.value === 'count') {
return {value}
;
} else if (type.value === 'fee') {
return ;
diff --git a/src/client/src/views/home/reports/forwardReport/ForwardsGraph.tsx b/src/client/src/views/home/reports/forwardReport/ForwardsGraph.tsx
index 9cce5e5a..a6f6ab25 100644
--- a/src/client/src/views/home/reports/forwardReport/ForwardsGraph.tsx
+++ b/src/client/src/views/home/reports/forwardReport/ForwardsGraph.tsx
@@ -69,7 +69,7 @@ export const ForwardsGraph: FC = ({ days, type }) => {
);
}
- if (!data?.getForwards.length) {
+ if (!data?.getForwards.list.length) {
return (
No forwards for this period.
@@ -77,7 +77,7 @@ export const ForwardsGraph: FC = ({ days, type }) => {
);
}
- const forwards = getByTime(data.getForwards, days.value);
+ const forwards = getByTime(data.getForwards.list, days.value);
return (
diff --git a/src/client/src/views/home/reports/forwardReport/helpers.ts b/src/client/src/views/home/reports/forwardReport/helpers.ts
index 4305aae7..b51d6cec 100644
--- a/src/client/src/views/home/reports/forwardReport/helpers.ts
+++ b/src/client/src/views/home/reports/forwardReport/helpers.ts
@@ -1,164 +1,4 @@
-import { differenceInCalendarDays, differenceInHours, subDays } from 'date-fns';
-import { sortBy, groupBy } from 'lodash';
import { GetClosedChannelsQuery } from '../../../../graphql/queries/__generated__/getClosedChannels.generated';
-import { Forward } from '../../../../graphql/types';
-
-type ListProps = {
- [key: string]: Forward[];
-};
-
-export const reduceForwardArray = (list: ListProps) => {
- const reducedOrder = [];
- for (const key in list) {
- if (Object.prototype.hasOwnProperty.call(list, key)) {
- const element: Forward[] = list[key];
-
- const reducedArray = element.reduce(
- (prev, current) => {
- return {
- fee: (prev.fee || 0) + (current.fee || 0),
- tokens: (prev.tokens || 0) + (current.tokens || 0),
- };
- },
- {
- fee: 0,
- tokens: 0,
- }
- );
-
- reducedOrder.push({
- period: Number(key),
- amount: element.length,
- ...reducedArray,
- });
- }
- }
-
- return reducedOrder;
-};
-
-export const orderAndReducedArray = (time: number, forwardArray: Forward[]) => {
- const endDate = subDays(new Date(), time);
- const filtered = forwardArray.filter(Boolean);
-
- if (time === 1) {
- const orderedHour = groupBy(filtered, item =>
- differenceInHours(new Date(item.created_at), endDate)
- );
-
- const reducedOrderedHour = reduceForwardArray(orderedHour);
-
- return reducedOrderedHour;
- }
-
- const orderedDay = groupBy(filtered, item =>
- differenceInCalendarDays(new Date(item.created_at), endDate)
- );
-
- const reducedOrderedDay = reduceForwardArray(orderedDay);
-
- return reducedOrderedDay;
-};
-
-const countRoutes = (list: Forward[]) => {
- const grouped = groupBy(list, 'route');
-
- const channelInfo = [];
- for (const key in grouped) {
- if (Object.prototype.hasOwnProperty.call(grouped, key)) {
- const element = grouped[key];
-
- const fee = element
- .map(forward => forward.fee)
- .reduce((p: number, c: number) => p + c);
-
- const tokens = element
- .map(forward => forward.tokens)
- .reduce((p: number, c: number) => p + c);
-
- channelInfo.push({
- incoming_alias:
- element[0].incoming_channel_info?.node2_info.alias || 'Unknown',
- outgoing_alias:
- element[0].outgoing_channel_info?.node2_info.alias || 'Unknown',
- incoming_channel: element[0].incoming_channel,
- outgoing_channel: element[0].outgoing_channel,
- route: key,
- amount: element.length,
- fee,
- tokens,
- });
- }
- }
-
- return channelInfo;
-};
-
-const countArray = (list: Forward[], type: boolean) => {
- const inOrOut = type ? 'incoming_channel' : 'outgoing_channel';
- const grouped = groupBy(list, inOrOut);
-
- const channelInfo = [];
- for (const key in grouped) {
- if (Object.prototype.hasOwnProperty.call(grouped, key)) {
- const element = grouped[key];
-
- const fee = element
- .map(forward => forward.fee)
- .reduce((p: number, c: number) => p + c);
-
- const tokens = element
- .map(forward => forward.tokens)
- .reduce((p: number, c: number) => p + c);
-
- const channelId = type
- ? element[0].incoming_channel
- : element[0].outgoing_channel;
-
- const alias = type
- ? element[0].incoming_channel_info?.node2_info.alias || 'Unknown'
- : element[0].outgoing_channel_info?.node2_info.alias || 'Unknown';
-
- channelInfo.push({
- alias,
- channelId,
- name: key,
- amount: element.length,
- fee,
- tokens,
- });
- }
- }
-
- return channelInfo;
-};
-
-export const orderForwardChannels = (
- type: string,
- order: string,
- forwardArray: Forward[]
-) => {
- if (type === 'route') {
- const mapped = forwardArray.map(forward => {
- return {
- route: `${forward.incoming_channel} - ${forward.outgoing_channel}`,
- ...forward,
- };
- });
- const grouped = countRoutes(mapped);
-
- const sortedRoute = sortBy(grouped, order).reverse().slice(0, 10);
- return sortedRoute;
- }
- if (type === 'incoming') {
- const incomingCount = countArray(forwardArray, true);
- const sortedInCount = sortBy(incomingCount, order).reverse().slice(0, 10);
- return sortedInCount;
- }
- const outgoingCount = countArray(forwardArray, false);
- const sortedOutCount = sortBy(outgoingCount, order).reverse().slice(0, 10);
- return sortedOutCount;
-};
export const getAliasFromClosedChannels = (
channelId: string,
diff --git a/src/client/src/views/home/reports/forwardReport/index.tsx b/src/client/src/views/home/reports/forwardReport/index.tsx
index 25a42301..c519feec 100644
--- a/src/client/src/views/home/reports/forwardReport/index.tsx
+++ b/src/client/src/views/home/reports/forwardReport/index.tsx
@@ -6,7 +6,6 @@ import {
SubTitle,
Card,
CardTitle,
- Separation,
} from '../../../../components/generic/Styled';
import { mediaWidths } from '../../../../styles/Themes';
import { ForwardChannelsReport } from './ForwardChannelReport';
@@ -43,7 +42,7 @@ export const options = [
];
export const typeOptions = [
- { label: 'Count', value: 'amount' },
+ { label: 'Count', value: 'count' },
{ label: 'Amount', value: 'tokens' },
{ label: 'Fees', value: 'fee' },
];
@@ -72,11 +71,11 @@ export const ForwardBox = () => {
-
-
-
-
+
+
+
+