Skip to content

Commit

Permalink
Bug fix/consider microsats,add year (#575)
Browse files Browse the repository at this point in the history
* consider mSats

* add year

* fix NaN bug.
  • Loading branch information
ybaidiuk authored Nov 5, 2023
1 parent 06f211e commit 365a21b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/client/src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/views/forwards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ForwardsList: FC<ForwardProps> = ({ days }) => {
accessorKey: 'fee',
cell: ({ row }: any) => (
<div style={{ whiteSpace: 'nowrap' }}>
<Price amount={row.original.fee} />
<Price amount={row.original.fee_mtokens / 1000} />
</div>
),
},
Expand Down
43 changes: 34 additions & 9 deletions src/client/src/views/home/reports/forwardReport/ForwardResume.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,17 +39,18 @@ type ForwardResumeProps = {
export const ForwardResume: FC<ForwardResumeProps> = ({ 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();

Expand All @@ -63,12 +64,15 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ 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;
Expand All @@ -78,25 +82,40 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ 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;
}
return p + 1;
}, 0);

return { day: dayValue, week: weekValue, month: monthValue };
return {
day: dayValue,
week: weekValue,
month: monthValue,
year: yearValue,
};
}, [data, type]);

if (loading) {
Expand All @@ -106,6 +125,8 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
const renderValue = (value: number) => {
if (type.value === 'amount') {
return <div>{value}</div>;
} else if (type.value === 'fee') {
return <Price amount={Math.floor(value / 1000)} />;
}
return <Price amount={value} />;
};
Expand All @@ -124,6 +145,10 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
<DarkSubTitle>Month</DarkSubTitle>
{renderValue(values.month)}
</S.item>
<S.item>
<DarkSubTitle>Year</DarkSubTitle>
{renderValue(values.year)}
</S.item>
</S.grid>
);
};

0 comments on commit 365a21b

Please sign in to comment.