import { ActionRow } from "../../../components/ui/action-row"; import { Box, ScrollBox, Text } from "../../../ui"; import { t } from "../../../i18n"; import { colors } from "../../../theme/colors"; import { formatCompact, padTo } from "../../../utils/format"; import { formatMarketQuantity } from "../../../market-data/market/format"; import { renderSummarySegments, type PortfolioSummarySegment, type ResolvedPortfolioAccountState, } from "./summary"; /** * Rows the open drawer needs: its title, the numbers the header row had no room * for, then every currency balance. The pane caps it; the drawer's own list only * scrolls by wheel, since the table keeps the paging keys. */ export function cashMarginDrawerHeight(accountState: ResolvedPortfolioAccountState, detailCount: number): number { return 1 + (detailCount > 0 ? 1 : 0) + Math.max(1, accountState.visibleCashBalances.length); } /** * Opens from the `[c]ash` hint and takes no rows while closed. It continues * the header row rather than repeating it, so no number is shown twice. */ export function PortfolioCashMarginDrawer({ accountState, detail, onToggle, width, height, }: { accountState: ResolvedPortfolioAccountState; detail: PortfolioSummarySegment[]; onToggle: () => void; width: number; height: number; }) { const currencyRowsHeight = Math.max(1, height - 1 - (detail.length > 0 ? 1 : 0)); return ( {detail.length > 0 && ( {renderSummarySegments(detail, width)} )} {accountState.visibleCashBalances.length === 0 ? ( {t("No non-zero cash balances.")} ) : ( accountState.visibleCashBalances.map((balance) => ( {padTo(balance.currency, 4)} {" qty "} {padTo(formatMarketQuantity(balance.quantity, { isCashBalance: true, maxWidth: 14 }), 14, "right")} {" value "} {padTo(balance.baseValue != null ? formatCompact(balance.baseValue) : "—", 10, "right")} )) )} ); }