refactor!: support RUB only (WealthLedger/main#55)
Adopt RUB-only API contract; remove currency cards, selectors, screener currency filter and multi-currency branches. BREAKING CHANGE: requires the RUB-only backend contract.
This commit is contained in:
@@ -25,34 +25,16 @@ type AccountsPageLoadedProps = {
|
||||
readRetry?: ReadRetryProps;
|
||||
};
|
||||
|
||||
type Money = { currency: string; value: string };
|
||||
|
||||
function accountTotals(accounts: BrokerageAccountCard[]) {
|
||||
const values = new Map<string, string[]>();
|
||||
let excludedCount = 0;
|
||||
function accountTotals(accounts: BrokerageAccountCard[]): null | string {
|
||||
const values: string[] = [];
|
||||
|
||||
for (const { summary } of accounts) {
|
||||
if (summary.state === "empty") continue;
|
||||
if (summary.state !== "available") continue;
|
||||
|
||||
if (summary.state === "unavailable") {
|
||||
excludedCount += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const total of summary.portfolio.totalsByCurrency) {
|
||||
values.set(total.currency, [
|
||||
...values.get(total.currency) ?? [],
|
||||
total.value,
|
||||
]);
|
||||
}
|
||||
values.push(summary.portfolio.totals.value);
|
||||
}
|
||||
|
||||
const totals: Money[] = Array.from(values, ([currency, amounts]) => ({
|
||||
currency,
|
||||
value: sumDecimals(amounts),
|
||||
}));
|
||||
|
||||
return { excludedCount, totals };
|
||||
return values.length > 0 ? sumDecimals(values) : null;
|
||||
}
|
||||
|
||||
function sumDecimals(values: string[]) {
|
||||
@@ -88,9 +70,11 @@ function sumDecimals(values: string[]) {
|
||||
|
||||
const AccountsPageLoaded: FC<AccountsPageLoadedProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { excludedCount, totals } = accountTotals(props.accounts);
|
||||
const primaryTotal = totals.find(total => total.currency === "RUB") ?? totals[0];
|
||||
const otherTotals = totals.filter(total => total !== primaryTotal);
|
||||
const total = accountTotals(props.accounts);
|
||||
|
||||
const excludedCount = props.accounts.filter(
|
||||
account => account.summary.state === "unavailable",
|
||||
).length;
|
||||
|
||||
return (
|
||||
<Stack gap="lg">
|
||||
@@ -101,25 +85,15 @@ const AccountsPageLoaded: FC<AccountsPageLoadedProps> = (props) => {
|
||||
{t("accounts.currentValue")}
|
||||
</Text>
|
||||
|
||||
{primaryTotal
|
||||
{total === null
|
||||
? (
|
||||
<Text className={classes.primaryTotal} fw={700}>
|
||||
{formatMoney(primaryTotal, { withRoundedCents: true })}
|
||||
</Text>
|
||||
<Text c="dimmed">{t("accounts.summaryNoTotals")}</Text>
|
||||
)
|
||||
: (
|
||||
<Text c="dimmed">{t("accounts.summaryNoTotals")}</Text>
|
||||
)}
|
||||
|
||||
{otherTotals.length > 0 && (
|
||||
<Group gap="md" wrap="wrap">
|
||||
{otherTotals.map(total => (
|
||||
<Text className={classes.otherTotal} key={total.currency}>
|
||||
{formatMoney(total, { withRoundedCents: true })}
|
||||
<Text className={classes.primaryTotal} fw={700}>
|
||||
{formatMoney({ currency: "RUB", value: total }, { withRoundedCents: true })}
|
||||
</Text>
|
||||
))}
|
||||
</Group>
|
||||
)}
|
||||
)}
|
||||
|
||||
<Group className={classes.meta} gap="xs" wrap="wrap">
|
||||
<Text c="dimmed" size="xs">
|
||||
|
||||
Reference in New Issue
Block a user