From 365a21b203f2510910a433f17a4ca1a2e1bc0b62 Mon Sep 17 00:00:00 2001 From: Yevhen Baidiuk Date: Sun, 5 Nov 2023 15:37:21 +0100 Subject: [PATCH] Bug fix/consider microsats,add year (#575) * consider mSats * add year * fix NaN bug. --- src/client/src/utils/helpers.tsx | 2 +- src/client/src/views/forwards/index.tsx | 2 +- .../reports/forwardReport/ForwardResume.tsx | 43 +++++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/client/src/utils/helpers.tsx b/src/client/src/utils/helpers.tsx index ce96b5b2..3198dee3 100644 --- a/src/client/src/utils/helpers.tsx +++ b/src/client/src/utils/helpers.tsx @@ -93,7 +93,7 @@ export const getValue = ({ ); } - const amountInFiat = (value / 100000000) * price; + const amountInFiat = ((value / 100000000) * price).toFixed(2); return noUnit ? ( numeral(amountInFiat).format('0,0.00') ) : ( diff --git a/src/client/src/views/forwards/index.tsx b/src/client/src/views/forwards/index.tsx index 4ecc8a20..eafb4974 100644 --- a/src/client/src/views/forwards/index.tsx +++ b/src/client/src/views/forwards/index.tsx @@ -58,7 +58,7 @@ export const ForwardsList: FC = ({ days }) => { accessorKey: 'fee', 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 c16ca4b9..6d47370e 100644 --- a/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx +++ b/src/client/src/views/home/reports/forwardReport/ForwardResume.tsx @@ -6,13 +6,13 @@ import { Price } from '../../../../components/price/Price'; import { mediaWidths } from '../../../../styles/Themes'; import { DarkSubTitle } from '../../../../components/generic/Styled'; -type ArrayType = { fee: number; tokens: number }; +type ArrayType = { fee: number; fee_mtokens: string; tokens: number }; const S = { grid: styled.div` display: grid; grid-gap: 16px; - grid-template-columns: 1fr 1fr 1fr; + grid-template-columns: 1fr 1fr 1fr 1fr; @media (${mediaWidths.mobile}) { display: block; @@ -39,17 +39,18 @@ type ForwardResumeProps = { export const ForwardResume: FC = ({ type }) => { const { data, loading } = useGetBasicForwardsQuery({ ssr: false, - variables: { days: 30 }, + variables: { days: 365 }, errorPolicy: 'ignore', }); const values = useMemo(() => { const day: ArrayType[] = []; const week: ArrayType[] = []; + const month: ArrayType[] = []; const forwards = data?.getForwards || []; - if (!forwards.length) return { day: 0, week: 0, month: 0 }; + if (!forwards.length) return { day: 0, week: 0, month: 0, year: 0 }; const today = new Date(); @@ -63,12 +64,15 @@ export const ForwardResume: FC = ({ type }) => { if (differenceInDays(today, forwardDate) < 7) { week.push(f); } + if (differenceInDays(today, forwardDate) < 30) { + month.push(f); + } }); const dayValue = day.reduce((p, c) => { if (!c) return p; if (type.value === 'fee') { - return p + c.fee; + return p + Number.parseInt(c.fee_mtokens); } if (type.value === 'tokens') { return p + c.tokens; @@ -78,17 +82,27 @@ export const ForwardResume: FC = ({ type }) => { const weekValue = week.reduce((p, c) => { if (!c) return p; if (type.value === 'fee') { - return p + c.fee; + return p + Number.parseInt(c.fee_mtokens); } if (type.value === 'tokens') { return p + c.tokens; } return p + 1; }, 0); - const monthValue = forwards.reduce((p, c) => { + const monthValue = month.reduce((p, c) => { if (!c) return p; if (type.value === 'fee') { - return p + c.fee; + return p + Number.parseInt(c.fee_mtokens); + } + if (type.value === 'tokens') { + return p + c.tokens; + } + return p + 1; + }, 0); + const yearValue = forwards.reduce((p, c) => { + if (!c) return p; + if (type.value === 'fee') { + return p + Number.parseInt(c.fee_mtokens); } if (type.value === 'tokens') { return p + c.tokens; @@ -96,7 +110,12 @@ export const ForwardResume: FC = ({ type }) => { return p + 1; }, 0); - return { day: dayValue, week: weekValue, month: monthValue }; + return { + day: dayValue, + week: weekValue, + month: monthValue, + year: yearValue, + }; }, [data, type]); if (loading) { @@ -106,6 +125,8 @@ export const ForwardResume: FC = ({ type }) => { const renderValue = (value: number) => { if (type.value === 'amount') { return
{value}
; + } else if (type.value === 'fee') { + return ; } return ; }; @@ -124,6 +145,10 @@ export const ForwardResume: FC = ({ type }) => { Month {renderValue(values.month)} + + Year + {renderValue(values.year)} + ); };