* fix: fixed mobile issues with SVGs * feat: first morphing AccountDetails * tidy: composition refresh * tidy: fine adjusting * fix: svg fixes * feat: updated summary structure * feat: overall layout adjustments * fix: fixed svg adjustments * feat: finished AccountSummary update * fix: fixed build * tidy: refactor * fix: fix enourmous APYs * fix: don’t abbreviate APYs * tidy: console.log * fix: fix borrow Rate sorting * fix: fixed scrollbars * fix: hide scrollbars * fix: resolved feedback * fix: amount not size * feat: only show credit account number outside of modals * fix: added missing Strategies to PortfolioAccount * fix: save some space
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { flexRender, Row as TanstackRow, Table as TanstackTable } from '@tanstack/react-table'
|
|
import classNames from 'classnames'
|
|
|
|
interface Props<T> {
|
|
row: TanstackRow<T>
|
|
table: TanstackTable<T>
|
|
renderExpanded?: (row: TanstackRow<T>, table: TanstackTable<T>) => JSX.Element
|
|
rowClassName?: string
|
|
spacingClassName?: string
|
|
className?: string
|
|
isSelectable?: boolean
|
|
type?: TableType
|
|
}
|
|
|
|
function getBorderColor(
|
|
type: TableType,
|
|
row: AccountBalanceRow | AccountStrategyRow | AccountPerpRow,
|
|
) {
|
|
if (type === 'strategies') return ''
|
|
if (type === 'balances') {
|
|
const balancesRow = row as AccountBalanceRow
|
|
return balancesRow.type === 'borrow' ? 'border-loss' : 'border-profit'
|
|
}
|
|
|
|
const perpRow = row as AccountPerpRow
|
|
return perpRow.tradeDirection === 'short' ? 'border-loss' : 'border-profit'
|
|
}
|
|
|
|
export default function Row<T>(props: Props<T>) {
|
|
const { renderExpanded, table, row, type, spacingClassName, isSelectable } = props
|
|
const canExpand = !!renderExpanded
|
|
|
|
return (
|
|
<>
|
|
<tr
|
|
key={`${row.id}-row`}
|
|
className={classNames(
|
|
'group/row transition-bg',
|
|
(renderExpanded || isSelectable) && 'hover:cursor-pointer',
|
|
canExpand && row.getIsExpanded() ? 'is-expanded bg-black/20' : 'hover:bg-white/5',
|
|
)}
|
|
onClick={(e) => {
|
|
e.preventDefault()
|
|
if (isSelectable) {
|
|
row.toggleSelected()
|
|
}
|
|
if (canExpand) {
|
|
const isExpanded = row.getIsExpanded()
|
|
table.resetExpanded()
|
|
!isExpanded && row.toggleExpanded()
|
|
}
|
|
}}
|
|
>
|
|
{row.getVisibleCells().map((cell) => {
|
|
const isSymbolOrName = cell.column.id === 'symbol' || cell.column.id === 'name'
|
|
return (
|
|
<td
|
|
key={cell.id}
|
|
className={classNames(
|
|
isSymbolOrName ? 'text-left' : 'text-right',
|
|
spacingClassName ?? 'px-3 py-4',
|
|
type && type !== 'strategies' && isSymbolOrName && 'border-l',
|
|
type && type !== 'strategies' && getBorderColor(type, cell.row.original as any),
|
|
cell.column.columnDef.meta?.className,
|
|
)}
|
|
>
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
</td>
|
|
)
|
|
})}
|
|
</tr>
|
|
{row.getIsExpanded() && renderExpanded && renderExpanded(row, table)}
|
|
</>
|
|
)
|
|
}
|