refactor: enforce frontend view model boundaries
This commit is contained in:
@@ -7,7 +7,8 @@ const VISIBLE_CURRENCY_LIMIT = 2;
|
||||
|
||||
type BrokerageAccountCard = {
|
||||
account: BrokerageAccount;
|
||||
positionCounts: null | { bonds: number; stocks: number };
|
||||
positionCounts: null
|
||||
| { bonds: number; stocks: number };
|
||||
source?: NonNullable<
|
||||
ReturnType<typeof useBrokerageAccounts>["meta"]
|
||||
>["dependencies"] extends (infer T)[] | undefined
|
||||
@@ -38,20 +39,26 @@ function brokerageAccountCards(
|
||||
item =>
|
||||
item.resourceKey === `portfolio/${encodeURIComponent(account.id)}`,
|
||||
);
|
||||
|
||||
const summary = account.portfolioSummary;
|
||||
if (!summary)
|
||||
return {
|
||||
account,
|
||||
positionCounts: /* eslint-disable-line unicorn/no-null -- The existing formatter contract uses null for unavailable data. */ null,
|
||||
positionCounts:
|
||||
// eslint-disable-next-line unicorn/no-null -- The existing formatter contract uses null for unavailable data.
|
||||
null,
|
||||
source,
|
||||
summary: { state: "unavailable" },
|
||||
};
|
||||
|
||||
const positionCounts = {
|
||||
bonds: summary.bondPositionCount,
|
||||
stocks: summary.stockPositionCount,
|
||||
};
|
||||
|
||||
if (summary.totalsByCurrency.length === 0)
|
||||
return { account, positionCounts, source, summary: { state: "empty" } };
|
||||
|
||||
return {
|
||||
account,
|
||||
positionCounts,
|
||||
|
||||
Reference in New Issue
Block a user