mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 22:25:21 +01:00
Bug fix/consider microsats,add year (#575)
* consider mSats * add year * fix NaN bug.
This commit is contained in:
parent
06f211edb7
commit
365a21b203
3 changed files with 36 additions and 11 deletions
|
@ -93,7 +93,7 @@ export const getValue = ({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountInFiat = (value / 100000000) * price;
|
const amountInFiat = ((value / 100000000) * price).toFixed(2);
|
||||||
return noUnit ? (
|
return noUnit ? (
|
||||||
numeral(amountInFiat).format('0,0.00')
|
numeral(amountInFiat).format('0,0.00')
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -58,7 +58,7 @@ export const ForwardsList: FC<ForwardProps> = ({ days }) => {
|
||||||
accessorKey: 'fee',
|
accessorKey: 'fee',
|
||||||
cell: ({ row }: any) => (
|
cell: ({ row }: any) => (
|
||||||
<div style={{ whiteSpace: 'nowrap' }}>
|
<div style={{ whiteSpace: 'nowrap' }}>
|
||||||
<Price amount={row.original.fee} />
|
<Price amount={row.original.fee_mtokens / 1000} />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,13 +6,13 @@ import { Price } from '../../../../components/price/Price';
|
||||||
import { mediaWidths } from '../../../../styles/Themes';
|
import { mediaWidths } from '../../../../styles/Themes';
|
||||||
import { DarkSubTitle } from '../../../../components/generic/Styled';
|
import { DarkSubTitle } from '../../../../components/generic/Styled';
|
||||||
|
|
||||||
type ArrayType = { fee: number; tokens: number };
|
type ArrayType = { fee: number; fee_mtokens: string; tokens: number };
|
||||||
|
|
||||||
const S = {
|
const S = {
|
||||||
grid: styled.div`
|
grid: styled.div`
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: 16px;
|
grid-gap: 16px;
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
|
|
||||||
@media (${mediaWidths.mobile}) {
|
@media (${mediaWidths.mobile}) {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -39,17 +39,18 @@ type ForwardResumeProps = {
|
||||||
export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
const { data, loading } = useGetBasicForwardsQuery({
|
const { data, loading } = useGetBasicForwardsQuery({
|
||||||
ssr: false,
|
ssr: false,
|
||||||
variables: { days: 30 },
|
variables: { days: 365 },
|
||||||
errorPolicy: 'ignore',
|
errorPolicy: 'ignore',
|
||||||
});
|
});
|
||||||
|
|
||||||
const values = useMemo(() => {
|
const values = useMemo(() => {
|
||||||
const day: ArrayType[] = [];
|
const day: ArrayType[] = [];
|
||||||
const week: ArrayType[] = [];
|
const week: ArrayType[] = [];
|
||||||
|
const month: ArrayType[] = [];
|
||||||
|
|
||||||
const forwards = data?.getForwards || [];
|
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();
|
const today = new Date();
|
||||||
|
|
||||||
|
@ -63,12 +64,15 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
if (differenceInDays(today, forwardDate) < 7) {
|
if (differenceInDays(today, forwardDate) < 7) {
|
||||||
week.push(f);
|
week.push(f);
|
||||||
}
|
}
|
||||||
|
if (differenceInDays(today, forwardDate) < 30) {
|
||||||
|
month.push(f);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const dayValue = day.reduce((p, c) => {
|
const dayValue = day.reduce((p, c) => {
|
||||||
if (!c) return p;
|
if (!c) return p;
|
||||||
if (type.value === 'fee') {
|
if (type.value === 'fee') {
|
||||||
return p + c.fee;
|
return p + Number.parseInt(c.fee_mtokens);
|
||||||
}
|
}
|
||||||
if (type.value === 'tokens') {
|
if (type.value === 'tokens') {
|
||||||
return p + c.tokens;
|
return p + c.tokens;
|
||||||
|
@ -78,17 +82,27 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
const weekValue = week.reduce((p, c) => {
|
const weekValue = week.reduce((p, c) => {
|
||||||
if (!c) return p;
|
if (!c) return p;
|
||||||
if (type.value === 'fee') {
|
if (type.value === 'fee') {
|
||||||
return p + c.fee;
|
return p + Number.parseInt(c.fee_mtokens);
|
||||||
}
|
}
|
||||||
if (type.value === 'tokens') {
|
if (type.value === 'tokens') {
|
||||||
return p + c.tokens;
|
return p + c.tokens;
|
||||||
}
|
}
|
||||||
return p + 1;
|
return p + 1;
|
||||||
}, 0);
|
}, 0);
|
||||||
const monthValue = forwards.reduce((p, c) => {
|
const monthValue = month.reduce((p, c) => {
|
||||||
if (!c) return p;
|
if (!c) return p;
|
||||||
if (type.value === 'fee') {
|
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') {
|
if (type.value === 'tokens') {
|
||||||
return p + c.tokens;
|
return p + c.tokens;
|
||||||
|
@ -96,7 +110,12 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
return p + 1;
|
return p + 1;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
return { day: dayValue, week: weekValue, month: monthValue };
|
return {
|
||||||
|
day: dayValue,
|
||||||
|
week: weekValue,
|
||||||
|
month: monthValue,
|
||||||
|
year: yearValue,
|
||||||
|
};
|
||||||
}, [data, type]);
|
}, [data, type]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
@ -106,6 +125,8 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
const renderValue = (value: number) => {
|
const renderValue = (value: number) => {
|
||||||
if (type.value === 'amount') {
|
if (type.value === 'amount') {
|
||||||
return <div>{value}</div>;
|
return <div>{value}</div>;
|
||||||
|
} else if (type.value === 'fee') {
|
||||||
|
return <Price amount={Math.floor(value / 1000)} />;
|
||||||
}
|
}
|
||||||
return <Price amount={value} />;
|
return <Price amount={value} />;
|
||||||
};
|
};
|
||||||
|
@ -124,6 +145,10 @@ export const ForwardResume: FC<ForwardResumeProps> = ({ type }) => {
|
||||||
<DarkSubTitle>Month</DarkSubTitle>
|
<DarkSubTitle>Month</DarkSubTitle>
|
||||||
{renderValue(values.month)}
|
{renderValue(values.month)}
|
||||||
</S.item>
|
</S.item>
|
||||||
|
<S.item>
|
||||||
|
<DarkSubTitle>Year</DarkSubTitle>
|
||||||
|
{renderValue(values.year)}
|
||||||
|
</S.item>
|
||||||
</S.grid>
|
</S.grid>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue