Skip to content

Commit

Permalink
feat: mempool txs sort menu
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Jan 4, 2024
1 parent 2b692f5 commit 6506cb1
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 125 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@segment/analytics-next": "1.60.0",
"@segment/snippet": "4.16.2",
"@stacks/auth": "6.9.0",
"@stacks/blockchain-api-client": "7.3.2",
"@stacks/blockchain-api-client": "v7.4.0-beta.2",
"@stacks/common": "6.8.1",
"@stacks/connect": "7.4.0",
"@stacks/connect-react": "22.2.0",
Expand Down Expand Up @@ -112,7 +112,7 @@
"@playwright/test": "1.40.0",
"@stacks/eslint-config": "2.0.0",
"@stacks/prettier-config": "0.0.10",
"@stacks/stacks-blockchain-api-types": "7.4.0-nakamoto.6",
"@stacks/stacks-blockchain-api-types": "v7.4.0-beta.2",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "14.4.3",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/app/_components/Stats/StatSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { FC, ReactNode } from 'react';
import * as React from 'react';

import { Box } from '../../../ui/Box';
import { Flex } from '../../../ui/Flex';
import { Flex, FlexProps } from '../../../ui/Flex';

Check warning on line 7 in src/app/_components/Stats/StatSection.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/StatSection.tsx#L7

Added line #L7 was not covered by tests
import { Grid } from '../../../ui/Grid';
import { Text } from '../../../ui/Text';

export const StatSection: FC<{
title: ReactNode;
bodyMainText: ReactNode;
bodySecondaryText: ReactNode;
caption: ReactNode;
}> = ({ title, bodyMainText, bodySecondaryText, caption, ...rest }) => (
export const StatSection: FC<

Check warning on line 11 in src/app/_components/Stats/StatSection.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/StatSection.tsx#L11

Added line #L11 was not covered by tests
{
title: ReactNode;
bodyMainText: ReactNode;
bodySecondaryText: ReactNode;
caption: ReactNode;
} & Omit<FlexProps, 'title'>
> = ({ title, bodyMainText, bodySecondaryText, caption, ...rest }) => (
<Flex
direction={'column'}
p={5}
Expand Down
139 changes: 139 additions & 0 deletions src/app/transactions/MempoolFeeStats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import React from 'react';

Check warning on line 1 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L1

Added line #L1 was not covered by tests

import { MempoolFeePriorities } from '@stacks/blockchain-api-client/src/generated/models';
import { MempoolFeePrioritiesAll } from '@stacks/blockchain-api-client/src/generated/models/MempoolFeePrioritiesAll';

import { getTxTypeIcon } from '../../common/components/TxIcon';
import { useSuspenseMempoolFee } from '../../common/queries/usMempoolFee';

Check warning on line 7 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L6-L7

Added lines #L6 - L7 were not covered by tests
import {
useCurrentStxPrice,
useSuspenseCurrentStxPrice,
} from '../../common/queries/useCurrentPrices';
import { MICROSTACKS_IN_STACKS, capitalize, getUsdValue } from '../../common/utils/utils';
import { Box } from '../../ui/Box';
import { Flex, FlexProps } from '../../ui/Flex';
import { HStack } from '../../ui/HStack';
import { Icon } from '../../ui/Icon';
import { Tooltip } from '../../ui/Tooltip';
import { Caption } from '../../ui/typography';
import { ExplorerErrorBoundary } from '../_components/ErrorBoundary';
import { StatSection } from '../_components/Stats/StatSection';
import { Wrapper } from '../_components/Stats/Wrapper';

Check warning on line 21 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L11-L21

Added lines #L11 - L21 were not covered by tests

function MempoolFeeByTxType({
mempoolFeeTokenTransfer,
mempoolFeeContractCall,
mempoolFeeSmartContract,
}: {
mempoolFeeTokenTransfer: number;
mempoolFeeContractCall: number;
mempoolFeeSmartContract: number;
}) {

Check warning on line 31 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L31

Added line #L31 was not covered by tests
return (
<HStack divider={<Caption color={'border'}>|</Caption>} gap={1}>
<Tooltip
label={`Token transfer tx fee: ${mempoolFeeTokenTransfer / MICROSTACKS_IN_STACKS} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'}>
<Icon as={getTxTypeIcon('token_transfer')} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeTokenTransfer / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
</Box>
</Flex>
</Tooltip>
<Tooltip
label={`Contract call tx fee: ${mempoolFeeContractCall / MICROSTACKS_IN_STACKS} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'}>
<Icon as={getTxTypeIcon('contract_call')} size={3} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeContractCall / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
</Box>
</Flex>
</Tooltip>
<Tooltip
label={`Smart contract tx fee: ${mempoolFeeSmartContract / MICROSTACKS_IN_STACKS} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'}>
<Icon as={getTxTypeIcon('smart_contract')} size={3} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeSmartContract / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
</Box>
</Flex>
</Tooltip>
</HStack>
);
}

function MempoolFeeSection({
mempoolFeeResponse,
priority,
stxPrice,
...rest
}: {
mempoolFeeResponse: MempoolFeePriorities;
priority: keyof MempoolFeePrioritiesAll;
stxPrice: number;
} & FlexProps) {

Check warning on line 77 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L77

Added line #L77 was not covered by tests
const mempoolFeeAll = mempoolFeeResponse?.all?.[priority] || 0;
const mempoolFeeTokenTransfer = mempoolFeeResponse?.token_transfer?.[priority] || 0;
const mempoolFeeContractCall = mempoolFeeResponse?.contract_call?.[priority] || 0;
const mempoolFeeSmartContract = mempoolFeeResponse?.smart_contract?.[priority] || 0;
return (
<StatSection
title={capitalize(priority.replaceAll('_', ' '))}
bodyMainText={`${mempoolFeeAll / MICROSTACKS_IN_STACKS} STX`}
bodySecondaryText={getUsdValue(mempoolFeeAll, stxPrice, true)}
caption={
<MempoolFeeByTxType
mempoolFeeTokenTransfer={mempoolFeeTokenTransfer}
mempoolFeeContractCall={mempoolFeeContractCall}
mempoolFeeSmartContract={mempoolFeeSmartContract}
/>
}
borderColor={'border'}
{...rest}
/>
);
}

export function MempoolFeeStats() {
const mempoolFeeResponse = useSuspenseMempoolFee().data as MempoolFeePriorities;
const { data: stxPrice } = useCurrentStxPrice();
console.log(mempoolFeeResponse);

Check warning on line 103 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L100-L103

Added lines #L100 - L103 were not covered by tests
return (
<Wrapper>
<MempoolFeeSection
mempoolFeeResponse={mempoolFeeResponse}
priority={'no_priority'}
stxPrice={stxPrice}
borderRightWidth={['0px', '0px', '1px', '1px']}
/>
<MempoolFeeSection
mempoolFeeResponse={mempoolFeeResponse}
priority={'low_priority'}
stxPrice={stxPrice}
borderRightWidth={['0px', '0px', '0px', '1px']}
/>
<MempoolFeeSection
mempoolFeeResponse={mempoolFeeResponse}
priority={'medium_priority'}
stxPrice={stxPrice}
borderRightWidth={['0px', '0px', '1px', '1px']}
/>
<MempoolFeeSection
mempoolFeeResponse={mempoolFeeResponse}
priority={'high_priority'}
stxPrice={stxPrice}
/>
</Wrapper>
);
}

export function MempoolFeeStatsWithErrorBoundary() {

Check warning on line 133 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L133

Added line #L133 was not covered by tests
return (
<ExplorerErrorBoundary renderContent={() => null}>

Check warning on line 135 in src/app/transactions/MempoolFeeStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L135

Added line #L135 was not covered by tests
<MempoolFeeStats />
</ExplorerErrorBoundary>
);
}
32 changes: 27 additions & 5 deletions src/app/transactions/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
'use client';

import React from 'react';
import * as React from 'react';

Check warning on line 3 in src/app/transactions/loading.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/loading.tsx#L3

Added line #L3 was not covered by tests

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

Check warning on line 5 in src/app/transactions/loading.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/loading.tsx#L5

Added line #L5 was not covered by tests
import { SkeletonTxsList } from '../../features/txs-list/SkeletonTxsList';
import { TxListTabsBase } from '../../features/txs-list/tabs/TxListTabsBase';
import { Flex } from '../../ui/Flex';
import { Skeleton } from '../../ui/Skeleton';
import { PageTitle } from '../_components/PageTitle';
import { SkeletonStatSection } from '../_components/Stats/SkeletonStatSection';
import { Wrapper as StatsWrapper } from '../_components/Stats/Wrapper';

Check warning on line 11 in src/app/transactions/loading.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/loading.tsx#L10-L11

Added lines #L10 - L11 were not covered by tests

export default function Loading() {
return (
<Flex direction={'column'} mt="32px" gap="32px">
<>
<PageTitle>
<Skeleton width={'400px'} height={'43px'} />
</PageTitle>
<TxListTabsBase confirmedList={<SkeletonTxsList />} mempoolList={<SkeletonTxsList />} />
</Flex>
<StatsWrapper>
<SkeletonStatSection borderRightWidth={['0px', '0px', '1px', '1px']} />
<SkeletonStatSection borderRightWidth={['0px', '0px', '0px', '1px']} />
<SkeletonStatSection borderRightWidth={['0px', '0px', '1px', '1px']} />
<SkeletonStatSection />
</StatsWrapper>

<TabsContainer
tabs={[
{
title: 'Confirmed',
content: <SkeletonTxsList />,
},
{
title: 'Pending',
content: <SkeletonTxsList />,
},
]}
actions={null}
gridColumnEnd={'3'}
/>
</>
);
}
36 changes: 34 additions & 2 deletions src/app/transactions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,46 @@

import { NextPage } from 'next';
import React from 'react';
import { BsChevronDown, BsCodeSlash } from 'react-icons/bs';
import { RxCube } from 'react-icons/rx';

import { numberToString } from '../../common/utils/utils';
import { TxListTabs } from '../../features/txs-list/tabs/TxListTabs';
import { PageTitle } from '../_components/PageTitle';
import { Button } from '../../ui/Button';
import { Flex } from '../../ui/Flex';

Check warning on line 11 in src/app/transactions/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L11

Added line #L11 was not covered by tests
import { Icon } from '../../ui/Icon';
import { Menu } from '../../ui/Menu';
import { MenuButton } from '../../ui/MenuButton';
import { MenuDivider } from '../../ui/MenuDivider';
import { MenuItem } from '../../ui/MenuItem';
import { MenuList } from '../../ui/MenuList';
import { Tag } from '../../ui/Tag';
import { TagLabel } from '../../ui/TagLabel';
import { useColorMode } from '../../ui/hooks/useColorMode';
import { FunctionIcon } from '../../ui/icons';
import { CubeSparkleIcon } from '../../ui/icons/CubeSparkleIcon';
import { PageTitle, PageTitleWithTags } from '../_components/PageTitle';

Check warning on line 23 in src/app/transactions/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L23

Added line #L23 was not covered by tests
import { StatSection } from '../_components/Stats/StatSection';
import {
CurrentStackingCycle,
LastBlock,
NextStackingCycle,
StxSupply,
} from '../_components/Stats/Stats';
import { Wrapper } from '../_components/Stats/Wrapper';
import { LinksGroup } from '../token/[tokenId]/LinksGroup';
import { LinksMenu } from '../token/[tokenId]/LinksMenu';
import { Tabs } from '../token/[tokenId]/Tabs';
import { TokenInfo } from '../token/[tokenId]/TokenInfo';
import { MempoolFeeStats, MempoolFeeStatsWithErrorBoundary } from './MempoolFeeStats';

Check warning on line 36 in src/app/transactions/page.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L36

Added line #L36 was not covered by tests

const TransactionsPage: NextPage = () => {
return (
<>
<PageTitle>Transactions</PageTitle>
<Flex justifyContent={'space-between'} alignItems={'flex-end'}>
<PageTitle>Transactions</PageTitle>
</Flex>
<MempoolFeeStatsWithErrorBoundary />
<TxListTabs />
</>
);
Expand Down
Loading

0 comments on commit 6506cb1

Please sign in to comment.