mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-21 05:16:20 +01:00
simplify ghostfolio widget
This commit is contained in:
parent
e97fdc17be
commit
e11589f52e
@ -1,45 +1,41 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import Container from "components/services/widget/container";
|
import Container from "components/services/widget/container";
|
||||||
import Block from "components/services/widget/block";
|
import Block from "components/services/widget/block";
|
||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
// import { useTranslation } from "next-i18next";
|
|
||||||
|
function getPerformancePercent(t, performanceRange) {
|
||||||
|
return `${(performanceRange.performance.currentGrossPerformancePercent > 0 ? "+" : "")}${t("common.percent", { value: performanceRange.performance.currentGrossPerformancePercent * 100, maximumFractionDigits: 2 })}`
|
||||||
|
}
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
// const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: performanceToday, error: ghostfolioErrorToday } = useWidgetAPI(widget, "today");
|
const { data: performanceToday, error: ghostfolioErrorToday } = useWidgetAPI(widget, "today");
|
||||||
const { data: performanceYtd, error: ghostfolioErrorYtd } = useWidgetAPI(widget, "ytd", { refreshInterval: 36000 });
|
const { data: performanceYear, error: ghostfolioErrorYear } = useWidgetAPI(widget, "year");
|
||||||
const { data: performanceYear, error: ghostfolioErrorYear } = useWidgetAPI(widget, "year", { refreshInterval: 36000 });
|
const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max");
|
||||||
const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max", { refreshInterval: 36000 });
|
|
||||||
|
|
||||||
if (ghostfolioErrorToday) {
|
if (ghostfolioErrorToday || ghostfolioErrorYear || ghostfolioErrorMax) {
|
||||||
return <Container error={ghostfolioErrorToday} />;
|
const finalError = ghostfolioErrorToday ?? ghostfolioErrorYear ?? ghostfolioErrorMax
|
||||||
|
return <Container error={finalError} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ghostfolioErrorYtd) {
|
if (!performanceToday || !performanceYear || !performanceMax) {
|
||||||
return <Container error={ghostfolioErrorYtd} />;
|
return (
|
||||||
}
|
<Container service={service}>
|
||||||
|
<Block label="ghostfolio.gross_percent_today" />
|
||||||
if (ghostfolioErrorYear) {
|
<Block label="ghostfolio.gross_percent_1y" />
|
||||||
return <Container error={ghostfolioErrorYear} />;
|
<Block label="ghostfolio.gross_percent_max" />
|
||||||
}
|
</Container>
|
||||||
|
);
|
||||||
if (ghostfolioErrorMax) {
|
|
||||||
return <Container error={ghostfolioErrorMax} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
{/* <Block label="ghostfolio.gross_percent_today" value={performanceToday && t("common.percent", { value: Math.round(performanceToday.performance.currentGrossPerformancePercent * 10000) / 100 }) || false} />
|
<Block label="ghostfolio.gross_percent_today" value={getPerformancePercent(t, performanceToday)} />
|
||||||
<Block label="ghostfolio.gross_percent_ytd" value={performanceYtd && t("common.percent", { value: Math.round(performanceYtd.performance.currentGrossPerformancePercent * 10000) / 100 }) || false} />
|
<Block label="ghostfolio.gross_percent_1y" value={getPerformancePercent(t, performanceYear)} />
|
||||||
<Block label="ghostfolio.gross_percent_1y" value={performanceYear && t("common.percent", { value: Math.round(performanceYear.performance.currentGrossPerformancePercent * 10000) / 100 }) || false} />
|
<Block label="ghostfolio.gross_percent_max" value={getPerformancePercent(t, performanceMax)} />
|
||||||
<Block label="ghostfolio.gross_percent_max" value={performanceMax && t("common.percent", { value: Math.round(performanceMax.performance.currentGrossPerformancePercent * 10000) / 100 }) || false} /> */}
|
|
||||||
<Block label="ghostfolio.gross_percent_today" value={performanceToday && `${(performanceToday.performance.currentGrossPerformancePercent > 0 ? "+" : "")}${(Math.round(performanceToday.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} />
|
|
||||||
<Block label="ghostfolio.gross_percent_ytd" value={performanceYtd && `${(performanceYtd.performance.currentGrossPerformancePercent > 0 ? "+" : "")}${(Math.round(performanceYtd.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} />
|
|
||||||
<Block label="ghostfolio.gross_percent_1y" value={performanceYear && `${(performanceYear.performance.currentGrossPerformancePercent > 0 ? "+" : "")}${(Math.round(performanceYear.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} />
|
|
||||||
<Block label="ghostfolio.gross_percent_max" value={performanceMax && `${(performanceMax.performance.currentGrossPerformancePercent > 0 ? "+" : "")}${(Math.round(performanceMax.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} />
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ const widget = {
|
|||||||
today: {
|
today: {
|
||||||
endpoint: "1d"
|
endpoint: "1d"
|
||||||
},
|
},
|
||||||
ytd: {
|
|
||||||
endpoint: "ytd"
|
|
||||||
},
|
|
||||||
year: {
|
year: {
|
||||||
endpoint: "1y"
|
endpoint: "1y"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user