Skip to content

Commit

Permalink
chore: added HIIQ holders count
Browse files Browse the repository at this point in the history
  • Loading branch information
invisiblemask committed Nov 15, 2024
1 parent e55921e commit 117ae81
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/client/HIIQHolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useGetHIIQHoldersRankQuery } from '@/services/holders'

export default function HIIQHolders() {
const { data, isLoading } = useGetHIIQHoldersRankQuery({
limit: 10,
limit: 100,
offset: 0,
})

Expand Down
56 changes: 36 additions & 20 deletions src/components/dashboard/hiiq-table/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,52 @@
import { ColumnDef } from '@tanstack/react-table'

import { Button } from '@/components/ui/button'
import { RiArrowDownSFill, RiFileCopyLine } from 'react-icons/ri'
import { RiArrowDownSFill, RiCheckFill, RiFileCopyLine } from 'react-icons/ri'
import { getShortenAddress } from '@/lib/helpers/getShortenAddress'
import { useState } from 'react'

export type HIIQHoldersProps = {
address: string
tokens: string
percentage?: string
updated: number
created: number
}

export const columns: ColumnDef<HIIQHoldersProps>[] = [
{
accessorKey: 'rank',
header: 'Rank',
cell: ({ row }) => {
return <div>{row.index + 1}</div>
},
},
{
accessorKey: 'address',
header: 'Address',
cell: ({ row }) => {
const [isCopied, setIsCopied] = useState(false)

const handleCopy = () => {
navigator.clipboard.writeText(row.getValue('address'))
setIsCopied(true)
setTimeout(() => {
setIsCopied(false)
}, 3000)
}

return (
<div className="flex flex-row items-center gap-2">
<span className="text-brand-500 dark:text-brand-800">
{getShortenAddress(row.getValue('address'))}
</span>
<RiFileCopyLine
size={18}
className="opacity-40 hover:opacity-70 cursor-pointer"
/>
{isCopied ? (
<RiCheckFill size={18} className="text-green-500" />
) : (
<RiFileCopyLine
size={18}
className="opacity-40 hover:opacity-70 cursor-pointer"
onClick={handleCopy}
/>
)}
</div>
)
},
Expand Down Expand Up @@ -59,25 +76,24 @@ export const columns: ColumnDef<HIIQHoldersProps>[] = [
},
},
{
accessorKey: 'percentage',
header: 'Percentage',
},
{
accessorKey: 'update',
header: 'Last Updated',
accessorKey: 'created',
header: 'Date Staked',
cell: ({ row }) => {
const dateString = row.getValue('created')
const date = new Date(dateString as string)

console.log(date)
return (
<div className="flex flex-row items-center gap-1 font-medium">
Block{' '}
<span className="text-brand-500 dark:text-brand-800">
{row.getValue('update')}
<span>
{new Date(row.getValue('created')).toLocaleDateString('en-GB', {
day: 'numeric',
month: 'short',
year: 'numeric',
})}
</span>
</div>
)
},
},
{
accessorKey: 'dateStaked',
header: 'Date Staked',
},
]
5 changes: 4 additions & 1 deletion src/components/dashboard/hiiq-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@/components/ui/table'
import { RiRefreshLine } from 'react-icons/ri'
import { Badge } from '@/components/ui/badge'
import { useGetHIIQHoldersCountQuery } from '@/services/holders'

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[]
Expand Down Expand Up @@ -61,6 +62,8 @@ export function DataTable<TData, TValue>({
},
})

const { data: count } = useGetHIIQHoldersCountQuery()

return (
<div className="rounded-xl border">
<div className="border-b p-4 flex flex-row gap-4 items-center">
Expand All @@ -69,7 +72,7 @@ export function DataTable<TData, TValue>({
className="bg-brand-50 text-brand-200 dark:text-brand-800"
variant="outline"
>
227 Token Holders
{count} Token Holders
</Badge>
</div>
<div className="flex items-center justify-end gap-4 p-4">
Expand Down
23 changes: 18 additions & 5 deletions src/services/holders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createApi } from '@reduxjs/toolkit/query/react'
import { HYDRATE } from 'next-redux-wrapper'
import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query'
import config from '@/config'
import { DAILY_HOLDERS, HIIQ_HOLDERS_RANK } from './queries'
import { DAILY_HOLDERS, HIIQ_HOLDERS_COUNT, HIIQ_HOLDERS_RANK } from './queries'

type GetHoldersResponse = {
IQHolders: { amount: number; day: string }[]
Expand All @@ -13,7 +13,6 @@ type GetHIIQHoldersRankResponse = {
address: string
tokens: string
created: number
updated: number
}[]
}

Expand Down Expand Up @@ -45,7 +44,6 @@ export const IQHoldersApi = createApi({
address: string
tokens: string
created: number
updated: number
}[],
{ limit: number; offset: number }
>({
Expand All @@ -60,9 +58,24 @@ export const IQHoldersApi = createApi({
return response.hiIQHoldersRank
},
}),
getHIIQHoldersCount: builder.query<number, void>({
query: () => ({
document: HIIQ_HOLDERS_COUNT,
}),
transformResponse: (response: {
hiIQHoldersCount: { amount: number }[]
}) => {
return response.hiIQHoldersCount[0].amount
},
}),
}),
})

export const { useGetIQHoldersQuery, useGetHIIQHoldersRankQuery } = IQHoldersApi
export const {
useGetIQHoldersQuery,
useGetHIIQHoldersRankQuery,
useGetHIIQHoldersCountQuery,
} = IQHoldersApi

export const { getIQHolders, getHIIQHoldersRank } = IQHoldersApi.endpoints
export const { getIQHolders, getHIIQHoldersRank, getHIIQHoldersCount } =
IQHoldersApi.endpoints
9 changes: 8 additions & 1 deletion src/services/holders/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ export const HIIQ_HOLDERS_RANK = gql`
address
tokens
created
updated
}
}
`

export const HIIQ_HOLDERS_COUNT = gql`
query HIIQHoldersCount {
hiIQHoldersCount {
amount
}
}
`

0 comments on commit 117ae81

Please sign in to comment.