Skip to content

Commit

Permalink
feat: wp
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Oct 31, 2024
1 parent 583ce9b commit 4a5c899
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 104 deletions.
2 changes: 2 additions & 0 deletions src/app/signers/PageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Flex } from '../../ui/Flex';
import { PageTitle } from '../_components/PageTitle';
import { SignersHeader } from './SignersHeader';
import SignersTable from './SignersTable';
import { SignerTable2 } from './SignersTable2';

Check warning on line 8 in src/app/signers/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/PageClient.tsx#L8

Added line #L8 was not covered by tests

export default function ({ tokenPrice }: { tokenPrice: TokenPrice }) {
return (
Expand All @@ -14,6 +15,7 @@ export default function ({ tokenPrice }: { tokenPrice: TokenPrice }) {
</Flex>
<SignersHeader tokenPrice={tokenPrice} />
<SignersTable />
<SignerTable2 />
</>
);
}
193 changes: 193 additions & 0 deletions src/app/signers/SignersTable2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import { ColumnDefinition, Table } from '@/common/components/table/Table';
import { UseQueryResult, useQueries, useQueryClient } from '@tanstack/react-query';
import React, { useMemo, useState } from 'react';

Check warning on line 3 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

import { AddressLink } from '../../common/components/ExplorerLinks';

Check warning on line 5 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L5

Added line #L5 was not covered by tests
import { ApiResponseWithResultsOffset } from '../../common/types/api';
import { truncateMiddle } from '../../common/utils/utils';
import { Flex } from '../../ui/Flex';
import { Text } from '../../ui/Text';
import { useSuspenseCurrentStackingCycle } from '../_components/Stats/CurrentStackingCycle/useCurrentStackingCycle';
import { removeStackingDaoFromName } from './SignerDistributionLegend';
import { SortByVotingPowerFilter, VotingPowerSortOrder } from './SortByVotingPowerFilter';
import { SignersStackersData, useGetStackersBySignerQuery } from './data/UseSignerAddresses';
import { SignerInfo, useSuspensePoxSigners } from './data/useSigners';
import { getSignerKeyName } from './utils';

Check warning on line 15 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L7-L15

Added lines #L7 - L15 were not covered by tests

const NUM_OF_ADDRESSES_TO_SHOW = 1;

Check warning on line 17 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L17

Added line #L17 was not covered by tests

// export const SignersTableHeader = ({
// headerTitle,
// isFirst,
// }: {
// headerTitle: string;
// isFirst: boolean;
// }) => (
// <Th py={3} px={6} border="none" sx={isFirst ? mobileBorderCss : {}} width="fit-content">
// <Flex
// bg="hoverBackground"
// px={2.5}
// py={2}
// borderRadius="md"
// justifyContent="center"
// alignItems="center"
// width="fit-content"
// >
// <Text
// fontWeight="medium"
// whiteSpace="nowrap"
// fontSize="xs"
// color={useColorModeValue('slate.700', 'slate.250')}
// textTransform="none"
// letterSpacing="normal"
// >
// {headerTitle}
// </Text>
// </Flex>
// </Th>
// );

function getEntityName(signerKey: string) {
const entityName = removeStackingDaoFromName(getSignerKeyName(signerKey));

Check warning on line 51 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L50-L51

Added lines #L50 - L51 were not covered by tests
return entityName === 'unknown' ? '-' : entityName;
}

type SignerRow = [number, string, string, SignersStackersData[], number, number];

function formatSignerRowData(
index: number,
singerInfo: SignerInfo,
stackers: SignersStackersData[]

Check warning on line 60 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L60

Added line #L60 was not covered by tests
): SignerRow {
return [

Check warning on line 62 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L62

Added line #L62 was not covered by tests
index, // index
singerInfo.signing_key, // signerKey
singerInfo.signing_key, // signerKey
stackers, // associatedAddress
singerInfo.weight_percent, // votingPower
parseFloat(singerInfo.stacked_amount) / 1_000_000, // stxStaked
];
}

export const columnDefinitions: ColumnDefinition[] = [

Check warning on line 72 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L72

Added line #L72 was not covered by tests
{
id: 'index',
header: '#',
accessor: (index: number | undefined) => index,

Check warning on line 76 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L76

Added line #L76 was not covered by tests
},
{
id: 'signerKey',
header: 'Signer key',
accessor: (signerKey: string | undefined) => truncateMiddle(signerKey ?? ''),
sortable: true,
},
{
id: 'entity',
header: 'Entity',
accessor: (signerKey: string | undefined) => getEntityName(signerKey ?? ''),
sortable: true,
},
{
id: 'associatedAddress',
header: 'Associated address',
accessor: (stackers: SignersStackersData[] | undefined) => stackers,

Check warning on line 93 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L93

Added line #L93 was not covered by tests
cellRenderer: (stackers: SignersStackersData[] | undefined) => (
<Flex textOverflow="ellipsis" overflow="hidden">
{stackers?.slice(0, NUM_OF_ADDRESSES_TO_SHOW).map((stacker, index) => (
<React.Fragment key={stacker.stacker_address}>

Check warning on line 97 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L97

Added line #L97 was not covered by tests
<AddressLink
principal={stacker.stacker_address}
whiteSpace="nowrap"
fontSize="sm"
color="textSubdued"
>
{truncateMiddle(stacker.stacker_address, 5, 5)}
</AddressLink>
{index < stackers.length - 1 && (
<Text color="textSubdued" fontSize="sm">
,&nbsp;
</Text>
)}
{stackers.length > NUM_OF_ADDRESSES_TO_SHOW ? (
<Text color="textSubdued" fontSize="sm">

Check warning on line 112 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L112

Added line #L112 was not covered by tests
&nbsp;+{stackers.length - NUM_OF_ADDRESSES_TO_SHOW}&nbsp;more
</Text>
) : null}

Check warning on line 115 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L115

Added line #L115 was not covered by tests
</React.Fragment>
))}
</Flex>
),
},
{
id: 'votingPower',
header: 'Voting power',
accessor: (votingPower: number | undefined) => `${votingPower?.toFixed(2)}%`,

Check warning on line 124 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L124

Added line #L124 was not covered by tests
sortable: true,
},
{
id: 'stxStaked',
header: 'STX stacked',
accessor: (stxStaked: number | undefined) => Number(stxStaked?.toFixed(0)).toLocaleString(),

Check warning on line 130 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L130

Added line #L130 was not covered by tests
sortable: true,
},
];

export function SignerTable2() {
const [votingPowerSortOrder, setVotingPowerSortOrder] = useState(VotingPowerSortOrder.Desc);
const { currentCycleId } = useSuspenseCurrentStackingCycle();

Check warning on line 137 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L135-L137

Added lines #L135 - L137 were not covered by tests

// Get signers
const {
data: { results: signers },
} = useSuspensePoxSigners(currentCycleId);

Check warning on line 142 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L142

Added line #L142 was not covered by tests

if (!signers) {
throw new Error('Signers data is not available');

Check warning on line 145 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L145

Added line #L145 was not covered by tests
}

// Get signers' stackers
const queryClient = useQueryClient();
const getQuery = useGetStackersBySignerQuery();
const signersStackersQueries = useMemo(() => {
return {
queries: signers.map(signer => {
return getQuery(currentCycleId, signer.signing_key);

Check warning on line 154 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L149-L154

Added lines #L149 - L154 were not covered by tests
}),
combine: (
response: UseQueryResult<ApiResponseWithResultsOffset<SignersStackersData>, Error>[]
) => response.map(r => r.data?.results ?? []),
};
}, [signers, getQuery, currentCycleId]);
const signersStackers = useQueries(signersStackersQueries, queryClient);

Check warning on line 161 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L161

Added line #L161 was not covered by tests

// Format signers data + sort
const signersData = useMemo(

Check warning on line 164 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L164

Added line #L164 was not covered by tests
() =>
signers
.map((signer, index) => formatSignerRowData(index, signer, signersStackers[index]))
.sort((a, b) => {
const aVotingPower = a[4];
const bVotingPower = b[4];

Check warning on line 170 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L166-L170

Added lines #L166 - L170 were not covered by tests
return votingPowerSortOrder === 'desc'
? bVotingPower - aVotingPower
: aVotingPower - bVotingPower;

Check warning on line 173 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L172-L173

Added lines #L172 - L173 were not covered by tests
}),
[signers, signersStackers, votingPowerSortOrder]
);

return (
<Table
title="Signers"
data={signersData}
columnDefinitions={columnDefinitions}
onSort={() => {}}

Check warning on line 183 in src/app/signers/SignersTable2.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signers/SignersTable2.tsx#L183

Added line #L183 was not covered by tests
sortColumn={null}
sortDirection={undefined}
topRight={
<SortByVotingPowerFilter
setVotingPowerSortOrder={setVotingPowerSortOrder}
votingPowerSortOrder={votingPowerSortOrder}
/>}
/>
);
}
2 changes: 1 addition & 1 deletion src/app/stacking/ActivePoolsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useMemo, useState } from 'react';

Check warning on line 1 in src/app/stacking/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/ActivePoolsTable.tsx#L1

Added line #L1 was not covered by tests

import CustomTable, { ColumnDefinition } from './CustomTable';
import CustomTable, { ColumnDefinition } from '../../common/components/table/Table';

Check warning on line 3 in src/app/stacking/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/ActivePoolsTable.tsx#L3

Added line #L3 was not covered by tests

type ActivePoolsData = [string, string, string, string, string, string, string];

Expand Down
4 changes: 0 additions & 4 deletions src/app/stacking/CustomTableWithCursorPagination.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/stacking/PreviousCyclesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useMemo, useState } from 'react';

Check warning on line 1 in src/app/stacking/PreviousCyclesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/PreviousCyclesTable.tsx#L1

Added line #L1 was not covered by tests

import { ColumnDefinition } from '../../common/components/table/Table';
import { CustomTableWithCursorPagination } from '../../common/components/table/TableWithCursorPagination';
import { Flex } from '../../ui/Flex';
import { Icon } from '../../ui/Icon';
import { Text } from '../../ui/Text';
import BitcoinIcon from '../../ui/icons/BitcoinIcon';
import StxIcon from '../../ui/icons/StxIcon';

Check warning on line 9 in src/app/stacking/PreviousCyclesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/PreviousCyclesTable.tsx#L4-L9

Added lines #L4 - L9 were not covered by tests
import { ColumnDefinition } from './CustomTable';
import { CustomTableWithCursorPagination } from './CustomTableWithCursorPagination';

type PreviousCyclesData = [
number,
Expand Down Expand Up @@ -148,7 +148,7 @@ export function PreviousCyclesTable() {
title="Previous Cycles"
topRight={null}
data={data}
columns={columns}
columnDefinitions={columns}
onSort={onSort}
sortColumn={sortColumn}
sortDirection={sortDirection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Button, Flex, Icon, Text } from '@chakra-ui/react';
import { CaretDoubleLeft, CaretDoubleRight, CaretLeft, CaretRight } from '@phosphor-icons/react';
import React, { useState } from 'react';

Check warning on line 3 in src/common/components/pagination/PaginationControls.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/PaginationControls.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

import { Box } from '../../ui/Box';
import { Input } from '../../ui/Input';
import { Box } from '../../../ui/Box';
import { Input } from '../../../ui/Input';

Check warning on line 6 in src/common/components/pagination/PaginationControls.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/PaginationControls.tsx#L5-L6

Added lines #L5 - L6 were not covered by tests

interface PaginationControlProps {
currentPage: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, { useEffect, useState } from 'react';

Check warning on line 1 in src/common/components/pagination/withCursorPagination.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/withCursorPagination.tsx#L1

Added line #L1 was not covered by tests

import { Stack } from '../../ui/Stack';
import { CustomTableProps } from './CustomTable';
import { Stack } from '../../../ui/Stack';

Check warning on line 3 in src/common/components/pagination/withCursorPagination.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/withCursorPagination.tsx#L3

Added line #L3 was not covered by tests
import { TableProps } from '../table/Table';
import { PaginationControl } from './PaginationControls';

Check warning on line 5 in src/common/components/pagination/withCursorPagination.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/withCursorPagination.tsx#L5

Added line #L5 was not covered by tests

interface CursorPaginationProps {
pageSize: number;
fetchNextPage: (cursor: string | null) => Promise<{ data: any[]; nextCursor: string | null }>;
}

type CustomTableWithPaginationProps = CustomTableProps & CursorPaginationProps;
type CustomTableWithPaginationProps = TableProps & CursorPaginationProps;

export function withCursorPagination<T extends CustomTableProps>(
Component: React.ComponentType<T>
) {
export function withCursorPagination<T extends TableProps>(Component: React.ComponentType<T>) {
return function WrappedComponent({

Check warning on line 15 in src/common/components/pagination/withCursorPagination.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/pagination/withCursorPagination.tsx#L14-L15

Added lines #L14 - L15 were not covered by tests
data,
pageSize,
Expand Down
Loading

0 comments on commit 4a5c899

Please sign in to comment.