Skip to content

Commit

Permalink
feat(mempool-header): fixed linting and build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Feb 6, 2024
1 parent 90f6043 commit d3796ce
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 93 deletions.
11 changes: 7 additions & 4 deletions src/app/_components/Stats/TransactionTypeFilterMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo } from 'react';

Check warning on line 1 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L1

Added line #L1 was not covered by tests

import { MempoolFeePriorities, MempoolTransactionStatsResponseTxTypeCounts } from '@stacks/blockchain-api-client';
import { MempoolFeePriorities } from '@stacks/blockchain-api-client';

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

Check warning on line 5 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L5

Added line #L5 was not covered by tests

export enum TransactionTypeFilterTypes {
Expand All @@ -26,7 +27,9 @@ function getTransactionTypeFilterLabel(transactionType: TransactionTypeFilterTyp
throw new Error('Invalid transactionType');

Check warning on line 27 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L27

Added line #L27 was not covered by tests
}

export function mapTransactionTypeToFilterValue(txType: TransactionTypeFilterTypes): keyof MempoolFeePriorities {
export function mapTransactionTypeToFilterValue(
txType: TransactionTypeFilterTypes

Check warning on line 31 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L30-L31

Added lines #L30 - L31 were not covered by tests
): keyof MempoolFeePriorities {
if (txType === TransactionTypeFilterTypes.AverageForAllTransactions) {
return 'all';

Check warning on line 34 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L34

Added line #L34 was not covered by tests
}
Expand All @@ -53,9 +56,9 @@ export function TransactionTypeFilterMenu({
() =>
Object.keys(TransactionTypeFilterTypes).map(filterType => ({
onClick: () => setTransactionType(filterType as TransactionTypeFilterTypes),

Check warning on line 58 in src/app/_components/Stats/TransactionTypeFilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/TransactionTypeFilterMenu.tsx#L57-L58

Added lines #L57 - L58 were not covered by tests
label: getTransactionTypeFilterLabel(filterType),
label: getTransactionTypeFilterLabel(filterType as TransactionTypeFilterTypes),
})),
[setTransactionType, transactionType]
[setTransactionType]
);

const filterLabel = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions src/app/transactions/MempoolFeeStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function MempoolFeePrioritCard({
mempoolFeeTokenTransfer / MICROSTACKS_IN_STACKS
} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color='secondaryText'>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color="secondaryText">
<Icon as={getTxTypeIcon('token_transfer')} size={3.5} mr={2} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeTokenTransfer / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
Expand All @@ -112,7 +112,7 @@ function MempoolFeePrioritCard({
<Tooltip
label={`Contract call tx fee: ${mempoolFeeContractCall / MICROSTACKS_IN_STACKS} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color='secondaryText'>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color="secondaryText">
<Icon as={getTxTypeIcon('contract_call')} size={3.5} mr={2} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeContractCall / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
Expand All @@ -124,7 +124,7 @@ function MempoolFeePrioritCard({
mempoolFeeSmartContract / MICROSTACKS_IN_STACKS
} STX`}
>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color='secondaryText'>
<Flex gap={0.5} alignItems={'center'} justifyContent={'center'} color="secondaryText">
<Icon as={getTxTypeIcon('smart_contract')} size={3.5} mr={2} />
<Box suppressHydrationWarning>
{`${Number((mempoolFeeSmartContract / MICROSTACKS_IN_STACKS).toFixed(3))}`} STX
Expand Down
80 changes: 40 additions & 40 deletions src/common/components/FilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,46 @@ export function FilterMenu({ filterLabel, menuItems, leftIcon }: FilterMenuProps
const filterLabelValue = typeof filterLabel === 'function' ? filterLabel?.() : filterLabel;

return (
<Menu>
{({ isOpen }) => (
<>
<MenuButton
as={Button}
rightIcon={<Icon as={BsChevronDown} size={3} color={textColor} />}
leftIcon={leftIcon ? <Icon as={leftIcon} size={4} color={filterTitleColor} /> : null}
fontSize={'sm'}
bg={bg}
fontWeight={'semibold'}
border={'1px'}
borderColor={borderColor}
onFocus={handleFocus}
onBlur={handleBlur}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
_hover={{ color: textColor, backgroundColor: hoverBg }}
_active={{ color: textColor, backgroundColor: hoverBg }}
_focus={{ color: textColor, backgroundColor: hoverBg }}
<Menu>
{({ isOpen }) => (
<>
<MenuButton
as={Button}
rightIcon={<Icon as={BsChevronDown} size={3} color={textColor} />}
leftIcon={leftIcon ? <Icon as={leftIcon} size={4} color={filterTitleColor} /> : null}
fontSize={'sm'}
bg={bg}
fontWeight={'semibold'}
border={'1px'}
borderColor={borderColor}
onFocus={handleFocus}
onBlur={handleBlur}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
_hover={{ color: textColor, backgroundColor: hoverBg }}
_active={{ color: textColor, backgroundColor: hoverBg }}
_focus={{ color: textColor, backgroundColor: hoverBg }}
>
<Box
display="inline"
fontWeight="normal"
color={isHoveredOrFocused || isOpen ? textColor : filterTitleColor}
>
<Box
display="inline"
fontWeight="normal"
color={isHoveredOrFocused || isOpen ? textColor : filterTitleColor}
>
Show:{' '}
</Box>
<Box display="inline" fontWeight="normal" color={textColor}>
{filterLabelValue}
</Box>
</MenuButton>
<MenuList fontSize={'sm'} padding="8px">
{menuItems.map(({ label, onClick }) => (
<MenuItem color={textColor} onClick={onClick}>
{label}
</MenuItem>
))}
</MenuList>
</>
)}
</Menu>
Show:{' '}
</Box>
<Box display="inline" fontWeight="normal" color={textColor}>
{filterLabelValue}
</Box>
</MenuButton>
<MenuList fontSize={'sm'} padding="8px">
{menuItems.map(({ label, onClick }) => (
<MenuItem color={textColor} onClick={onClick}>
{label}
</MenuItem>
))}
</MenuList>
</>
)}
</Menu>
);
}
2 changes: 1 addition & 1 deletion src/common/components/StxPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface StxPriceProps {
}

const StxPriceBase: FC<StxPriceProps> = ({ tx, value }) => {
const { historicalStxPrice, currentStxPrice } = useStxPriceForTx(tx);
const { historicalStxPrice, currentStxPrice } = useStxPriceForTx(tx);

Check warning on line 21 in src/common/components/StxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L20-L21

Added lines #L20 - L21 were not covered by tests

const activeTransactionValueFilter = useAppSelector(
state => state.activeTransactionValueFilter.activeTransactionValueFilter

Check warning on line 24 in src/common/components/StxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L23-L24

Added lines #L23 - L24 were not covered by tests
Expand Down
13 changes: 2 additions & 11 deletions src/common/components/TxIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { CoinSparkleIcon } from '@/ui/icons/CoinSparkleIcon';
import React, { FC } from 'react';
import { BsCodeSlash } from 'react-icons/bs';
import {
PiArrowBendDoubleUpRightLight,
PiArrowBendDownRight,
PiClock,
PiFireLight,
PiWarningCircle,
} from 'react-icons/pi';
import { RxCube } from 'react-icons/rx';
import { PiArrowBendDownRight, PiClock, PiWarningCircle } from 'react-icons/pi';
import { TbArrowsDoubleSwNe } from 'react-icons/tb';

import { Transaction } from '@stacks/stacks-blockchain-api-types';
import { TransactionType } from '@stacks/stacks-blockchain-api-types/generated';
Expand All @@ -20,8 +13,6 @@ import { CubeSparkleIcon } from '../../ui/icons/CubeSparkleIcon';
import { TransactionStatus } from '../constants/constants';
import { TxStatus } from '../types/tx';
import { Circle } from './Circle';
import { TbArrowsDoubleSwNe } from 'react-icons/tb';
import { useIsNakamoto } from '../hooks/useIsNakamoto';

export const getTxTypeIcon = (txType: Transaction['tx_type']): FC => {
switch (txType) {
Expand Down
3 changes: 2 additions & 1 deletion src/common/queries/useMempoolTxStats.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';

Check warning on line 1 in src/common/queries/useMempoolTxStats.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useMempoolTxStats.ts#L1

Added line #L1 was not covered by tests

import { MempoolTransactionStatsResponse } from '@stacks/blockchain-api-client';

import { useApi } from '../api/useApi';
import { ONE_MINUTE } from './query-stale-time';

Check warning on line 6 in src/common/queries/useMempoolTxStats.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useMempoolTxStats.ts#L5-L6

Added lines #L5 - L6 were not covered by tests
import { MempoolTransactionStatsResponse } from '@stacks/blockchain-api-client';

export function useMempoolTransactionStats(options: any = {}) {
const api = useApi();
Expand Down
13 changes: 7 additions & 6 deletions src/common/state/slices/transaction-value-filter-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { PayloadAction, createSlice } from '@reduxjs/toolkit';
import { useAppSelector } from '../../state/hooks';

export enum TransactionValueFilterTypes {
CurrentValue = 'CurrentValue',
EstimatedValueOnDayOfTransaction = 'EstimatedValueOnDayOfTransaction',
}
CurrentValue = 'CurrentValue',
EstimatedValueOnDayOfTransaction = 'EstimatedValueOnDayOfTransaction',
}

export interface TransactionValueFilterState {
activeTransactionValueFilter: TransactionValueFilterTypes;
activeTransactionValueFilter: TransactionValueFilterTypes;
}

export const initialState: TransactionValueFilterState = {
activeTransactionValueFilter: TransactionValueFilterTypes.CurrentValue,
activeTransactionValueFilter: TransactionValueFilterTypes.CurrentValue,
};

export const activeTransactionValueFilterSlice = createSlice({
Expand All @@ -27,4 +27,5 @@ export const activeTransactionValueFilterSlice = createSlice({

export const { setTransactionValueFilter } = activeTransactionValueFilterSlice.actions;

export const useTransactionValue = () => useAppSelector(state => state.activeTransactionValueFilter.activeTransactionValueFilter);
export const useTransactionValue = () =>
useAppSelector(state => state.activeTransactionValueFilter.activeTransactionValueFilter);

Check warning on line 31 in src/common/state/slices/transaction-value-filter-slice.ts

View check run for this annotation

Codecov / codecov/patch

src/common/state/slices/transaction-value-filter-slice.ts#L31

Added line #L31 was not covered by tests
6 changes: 4 additions & 2 deletions src/common/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import {
filterAndSortReducers,
} from '../../features/txsFilterAndSort/txsFilterAndSortSlice';
import { ModalState, modalSlice } from '../components/modals/modal-slice';
import { TransactionValueFilterState, activeTransactionValueFilterSlice } from './slices/transaction-value-filter-slice';
import {
TransactionValueFilterState,
activeTransactionValueFilterSlice,
} from './slices/transaction-value-filter-slice';

const rootReducer = combineReducers({
modal: modalSlice.reducer,
search: searchSlice.reducer,
connect: sandboxSlice.reducer,
...filterAndSortReducers,
activeTransactionValueFilter: activeTransactionValueFilterSlice.reducer,

});

export const makeStore = () =>
Expand Down
9 changes: 6 additions & 3 deletions src/common/utils/test-utils/renderWithReduxProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configureStore } from '@reduxjs/toolkit';
import type { PreloadedState } from '@reduxjs/toolkit';
import { render } from '@testing-library/react';
import { configureStore } from '@reduxjs/toolkit';
import type { RenderOptions } from '@testing-library/react';
import { render } from '@testing-library/react';
import React, { PropsWithChildren } from 'react';
import { Provider } from 'react-redux';

Expand All @@ -23,8 +23,11 @@ import {
modalSlice,
initialState as modalSliceInitialState,
} from '../../components/modals/modal-slice';
import {
initialState as activeTransactionValueFilterInitialState,
activeTransactionValueFilterSlice,
} from '../../state/slices/transaction-value-filter-slice';
import { AppStore, RootState } from '../../state/store';
import { initialState as activeTransactionValueFilterInitialState, activeTransactionValueFilterSlice} from '../../state/slices/transaction-value-filter-slice';

interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> {
preloadedState?: PreloadedState<RootState>;
Expand Down
12 changes: 4 additions & 8 deletions src/features/txs-list/ListItem/TxListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, useColorMode } from '@chakra-ui/react';
import { Box } from '@chakra-ui/react';

Check warning on line 1 in src/features/txs-list/ListItem/TxListItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/features/txs-list/ListItem/TxListItem.tsx#L1

Added line #L1 was not covered by tests
import { FC, ReactNode, memo } from 'react';

import { Transaction } from '@stacks/stacks-blockchain-api-types';
Expand All @@ -12,10 +12,10 @@ import { getTransactionStatus } from '../../../common/utils/transactions';
import { MICROSTACKS_IN_STACKS, truncateMiddle } from '../../../common/utils/utils';
import { FlexProps } from '../../../ui/Flex';
import { HStack } from '../../../ui/HStack';
import { TxLink } from '../../../ui/TxLink';

Check warning on line 15 in src/features/txs-list/ListItem/TxListItem.tsx

View check run for this annotation

Codecov / codecov/patch

src/features/txs-list/ListItem/TxListItem.tsx#L15

Added line #L15 was not covered by tests
import { Caption } from '../../../ui/typography';
import { TxTitle } from '../TxTitle';
import { getTransactionTypeLabel } from '../utils';
import { TxLink } from '../../../ui/TxLink';

interface TxsListItemProps extends FlexProps {
tx: Transaction;
Expand Down Expand Up @@ -59,12 +59,8 @@ const RightTitle: FC<{ tx: Transaction }> = memo(({ tx }) => {
divider={<Caption></Caption>}
minWidth={'160px'}
>
<Box
display={['none', 'none', 'inline']}
>
<TxLink href={href} >
{truncateMiddle(tx.tx_id)}
</TxLink>
<Box display={['none', 'none', 'inline']}>
<TxLink href={href}>{truncateMiddle(tx.tx_id)}</TxLink>
</Box>
<TxTimestamp tx={tx} />
</HStack>
Expand Down
3 changes: 1 addition & 2 deletions src/features/txs-list/tabs/TxListTabsBase.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use client';

import { useParams } from 'next/navigation';
import * as React from 'react';
import { FC, ReactNode, useState } from 'react';

import { TabsContainer } from '../../../common/components/TabsContainer';
import { Box } from '../../../ui/Box';
import { FlexProps } from '../../../ui/Flex';
import { ShowValueMenu } from '../..//txsFilterAndSort/ShowValueMenu';
import { FilterButton } from '../../txsFilterAndSort/FilterButton';
import { SortMenu } from '../../txsFilterAndSort/SortMenu';
import { CSVDownloadButton } from './CSVDownloadButton';
import { ShowValueMenu } from '../..//txsFilterAndSort/ShowValueMenu';

export const TxListTabsBase: FC<
{
Expand Down
13 changes: 5 additions & 8 deletions src/features/txsFilterAndSort/ShowValueMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ export function ShowValueMenu() {
})),
[dispatch]
);
const filterLabel = useCallback(() => getActiveTransactionValueFilterLabel(activeTransactionValueFilter), [activeTransactionValueFilter]);

return (
<FilterMenu
filterLabel={filterLabel}
menuItems={menuItems}
leftIcon={PiCurrencyDollar}
/>
const filterLabel = useCallback(
() => getActiveTransactionValueFilterLabel(activeTransactionValueFilter),
[activeTransactionValueFilter]
);

return <FilterMenu filterLabel={filterLabel} menuItems={menuItems} leftIcon={PiCurrencyDollar} />;
}
2 changes: 1 addition & 1 deletion src/features/txsFilterAndSort/SortMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterMenu } from '@/common/components/FilterMenu';
import { FilterMenu } from '../../common/components/FilterMenu';
import { useCallback, useMemo } from 'react';
import { GoSortDesc } from 'react-icons/go';

Expand Down
2 changes: 1 addition & 1 deletion src/ui/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
forwardRef,
useColorModeValue,
} from '@chakra-ui/react';
import { ReactNode } from 'react';

import { UIComponent } from './types';
import { ReactNode } from 'react';

export type MenuButtonProps = CUIMenuButtonProps &
UIComponent & {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type MenuItemProps = CUIMenuItemProps & UIComponent;
export const MenuItem = forwardRef<MenuItemProps, 'button'>(({ children, size, ...rest }, ref) => {
const blackColor = useColorModeValue('slate.900', 'slate.900');
const hoverBg = useColorModeValue('slate.150 !important', 'slate.900');

return (
<CUIMenuItem
padding="12px 16px"
Expand Down
6 changes: 5 additions & 1 deletion src/ui/TxLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { FC } from 'react';

import { Box, BoxProps } from './Box';

Check warning on line 5 in src/ui/TxLink.tsx

View check run for this annotation

Codecov / codecov/patch

src/ui/TxLink.tsx#L5

Added line #L5 was not covered by tests

export const TxLink: FC<{ href?: string, openInNewTab?: boolean } & BoxProps> = ({ href, openInNewTab = false, ...rest }) => {
export const TxLink: FC<{ href?: string; openInNewTab?: boolean } & BoxProps> = ({

Check warning on line 7 in src/ui/TxLink.tsx

View check run for this annotation

Codecov / codecov/patch

src/ui/TxLink.tsx#L7

Added line #L7 was not covered by tests
href,
openInNewTab = false,
...rest
}) => {
const colorMode = useColorMode();

Check warning on line 12 in src/ui/TxLink.tsx

View check run for this annotation

Codecov / codecov/patch

src/ui/TxLink.tsx#L11-L12

Added lines #L11 - L12 were not covered by tests

return (
Expand Down

0 comments on commit d3796ce

Please sign in to comment.