Skip to content

Commit 20d475e

Browse files
committed
add new columns on categories page
1 parent e3424bf commit 20d475e

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

src/components/Table/Defi/columns.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,64 @@ export const categoriesColumn: ColumnDef<ICategoryRow>[] = [
176176
{
177177
header: 'Protocols',
178178
accessorKey: 'protocols',
179-
size: 100
179+
size: 100,
180+
meta: {
181+
align: 'end'
182+
}
180183
},
181184
{
182185
header: 'Combined TVL',
183186
accessorKey: 'tvl',
187+
accessorFn: (row) => row.tvl ?? undefined,
184188
cell: ({ getValue }) => {
185189
const value = getValue() as number | null
186190
return value && value > 0 ? <>{'$' + formattedNum(value)}</> : <></>
187191
},
192+
meta: {
193+
align: 'end'
194+
},
195+
sortUndefined: 'last',
188196
size: 135
189197
},
198+
{
199+
header: '1d Change',
200+
accessorKey: 'change_1d',
201+
cell: (info) => <>{formattedPercent(info.getValue())}</>,
202+
size: 110,
203+
meta: {
204+
align: 'end'
205+
}
206+
},
207+
{
208+
header: '7d Change',
209+
accessorKey: 'change_7d',
210+
cell: (info) => <>{formattedPercent(info.getValue())}</>,
211+
size: 110,
212+
meta: {
213+
align: 'end'
214+
}
215+
},
216+
{
217+
header: '1m Change',
218+
accessorKey: 'change_1m',
219+
cell: (info) => <>{formattedPercent(info.getValue())}</>,
220+
size: 110,
221+
meta: {
222+
align: 'end'
223+
}
224+
},
190225
{
191226
header: 'Combined 24h Revenue',
192227
accessorKey: 'revenue',
228+
accessorFn: (row) => row.revenue ?? undefined,
193229
cell: ({ getValue }) => {
194230
const value = getValue() as number | null
195231
return value && value > 0 ? <>{'$' + formattedNum(value)}</> : <></>
196232
},
233+
meta: {
234+
align: 'end'
235+
},
236+
sortUndefined: 'last',
197237
size: 200
198238
},
199239
{

src/components/Table/Defi/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface ICategoryRow {
1818
protocols: number
1919
tvl: number
2020
description: string
21+
change_1d: number
22+
change_7d: number
23+
change_1m: number
24+
revenue: number
2125
}
2226

2327
export interface IChain {

src/pages/categories.tsx

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { categoriesColumn } from '~/components/Table/Defi/columns'
99
import { TableWithSearch } from '~/components/Table/TableWithSearch'
1010
import { useCalcGroupExtraTvlsByDay } from '~/hooks/data'
1111
import Layout from '~/layout'
12+
import { getPercentChange } from '~/utils'
1213
import { withPerformanceLogging } from '~/utils/perf'
1314

1415
const AreaChart = dynamic(() => import('~/components/ECharts/AreaChart'), {
@@ -57,9 +58,9 @@ export const getStaticProps = withPerformanceLogging('categories', async () => {
5758
name,
5859
protocols: details.protocols > 0 ? details.protocols : '',
5960
tvl: details.tvl,
60-
tvlPrevDay: details.tvlPrevDay ?? 0,
61-
tvlPrevWeek: details.tvlPrevWeek ?? 0,
62-
tvlPrevMonth: details.tvlPrevMonth ?? 0,
61+
change_1d: getPercentChange(details.tvl, details.tvlPrevDay),
62+
change_7d: getPercentChange(details.tvl, details.tvlPrevWeek),
63+
change_1m: getPercentChange(details.tvl, details.tvlPrevMonth),
6364
revenue: details.revenue,
6465
description: descriptions[name] || ''
6566
})
@@ -164,24 +165,6 @@ export const descriptions = {
164165
export default function Protocols({ categories, chartData, categoryColors, uniqueCategories }) {
165166
const { chainsWithExtraTvlsByDay: categoriesWithExtraTvlsByDay } = useCalcGroupExtraTvlsByDay(chartData)
166167

167-
const [selectedValue, setValue] = React.useState('Current')
168-
169-
const finalCategories = React.useMemo(() => {
170-
return selectedValue === 'Current'
171-
? categories
172-
: categories.map((category) => {
173-
return {
174-
...category,
175-
tvl:
176-
selectedValue === 'Prev Day'
177-
? category.tvlPrevDay
178-
: selectedValue === 'Prev Week'
179-
? category.tvlPrevWeek
180-
: category.tvlPrevMonth
181-
}
182-
})
183-
}, [categories, selectedValue])
184-
185168
return (
186169
<Layout title={`Categories - DefiLlama`} defaultSEO>
187170
<ProtocolsChainsSearch />
@@ -202,29 +185,11 @@ export default function Protocols({ categories, chartData, categoryColors, uniqu
202185
</div>
203186

204187
<TableWithSearch
205-
data={finalCategories}
188+
data={categories}
206189
columns={categoriesColumn}
207190
columnToSearch={'name'}
208191
placeholder={'Search category...'}
209-
customFilters={
210-
<div className="flex items-center rounded-lg overflow-x-auto flex-nowrap w-fit">
211-
{values.map((value) => {
212-
return (
213-
<button
214-
className="flex-shrink-0 py-2 px-3 whitespace-nowrap font-medium text-sm text-black dark:text-white bg-[var(--link-bg)] hover:bg-[var(--link-hover-bg)] focus-visible:bg-[var(--link-hover-bg)] data-[active=true]:bg-[var(--link-active-bg)] data-[active=true]:text-white"
215-
data-active={value === selectedValue}
216-
key={value}
217-
onClick={() => setValue(value)}
218-
>
219-
{value}
220-
</button>
221-
)
222-
})}
223-
</div>
224-
}
225192
/>
226193
</Layout>
227194
)
228195
}
229-
230-
const values = ['Current', 'Prev Day', 'Prev Week', 'Prev Month']

0 commit comments

Comments
 (0)