Enhancement: add net worth field for ghostfolio (#5958)

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
qmph22
2025-11-12 19:31:55 -05:00
committed by GitHub
parent 1a21189643
commit 17c9b2631e
4 changed files with 22 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ See the [official docs](https://github.com/ghostfolio/ghostfolio#authorization-b
_Note that the Bearer token is valid for 6 months, after which a new one must be generated._ _Note that the Bearer token is valid for 6 months, after which a new one must be generated._
Allowed fields: `["gross_percent_today", "gross_percent_1y", "gross_percent_max"]` Allowed fields: `["gross_percent_today", "gross_percent_1y", "gross_percent_max", "net_worth"]`
```yaml ```yaml
widget: widget:

View File

@@ -759,7 +759,8 @@
"ghostfolio": { "ghostfolio": {
"gross_percent_today": "Today", "gross_percent_today": "Today",
"gross_percent_1y": "One year", "gross_percent_1y": "One year",
"gross_percent_max": "All time" "gross_percent_max": "All time",
"net_worth": "Net Worth"
}, },
"audiobookshelf": { "audiobookshelf": {
"podcasts": "Podcasts", "podcasts": "Podcasts",

View File

@@ -20,13 +20,15 @@ function getPerformancePercent(t, performanceRange) {
export default function Component({ service }) { export default function Component({ service }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { widget } = service; const { widget } = service;
const includeNetWorth = widget.fields?.includes("net_worth");
const { data: performanceToday, error: ghostfolioErrorToday } = useWidgetAPI(widget, "today"); const { data: performanceToday, error: ghostfolioErrorToday } = useWidgetAPI(widget, "today");
const { data: performanceYear, error: ghostfolioErrorYear } = useWidgetAPI(widget, "year"); const { data: performanceYear, error: ghostfolioErrorYear } = useWidgetAPI(widget, "year");
const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max"); const { data: performanceMax, error: ghostfolioErrorMax } = useWidgetAPI(widget, "max");
const { data: userInfo, error: ghostfolioErrorUserInfo } = useWidgetAPI(widget, includeNetWorth ? "userInfo" : "");
if (ghostfolioErrorToday || ghostfolioErrorYear || ghostfolioErrorMax) { if (ghostfolioErrorToday || ghostfolioErrorYear || ghostfolioErrorMax || ghostfolioErrorUserInfo) {
const finalError = ghostfolioErrorToday ?? ghostfolioErrorYear ?? ghostfolioErrorMax; const finalError = ghostfolioErrorToday ?? ghostfolioErrorYear ?? ghostfolioErrorMax ?? ghostfolioErrorUserInfo;
return <Container service={service} error={finalError} />; return <Container service={service} error={finalError} />;
} }
@@ -34,12 +36,13 @@ export default function Component({ service }) {
return <Container service={service} error={performanceToday} />; return <Container service={service} error={performanceToday} />;
} }
if (!performanceToday || !performanceYear || !performanceMax) { if (!performanceToday || !performanceYear || !performanceMax || (includeNetWorth && !userInfo)) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="ghostfolio.gross_percent_today" /> <Block label="ghostfolio.gross_percent_today" />
<Block label="ghostfolio.gross_percent_1y" /> <Block label="ghostfolio.gross_percent_1y" />
<Block label="ghostfolio.gross_percent_max" /> <Block label="ghostfolio.gross_percent_max" />
{includeNetWorth && <Block label="ghostfolio.net_worth" />}
</Container> </Container>
); );
} }
@@ -49,6 +52,12 @@ export default function Component({ service }) {
<Block label="ghostfolio.gross_percent_today" value={getPerformancePercent(t, performanceToday)} /> <Block label="ghostfolio.gross_percent_today" value={getPerformancePercent(t, performanceToday)} />
<Block label="ghostfolio.gross_percent_1y" value={getPerformancePercent(t, performanceYear)} /> <Block label="ghostfolio.gross_percent_1y" value={getPerformancePercent(t, performanceYear)} />
<Block label="ghostfolio.gross_percent_max" value={getPerformancePercent(t, performanceMax)} /> <Block label="ghostfolio.gross_percent_max" value={getPerformancePercent(t, performanceMax)} />
{includeNetWorth && (
<Block
label="ghostfolio.net_worth"
value={`${performanceToday.performance.currentNetWorth.toFixed(2)} ${userInfo?.settings?.currency ?? ""}`}
/>
)}
</Container> </Container>
); );
} }

View File

@@ -1,18 +1,21 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = { const widget = {
api: "{url}/api/v2/portfolio/performance?range={endpoint}", api: "{url}/api/{endpoint}",
proxyHandler: credentialedProxyHandler, proxyHandler: credentialedProxyHandler,
mappings: { mappings: {
today: { today: {
endpoint: "1d", endpoint: "v2/portfolio/performance?range=1d",
}, },
year: { year: {
endpoint: "1y", endpoint: "v2/portfolio/performance?range=1y",
}, },
max: { max: {
endpoint: "max", endpoint: "v2/portfolio/performance?range=max",
},
userInfo: {
endpoint: "v1/user",
}, },
}, },
}; };