refactor!: support RUB only (WealthLedger/main#55) (#168)
This commit was merged in pull request #168.
This commit is contained in:
@@ -34,10 +34,10 @@ type BrokerageAccountSummaryProps = {
|
||||
type PortfolioSummary = AvailableSummary["portfolio"];
|
||||
|
||||
type ReturnValueProps = {
|
||||
item: PortfolioSummary["unrealizedReturnByCurrency"][number];
|
||||
item: PortfolioSummary["unrealizedReturn"];
|
||||
};
|
||||
|
||||
type StructureCurrency = PortfolioSummary["structure"]["currencies"][number];
|
||||
type StructureCurrency = PortfolioSummary["structure"];
|
||||
|
||||
function formatPercent(value: null | string) {
|
||||
if (value === null) return "—";
|
||||
@@ -81,7 +81,7 @@ const ReturnValue: FC<ReturnValueProps> = (props) => {
|
||||
|
||||
<Text className={toneClass} size="sm">
|
||||
{formatMoney(
|
||||
{ currency: item.currency, value: item.absolute },
|
||||
{ currency: "RUB", value: item.absolute },
|
||||
{ withSign: true },
|
||||
)}
|
||||
</Text>
|
||||
@@ -119,7 +119,6 @@ const StructureBar: FC<StructureBarProps> = (props) => {
|
||||
}).join("; ");
|
||||
|
||||
const label = t("accounts.structure.label", {
|
||||
currency: props.item.currency,
|
||||
value: description,
|
||||
});
|
||||
|
||||
@@ -197,50 +196,24 @@ const BrokerageAccountSummary: FC<BrokerageAccountSummaryProps> = (props) => {
|
||||
return (
|
||||
<Stack className={classes.balance} gap="xs">
|
||||
<Stack className={classes.summary} gap="sm">
|
||||
{summary.totals.map((total) => {
|
||||
const item = summary.portfolio.unrealizedReturnByCurrency.find(
|
||||
returnItem => returnItem.currency === total.currency,
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack
|
||||
className={classes.currencySummary}
|
||||
gap={2}
|
||||
key={total.currency}
|
||||
>
|
||||
<Text className={classes.total} fw={700}>
|
||||
{formatMoney(total, { withRoundedCents: true })}
|
||||
</Text>
|
||||
|
||||
{item && <ReturnValue item={item} />}
|
||||
</Stack>
|
||||
);
|
||||
})}
|
||||
|
||||
{!!summary.remainingCurrencyCount && (
|
||||
<Text c="dimmed" size="sm">
|
||||
{t("accounts.remainingCurrencies", {
|
||||
count: summary.remainingCurrencyCount,
|
||||
})}
|
||||
<Stack className={classes.currencySummary} gap={2}>
|
||||
<Text className={classes.total} fw={700}>
|
||||
{formatMoney(summary.totals, { withRoundedCents: true })}
|
||||
</Text>
|
||||
)}
|
||||
|
||||
<ReturnValue item={summary.portfolio.unrealizedReturn} />
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
{summary.portfolio.cashBalances.length > 0 && (
|
||||
<Group className={classes.cash} gap="xs" justify="flex-end">
|
||||
<Text c="dimmed" size="xs">
|
||||
{t("accounts.cash")}
|
||||
</Text>
|
||||
<Group className={classes.cash} gap="xs" justify="flex-end">
|
||||
<Text c="dimmed" size="xs">
|
||||
{t("accounts.cash")}
|
||||
</Text>
|
||||
|
||||
<Stack gap={0}>
|
||||
{summary.portfolio.cashBalances.map(cash => (
|
||||
<Text className={classes.cashValue} key={cash.currency} size="sm">
|
||||
{formatMoney(cash, { withRoundedCents: true })}
|
||||
</Text>
|
||||
))}
|
||||
</Stack>
|
||||
</Group>
|
||||
)}
|
||||
<Text className={classes.cashValue} size="sm">
|
||||
{formatMoney(summary.portfolio.cash, { withRoundedCents: true })}
|
||||
</Text>
|
||||
</Group>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -287,39 +260,31 @@ const AccountDescription: FC<AccountDescriptionProps> = (props) => {
|
||||
const { account, summary } = props.account;
|
||||
if (summary.state !== "available") return null;
|
||||
|
||||
const returns = summary.portfolio.unrealizedReturnByCurrency.map(item =>
|
||||
t("accounts.description.return", {
|
||||
absolute: formatMoney(
|
||||
{ currency: item.currency, value: item.absolute },
|
||||
{ withSign: true },
|
||||
),
|
||||
currency: item.currency,
|
||||
percent: formatPercent(item.percent),
|
||||
}),
|
||||
);
|
||||
const returns = [t("accounts.description.return", {
|
||||
absolute: formatMoney(
|
||||
{ currency: "RUB", value: summary.portfolio.unrealizedReturn.absolute },
|
||||
{ withSign: true },
|
||||
),
|
||||
percent: formatPercent(summary.portfolio.unrealizedReturn.percent),
|
||||
})];
|
||||
|
||||
const structures = summary.portfolio.structure.currencies.map((item) => {
|
||||
const categories = item.categories.map(category =>
|
||||
const structures = (() => {
|
||||
const categories = summary.portfolio.structure.categories.map(category =>
|
||||
t("accounts.description.structureCategory", {
|
||||
category: t(portfolioCategoryPresentation[category.type].label),
|
||||
value: formatMoney(
|
||||
{ currency: item.currency, value: category.value },
|
||||
{ currency: "RUB", value: category.value },
|
||||
{ withRoundedCents: true },
|
||||
),
|
||||
}),
|
||||
).join(", ");
|
||||
|
||||
return t("accounts.description.structure", {
|
||||
currency: item.currency,
|
||||
value: categories,
|
||||
});
|
||||
});
|
||||
return t("accounts.description.structure", { value: categories });
|
||||
})();
|
||||
|
||||
const hasPartialReturn = summary.portfolio.unrealizedReturnByCurrency.some(
|
||||
item => item.partial,
|
||||
);
|
||||
const hasPartialReturn = summary.portfolio.unrealizedReturn.partial;
|
||||
|
||||
const details = [...returns, ...structures].join(". ");
|
||||
const details = [returns, structures].join(". ");
|
||||
|
||||
return (
|
||||
<VisuallyHidden>
|
||||
@@ -328,8 +293,7 @@ const AccountDescription: FC<AccountDescriptionProps> = (props) => {
|
||||
type: t(accountTypeKey(account.type)),
|
||||
})}
|
||||
{t("accounts.description.currentValue", {
|
||||
value: summary.portfolio.totalsByCurrency
|
||||
.map(total => formatMoney(total)).join(", "),
|
||||
value: formatMoney(summary.portfolio.totals),
|
||||
})}
|
||||
{details ? `${details}. ` : ""}
|
||||
{hasPartialReturn ? t("accounts.brokerDescription") : ""}
|
||||
@@ -369,9 +333,7 @@ const BrokerageAccountList: FC<BrokerageAccountListProps> = (props) => {
|
||||
|
||||
{summary.state === "available" && (
|
||||
<Stack className={classes.structure} gap={4}>
|
||||
{summary.portfolio.structure.currencies.map(item => (
|
||||
<StructureBar item={item} key={item.currency} />
|
||||
))}
|
||||
<StructureBar item={summary.portfolio.structure} />
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user