Skip to content

Commit

Permalink
feat: added signer id page
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Nov 4, 2024
1 parent 7605378 commit 64ad792
Show file tree
Hide file tree
Showing 11 changed files with 1,345 additions and 182 deletions.
696 changes: 547 additions & 149 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions src/app/signer/[signerKey]/AssociatedAddressesTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useMemo } from 'react';

Check warning on line 1 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L1

Added line #L1 was not covered by tests

import { useSuspenseSignerStackersInfinite } from '../../../app/signers/data/UseSignerAddresses';
import { CopyButton } from '../../../common/components/CopyButton';
import { ListFooter } from '../../../common/components/ListFooter';
import { Section } from '../../../common/components/Section';
import { Box } from '../../../ui/Box';
import { Flex } from '../../../ui/Flex';
import { Stack } from '../../../ui/Stack';
import { Text } from '../../../ui/Text';
import { useSuspenseCurrentStackingCycle } from '../../_components/Stats/CurrentStackingCycle/useCurrentStackingCycle';

Check warning on line 11 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L3-L11

Added lines #L3 - L11 were not covered by tests

const addressItemHeight = 69;

Check warning on line 13 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L13

Added line #L13 was not covered by tests

export function AssociatedAddressesTable({ signerKey }: { signerKey: string }) {
const { currentCycleId } = useSuspenseCurrentStackingCycle();

Check warning on line 16 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L15-L16

Added lines #L15 - L16 were not covered by tests
const {
data: signerStackers,
isFetchingNextPage,
fetchNextPage,
hasNextPage,
} = useSuspenseSignerStackersInfinite(currentCycleId, signerKey);

Check warning on line 22 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L22

Added line #L22 was not covered by tests

const stackers = useMemo(
() => signerStackers?.pages.flatMap(page => page.results),

Check warning on line 25 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L24-L25

Added lines #L24 - L25 were not covered by tests
[signerStackers]
);

return (
<Section title="Associated addresses">
<Stack gap={0}>
<Box h={addressItemHeight * 10} overflow="auto">
{signerStackers?.pages
.flatMap(page => page.results)

Check warning on line 34 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L34

Added line #L34 was not covered by tests
.map((stacker, i) => (
<Flex

Check warning on line 36 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L36

Added line #L36 was not covered by tests
key={stacker.stacker_address}
alignItems={'center'}
gap={1}
py={6}
borderBottom={
i !== (stackers?.length ?? 0) - 1
? '1px solid var(--stacks-colors-borderSecondary)'
: 'none'

Check warning on line 44 in src/app/signer/[signerKey]/AssociatedAddressesTable.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/AssociatedAddressesTable.tsx#L43-L44

Added lines #L43 - L44 were not covered by tests
}
>
<Text fontSize={'sm'}>{stacker.stacker_address}</Text>
<CopyButton
className={'fancy-copy'}
initialValue={stacker.pox_address}
aria-label={'copy row'}
size={4}
color="textSubdued"
/>
</Flex>
))}
</Box>

<ListFooter
label="addresses"
isLoading={isFetchingNextPage}
fetchNextPage={fetchNextPage}
hasNextPage={hasNextPage}
pb={6}
position={'sticky'}
bottom={0}
bg="surface"
/>
</Stack>
</Section>
);
}
45 changes: 45 additions & 0 deletions src/app/signer/[signerKey]/CycleSortFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SortDescending } from '@phosphor-icons/react';
import { useMemo } from 'react';

Check warning on line 2 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L1-L2

Added lines #L1 - L2 were not covered by tests

import { FilterMenu } from '../../../common/components/FilterMenu';

Check warning on line 4 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L4

Added line #L4 was not covered by tests

export enum CycleSortOrder {
Asc = 'asc',
Desc = 'desc',
}

function getSortOptionLabel(order: CycleSortOrder) {

Check warning on line 11 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L11

Added line #L11 was not covered by tests
switch (order) {
case CycleSortOrder.Asc:
return 'Cycle Asc';
case CycleSortOrder.Desc:
return 'Cycle Desc';

Check warning on line 16 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L13-L16

Added lines #L13 - L16 were not covered by tests
}
}

export function CycleSortFilter({

Check warning on line 20 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L20

Added line #L20 was not covered by tests
cycleSortOrder,
setCycleSortOrder,
}: {
cycleSortOrder: CycleSortOrder;
setCycleSortOrder: (order: CycleSortOrder) => void;
}) {
const menuItems = useMemo(

Check warning on line 27 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L26-L27

Added lines #L26 - L27 were not covered by tests
() =>
Object.values(CycleSortOrder).map(order => ({
onClick: () => {
setCycleSortOrder(order);

Check warning on line 31 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L29-L31

Added lines #L29 - L31 were not covered by tests
},
label: getSortOptionLabel(order),
})),
[setCycleSortOrder]
);

return (
<FilterMenu
filterLabel={() => getSortOptionLabel(cycleSortOrder)}

Check warning on line 40 in src/app/signer/[signerKey]/CycleSortFilter.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/CycleSortFilter.tsx#L40

Added line #L40 was not covered by tests
menuItems={menuItems}
leftIcon={SortDescending}
/>
);
}
51 changes: 51 additions & 0 deletions src/app/signer/[signerKey]/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use client';

import { useParams } from 'next/navigation';

Check warning on line 3 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L3

Added line #L3 was not covered by tests

import { Grid, GridProps } from '../../../ui/Grid';
import { Stack } from '../../../ui/Stack';
import { PageTitle } from '../../_components/PageTitle';
import { AssociatedAddressesTable } from './AssociatedAddressesTable';
import { SignerKeyStats } from './SignerKeyStats';
import { SignerKeySummary } from './SignerKeySummary';
import { StackingHistoryTable } from './StackingHistoryTable';

Check warning on line 11 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L5-L11

Added lines #L5 - L11 were not covered by tests

export function SignerKeyPageLayout(props: GridProps) {

Check warning on line 13 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L13

Added line #L13 was not covered by tests
return (
<Grid
gridColumnGap={8}
gridTemplateColumns={['100%', '100%', 'repeat(1, calc(100% - 352px) 320px)']}
gridRowGap={[8, 8, 'unset']}
maxWidth="100%"
alignItems="flex-start"
{...props}
/>
);
}

export default function PageClient() {
const params = useParams<{ signerKey: string }>();

Check warning on line 27 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L26-L27

Added lines #L26 - L27 were not covered by tests

if (!params) {
console.error('params is undefined. This component should receive params from its parent.');
return null; // or some error UI

Check warning on line 31 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L30-L31

Added lines #L30 - L31 were not covered by tests
}

const { signerKey } = params;

Check warning on line 34 in src/app/signer/[signerKey]/PageClient.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/PageClient.tsx#L34

Added line #L34 was not covered by tests
return (
<>
<PageTitle>Signer key</PageTitle>

<SignerKeyPageLayout>
<Stack gap={8}>
<SignerKeySummary signerKey={signerKey} />
<AssociatedAddressesTable signerKey={signerKey} />
<StackingHistoryTable signerKey={signerKey} />
</Stack>
<Stack gap={8}>
<SignerKeyStats signerKey={signerKey} />
</Stack>
</SignerKeyPageLayout>
</>
);
}
48 changes: 48 additions & 0 deletions src/app/signer/[signerKey]/SignerKeyStats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ExplorerErrorBoundary } from '@/app/_components/ErrorBoundary';
import { useSuspenseSignerStackers } from '@/app/signers/data/UseSignerAddresses';
import { Section } from '@/common/components/Section';
import { Box } from '@/ui/Box';
import { Stack } from '@/ui/Stack';
import { Caption } from '@/ui/typography';

Check warning on line 6 in src/app/signer/[signerKey]/SignerKeyStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeyStats.tsx#L1-L6

Added lines #L1 - L6 were not covered by tests

import { useSuspenseCurrentStackingCycle } from '../../_components/Stats/CurrentStackingCycle/useCurrentStackingCycle';
import { useSuspensePoxSigner } from '../../signers/data/UseSigner';

Check warning on line 9 in src/app/signer/[signerKey]/SignerKeyStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeyStats.tsx#L8-L9

Added lines #L8 - L9 were not covered by tests

interface SignerKeyStatsProps {
signerKey: string;
}

function SignerKeyStatsBase({ signerKey }: SignerKeyStatsProps) {
const { currentCycleId } = useSuspenseCurrentStackingCycle();
const { data: signerData } = useSuspensePoxSigner(currentCycleId, signerKey);
const { data: signerStackers } = useSuspenseSignerStackers(currentCycleId, signerKey);

Check warning on line 18 in src/app/signer/[signerKey]/SignerKeyStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeyStats.tsx#L15-L18

Added lines #L15 - L18 were not covered by tests

return (
<Section title={'Stats'}>
<Stack gap={2} py={4}>
<Caption>Performance</Caption>
<Box>Waiting on the API for the data</Box>
</Stack>
<Stack gap={2} py={4}>
<Caption>Total signed transactions</Caption>
<Box>Waiting on the API for the data</Box>
</Stack>
<Stack gap={2} py={4}>
<Caption>Slot success rate</Caption>
<Box>Waiting on the API for the data</Box>
</Stack>
<Stack gap={2} py={4}>
<Caption>Uptime</Caption>
<Box>Waiting on the API for the data</Box>
</Stack>
</Section>
);
}

export function SignerKeyStats(props: SignerKeyStatsProps) {

Check warning on line 42 in src/app/signer/[signerKey]/SignerKeyStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeyStats.tsx#L42

Added line #L42 was not covered by tests
return (
<ExplorerErrorBoundary Wrapper={Section} wrapperProps={{ title: 'STX Balance' }} tryAgainButton>
<SignerKeyStatsBase {...props} />
</ExplorerErrorBoundary>
);
}
59 changes: 59 additions & 0 deletions src/app/signer/[signerKey]/SignerKeySummary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useSuspenseSignerStackers } from '@/app/signers/data/UseSignerAddresses';
import { KeyValueHorizontal } from '@/common/components/KeyValueHorizontal';
import { Section } from '@/common/components/Section';
import { Value } from '@/common/components/Value';
import { microToStacksFormatted } from '@/common/utils/utils';
import { Box } from '@/ui/Box';
import { Flex } from '@/ui/Flex';

Check warning on line 7 in src/app/signer/[signerKey]/SignerKeySummary.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeySummary.tsx#L1-L7

Added lines #L1 - L7 were not covered by tests

import { getEntityName } from '../../../app/signers/SignersTable';
import { useSuspenseCurrentStackingCycle } from '../../_components/Stats/CurrentStackingCycle/useCurrentStackingCycle';
import { useSuspensePoxSigner } from '../../signers/data/UseSigner';

Check warning on line 11 in src/app/signer/[signerKey]/SignerKeySummary.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeySummary.tsx#L9-L11

Added lines #L9 - L11 were not covered by tests

interface SignerKeySummaryProps {
signerKey: string;
}
export const SignerKeySummary = ({ signerKey }: SignerKeySummaryProps) => {
const { currentCycleId } = useSuspenseCurrentStackingCycle();
const { data: signerData } = useSuspensePoxSigner(currentCycleId, signerKey);
const { data: signerStackers } = useSuspenseSignerStackers(currentCycleId, signerKey);

Check warning on line 19 in src/app/signer/[signerKey]/SignerKeySummary.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/signer/[signerKey]/SignerKeySummary.tsx#L16-L19

Added lines #L16 - L19 were not covered by tests

return (
<Section title="Summary">
<Flex width="100%" flexDirection={['column', 'column', 'row']}>
<Box width={['100%']}>
<KeyValueHorizontal
label={'Key'}
value={<Value>{signerKey}</Value>}
copyValue={signerKey}
/>
<KeyValueHorizontal
label={'Entity'}
value={<Value>{getEntityName(signerKey)}</Value>}
copyValue={getEntityName(signerKey)}
/>
{/* <KeyValueHorizontal // TODO: this is stupid, I don't think we should show this as the calculation adds unncessary network calls
label={'Rank'}
value={<Value>{principal}</Value>}
copyValue={principal}
/> */}
<KeyValueHorizontal
label={'Voting Power'}
value={<Value>{signerData?.weight_percent.toFixed(2)}%</Value>}
copyValue={signerData?.weight_percent.toFixed(2)}
/>
<KeyValueHorizontal
label={'STX Stacked'}
value={<Value>{microToStacksFormatted(signerData?.stacked_amount)}</Value>}
copyValue={microToStacksFormatted(signerData?.stacked_amount)}
/>
<KeyValueHorizontal
label={'Associated Addresses'}
value={<Value>{signerStackers?.results.length}</Value>}
copyValue={signerStackers?.results.length.toString()}
/>
</Box>
</Flex>
</Section>
);
};
Loading

0 comments on commit 64ad792

Please sign in to comment.