diff --git a/src/widgets/ghostfolio/component.jsx b/src/widgets/ghostfolio/component.jsx index d6314991..7a56ae0b 100644 --- a/src/widgets/ghostfolio/component.jsx +++ b/src/widgets/ghostfolio/component.jsx @@ -1,45 +1,41 @@ +import { useTranslation } from "next-i18next"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; 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 }) { - // const { t } = useTranslation(); - + const { t } = useTranslation(); const { widget } = service; 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", { refreshInterval: 36000 }); - const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max", { refreshInterval: 36000 }); + const { data: performanceYear, error: ghostfolioErrorYear } = useWidgetAPI(widget, "year"); + const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max"); - if (ghostfolioErrorToday) { - return ; + if (ghostfolioErrorToday || ghostfolioErrorYear || ghostfolioErrorMax) { + const finalError = ghostfolioErrorToday ?? ghostfolioErrorYear ?? ghostfolioErrorMax + return ; } - if (ghostfolioErrorYtd) { - return ; - } - - if (ghostfolioErrorYear) { - return ; - } - - if (ghostfolioErrorMax) { - return ; + if (!performanceToday || !performanceYear || !performanceMax) { + return ( + + + + + + ); } return ( - {/* - - - */} - 0 ? "+" : "")}${(Math.round(performanceToday.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} /> - 0 ? "+" : "")}${(Math.round(performanceYtd.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} /> - 0 ? "+" : "")}${(Math.round(performanceYear.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} /> - 0 ? "+" : "")}${(Math.round(performanceMax.performance.currentGrossPerformancePercent * 10000) / 100)}%` || false} /> + + + ); } diff --git a/src/widgets/ghostfolio/widget.js b/src/widgets/ghostfolio/widget.js index 1c790474..a084d8f4 100644 --- a/src/widgets/ghostfolio/widget.js +++ b/src/widgets/ghostfolio/widget.js @@ -8,9 +8,6 @@ const widget = { today: { endpoint: "1d" }, - ytd: { - endpoint: "ytd" - }, year: { endpoint: "1y" },