feat(accounts): enrich brokerage account list

This commit is contained in:
2026-08-26 20:57:55 +03:00
parent 488ccad540
commit fd93133cfc
12 changed files with 230 additions and 44 deletions
@@ -1,5 +1,17 @@
import type { BrokerageAccount } from "../api/useBrokerageAccounts";
type Money = NonNullable<
BrokerageAccount["portfolioSummary"]
>["totalsByCurrency"][number];
type BrokerageAccountCard = {
account: BrokerageAccount;
summary:
| { state: "unavailable" }
| { state: "empty" }
| { state: "available"; totals: Money[]; remainingCurrencyCount: number };
};
function accountTypeKey(type: BrokerageAccount["type"]) {
return `accounts.types.${type}` as const;
}
@@ -10,4 +22,31 @@ function errorCode(error: unknown): string | undefined {
: undefined;
}
export { accountTypeKey, errorCode };
function brokerageAccountCards(
accounts: BrokerageAccount[],
): BrokerageAccountCard[] {
return accounts.map((account) => {
const summary = account.portfolioSummary;
if (!summary) return { account, summary: { state: "unavailable" } };
if (!summary.totalsByCurrency.length)
return { account, summary: { state: "empty" } };
return {
account,
summary: {
state: "available",
totals: summary.totalsByCurrency.slice(0, 2),
remainingCurrencyCount: Math.max(
summary.totalsByCurrency.length - 2,
0,
),
},
};
});
}
export {
accountTypeKey,
type BrokerageAccountCard,
brokerageAccountCards,
errorCode,
};