Skip to content

Commit

Permalink
Improve slashable stake sorting (l2beat#5721)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlyy authored Nov 5, 2024
1 parent 7b9c278 commit 9357b5d
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createColumnHelper } from '@tanstack/react-table'
import { type Row, createColumnHelper } from '@tanstack/react-table'
import { NaBadge } from '~/components/badge/na-badge'
import { GrissiniCell } from '~/components/rosette/grissini/grissini-cell'
import { TwoRowCell } from '~/components/table/cells/two-row-cell'
Expand Down Expand Up @@ -79,7 +79,6 @@ const tvsColumn = columnHelper.accessor('tvs', {
</div>
)
},
enableSorting: false,
meta: {
tooltip:
'Total value secured (TVS) is the total value locked of all projects using this layer.',
Expand All @@ -105,6 +104,7 @@ const slashableStakeColumn = columnHelper.accessor('economicSecurity', {
</div>
)
},
sortingFn: sortSlashableStake,
meta: {
align: 'right',
tooltip:
Expand Down Expand Up @@ -229,3 +229,25 @@ export const publicSystemsColumns = [
bridgeColumn,
bridgeGroup,
]

function sortSlashableStake(
rowA: Row<DaSummaryEntry>,
rowB: Row<DaSummaryEntry>,
) {
const rowAValue = slashableStakeToValue(rowA.original)
const rowBValue = slashableStakeToValue(rowB.original)

return rowBValue - rowAValue
}

function slashableStakeToValue(entry: DaSummaryEntry) {
if (entry.risks.economicSecurity.type === 'Unknown') {
return 0
}

if (!entry.economicSecurity || entry.economicSecurity.status !== 'Synced') {
return 0
}

return entry.economicSecurity.economicSecurity
}

0 comments on commit 9357b5d

Please sign in to comment.