Skip to content

Commit

Permalink
feat: wp
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Feb 12, 2025
1 parent 3bf1e50 commit 514cf74
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 395 deletions.
2 changes: 1 addition & 1 deletion src/app/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { ActivePoolsTable } from '@/common/components/Table Delete/ActivePoolsTable';
import { ActivePoolsTable } from '@/common/components/table/ActivePoolsTable';

Check warning on line 3 in src/app/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L3

Added line #L3 was not covered by tests
import { Grid } from '@chakra-ui/react';
import { NextPage } from 'next';
import dynamic from 'next/dynamic';
Expand Down
147 changes: 109 additions & 38 deletions src/common/components/Table/ActivePoolsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useCallback, useMemo, useState } from 'react';
import { Text } from '@/ui/Text';
import { Table as ChakraTable, Flex, Icon } from '@chakra-ui/react';
import { ArrowsClockwise } from '@phosphor-icons/react';
import { useMemo } from 'react';

Check warning on line 4 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L1-L4

Added lines #L1 - L4 were not covered by tests

import { ColumnDefinition, Table } from './Table';
import { CellRenderer, ColumnDefinition, Table } from './Table';
import { TableContainer } from './TableContainer';

Check warning on line 7 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L6-L7

Added lines #L6 - L7 were not covered by tests

// Define your enum and data type
enum ActivePoolsColumns {
Provider = 'provider',
PoxAddress = 'poxAddress',
Expand All @@ -14,7 +17,7 @@ enum ActivePoolsColumns {
}

interface ActivePoolsData {
[ActivePoolsColumns.Provider]: { functionName: string, contractName: string };
[ActivePoolsColumns.Provider]: string;
[ActivePoolsColumns.PoxAddress]: string;
[ActivePoolsColumns.Contract]: string;
[ActivePoolsColumns.RewardsIn]: string;
Expand All @@ -23,59 +26,127 @@ interface ActivePoolsData {
[ActivePoolsColumns.Rewards]: number;
}

// type ActivePoolsData = [string, string, string, string, string, string, string];
const defaultCellRenderer: CellRenderer<ActivePoolsData, string | number> = (
value: string | number | undefined

Check warning on line 30 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
) => {
return (
<Text whiteSpace="nowrap" overflow="hidden" textOverflow="ellipsis" fontSize="sm">
{String(value)}
</Text>
);
};

export async function ActivePoolsTable() {
const rowData: ActivePoolsData[] = useMemo(
() =>
Array.from({ length: 10 }, (_, index) => ({
[ActivePoolsColumns.Provider]: { functionName: 'Xverse' + index, contractName: 'Xverse' + index, status: 'Active' },
[ActivePoolsColumns.PoxAddress]: 'bc1q9hquna0...h5edvpgxfjp6d5g',
[ActivePoolsColumns.Contract]: 'xverse-pool-btc-v-1-2',
[ActivePoolsColumns.RewardsIn]: '10,426',
[ActivePoolsColumns.StackersDelegating]: 118432860,
[ActivePoolsColumns.AmountStacked]: 12300000,
[ActivePoolsColumns.Rewards]: 2325,
})),
[]
export function UpdateTableBannerRow() {
const numColumns = Object.keys(ActivePoolsColumns).length;

Check warning on line 40 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L39-L40

Added lines #L39 - L40 were not covered by tests

return (
<ChakraTable.Row
css={{
'& > td:first-of-type': {
borderTopLeftRadius: 'redesign.md',
borderBottomLeftRadius: 'redesign.md',
},
'& > td:last-of-type': {
borderTopRightRadius: 'redesign.md',
borderBottomRightRadius: 'redesign.md',
},
}}
>
<ChakraTable.Cell colSpan={numColumns} py={2} px={1}>
<Flex
alignItems="center"
justifyContent="center"
gap={1.5}
boxShadow="0px 4px 12px 0px color(display-p3 0.9882 0.3922 0.1961 / 0.25), 0px 4px 12px 0px rgba(255, 85, 18, 0.25)"
border="1px dashed var(--stacks-colors-accent-stacks-500)"
borderRadius="redesign.lg"
h={12}
>
<Text fontSize="sm" fontWeight="medium" color="textSecondary">
New transactions have come in. Update list
</Text>
<Icon h={3.5} w={3.5} color="iconTertiary">
<ArrowsClockwise />
</Icon>
</Flex>
</ChakraTable.Cell>
</ChakraTable.Row>
);
}

export function ActivePoolsTable() {
const rowData: ActivePoolsData[] = useMemo(() => {
const data: ActivePoolsData[] = Array.from({ length: 10 }, (_, index) => ({

Check warning on line 79 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L77-L79

Added lines #L77 - L79 were not covered by tests
[ActivePoolsColumns.Provider]: 'Xverse' + index,
[ActivePoolsColumns.PoxAddress]: 'bc1q9hquna0...h5edvpgxfjp6d5g',
[ActivePoolsColumns.Contract]: 'xverse-pool-btc-v-1-2',
[ActivePoolsColumns.RewardsIn]: '10,426',
[ActivePoolsColumns.StackersDelegating]: 118432860,
[ActivePoolsColumns.AmountStacked]: 12300000,
[ActivePoolsColumns.Rewards]: 2325,
}));
return data;

Check warning on line 88 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L88

Added line #L88 was not covered by tests
}, []);

const columnDefinitions: ColumnDefinition<ActivePoolsData, ActivePoolsColumns>[] = useMemo(
() => [

Check warning on line 92 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L91-L92

Added lines #L91 - L92 were not covered by tests
{ id: ActivePoolsColumns.Provider, header: 'Provider', sortable: true, onSort: (a, b) => a.provider.localeCompare(b.provider), accessor: (_, row) => value[ActivePoolsColumns.Provider].functionName, cellRenderer: (value: ActivePoolsData) => value[ActivePoolsColumns.Provider].functionName },
{ id: ActivePoolsColumns.PoxAddress, header: 'PoX Address', sortable: false },
{ id: ActivePoolsColumns.Contract, header: 'Contract', sortable: false },
{ id: ActivePoolsColumns.RewardsIn, header: 'Rewards in', sortable: false },
{
id: ActivePoolsColumns.Provider,
header: 'Provider',
onSort: (a, b) => a.provider.localeCompare(b.provider),
accessor: row => row[ActivePoolsColumns.Provider],

Check warning on line 97 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L96-L97

Added lines #L96 - L97 were not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.PoxAddress,
header: 'PoX Address',
accessor: row => row[ActivePoolsColumns.PoxAddress],

Check warning on line 103 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L103

Added line #L103 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.Contract,
header: 'Contract',
accessor: row => row[ActivePoolsColumns.Contract],

Check warning on line 109 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L109

Added line #L109 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.RewardsIn,
header: 'Rewards in',
accessor: row => row[ActivePoolsColumns.RewardsIn],

Check warning on line 115 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L115

Added line #L115 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.StackersDelegating,
header: 'Stackers delegating',
sortable: true,
accessor: row => row[ActivePoolsColumns.StackersDelegating],

Check warning on line 121 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L121

Added line #L121 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.AmountStacked,
header: 'Amount stacked',
sortable: true,
accessor: row => row[ActivePoolsColumns.AmountStacked],

Check warning on line 127 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L127

Added line #L127 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{
id: ActivePoolsColumns.Rewards,
header: 'Rewards',
accessor: row => row[ActivePoolsColumns.Rewards],

Check warning on line 133 in src/common/components/Table/ActivePoolsTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/Table/ActivePoolsTable.tsx#L133

Added line #L133 was not covered by tests
cellRenderer: defaultCellRenderer,
},
{ id: ActivePoolsColumns.Rewards, header: 'Rewards', sortable: true },
],
[]
);

const [sortColumn, setSortColumn] = useState<null | string>(null);
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('asc');
const onSort = useCallback((columnId: string, newSortDirection: 'asc' | 'desc') => {
setSortColumn(columnId);
setSortDirection(newSortDirection);
}, []);

return (
<Table
title="Active Pools"
topRight={null}
<Table<ActivePoolsData>
rowData={rowData}
columnDefinitions={columnDefinitions}
onSort={onSort}
sortColumn={sortColumn}
sortDirection={sortDirection}
hasScrollIndicator
hasFixedFirstColumn
tableContainerWrapper={table => (
<TableContainer title={'Active Pools'}>{table}</TableContainer>
)}
bannerRow={<UpdateTableBannerRow />}
/>
);
}
Loading

0 comments on commit 514cf74

Please sign in to comment.