Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ui updates #1442

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/app/PageClient.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';

import dynamic from 'next/dynamic';
import * as React from 'react';

import { DEFAULT_BLOCKS_LIST_LIMIT, DEFAULT_LIST_LIMIT_SMALL } from '../common/constants/constants';
import { useGlobalContext } from '../common/context/useAppContext';
Expand All @@ -13,8 +12,8 @@

const NonPaginatedBlockListLayoutA = dynamic(
() =>
import('./_components/BlockList/LayoutA/NonPaginated').then(
mod => mod.NonPaginatedBlockListLayoutA

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

View check run for this annotation

Codecov / codecov/patch

src/app/PageClient.tsx#L15-L16

Added lines #L15 - L16 were not covered by tests
),
{
loading: () => <SkeletonBlockList />,
Expand All @@ -36,7 +35,7 @@
<Grid
gap="7"
width="full"
gridTemplateColumns={['100%', '100%', 'minmax(0, 0.6fr) minmax(0, 0.4fr)']}
gridTemplateColumns={['100%', '100%', '100%', 'minmax(0, 0.6fr) minmax(0, 0.4fr)']}
>
<TxListTabs limit={DEFAULT_LIST_LIMIT_SMALL} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ exports[`BlockListWithControls renders correctly 1`] = `
<span
class="chakra-text css-nvxyq8"
>
in 54062 years
in 54066 years
</span>
</div>
</div>
Expand Down Expand Up @@ -256,7 +256,7 @@ exports[`BlockListWithControls renders correctly 1`] = `
<span
class="chakra-text css-nvxyq8"
>
in 54062 years
in 54066 years
</span>
</div>
</div>
Expand Down Expand Up @@ -303,7 +303,7 @@ exports[`BlockListWithControls renders correctly 1`] = `
<span
class="chakra-text css-nvxyq8"
>
in 54062 years
in 54066 years
</span>
</div>
</div>
Expand Down Expand Up @@ -377,7 +377,7 @@ exports[`BlockListWithControls renders correctly 1`] = `
<span
class="chakra-text css-nvxyq8"
>
in 54062 years
in 54066 years
</span>
</div>
</div>
Expand Down
24 changes: 3 additions & 21 deletions src/app/sandbox/components/TransactionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useColorMode } from '@chakra-ui/react';
import { useRouter } from 'next/navigation';
import React, { Fragment, useMemo } from 'react';
import React, { useMemo } from 'react';

Check warning on line 5 in src/app/sandbox/components/TransactionsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/sandbox/components/TransactionsPanel.tsx#L5

Added line #L5 was not covered by tests
import { BsChevronDown } from 'react-icons/bs';

import { Transaction } from '@stacks/stacks-blockchain-api-types';
Expand All @@ -18,7 +18,7 @@
import { MempoolTxListItemMini } from '../../../features/txs-list/ListItem/MempoolTxListItemMini';
import { TxListItemMini } from '../../../features/txs-list/ListItem/TxListItemMini';
import { FilterButton } from '../../../features/txsFilterAndSort/FilterButton';
import { FilteredMessage } from '../../../features/txsFilterAndSort/FilterPanel';
import { AllTransactionsFilteredMessage } from '../../../features/txsFilterAndSort/TransactionMessages';

Check warning on line 21 in src/app/sandbox/components/TransactionsPanel.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/sandbox/components/TransactionsPanel.tsx#L21

Added line #L21 was not covered by tests
import { useFilterAndSortState } from '../../../features/txsFilterAndSort/useFilterAndSortState';
import { Accordion } from '../../../ui/Accordion';
import { AccordionButton } from '../../../ui/AccordionButton';
Expand All @@ -36,23 +36,6 @@
import { useUser } from '../hooks/useUser';
import { setCodeBody, toggleRightPanel } from '../sandbox-slice';

const PanelHeader: React.FC = () => {
return (
<>
<Flex
justifyContent="space-between"
px="16px"
borderBottomWidth="1px"
py="8px"
bg={`bg.${useColorMode().colorMode}`}
>
<Caption>Transactions</Caption>
<FilterButton />
</Flex>
</>
);
};

const LoadButton = ({ codeBody }: { codeBody: string }) => {
const router = useRouter();
const network = useGlobalContext().activeNetwork;
Expand Down Expand Up @@ -198,7 +181,6 @@
: tx.tx_type === 'contract_call'
? tx.contract_call.contract_id
: undefined;
const colorMode = useColorMode().colorMode;

const { data: contract } = useContractById(contractId);

Expand Down Expand Up @@ -300,7 +282,7 @@
{filteredTxs?.length ? (
<Accordion allowMultiple>{txList}</Accordion>
) : hasTxButIsFiltered ? (
<FilteredMessage />
<AllTransactionsFilteredMessage />
) : (
<Flex flexGrow={1} flexDirection="column" alignItems="center" justifyContent="center">
<Stack textAlign="center">
Expand Down
2 changes: 0 additions & 2 deletions src/app/txid/[txId]/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Code } from '@chakra-ui/react';
import React, { FC, Fragment } from 'react';
import { IconType } from 'react-icons';
import { TbAlignLeft, TbArrowRight, TbPlus, TbTrash } from 'react-icons/tb';

import {
Expand All @@ -29,7 +28,6 @@ import {
} from '../../../common/utils/utils';
import { Box } from '../../../ui/Box';
import { Flex } from '../../../ui/Flex';
import { Grid } from '../../../ui/Grid';
import { HStack } from '../../../ui/HStack';
import { Icon } from '../../../ui/Icon';
import { StxIcon } from '../../../ui/icons';
Expand Down
2 changes: 0 additions & 2 deletions src/app/txid/[txId]/TxDetails/BlockHeight.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use client';

import * as React from 'react';
import { Fragment } from 'react';
import { AiOutlineClockCircle } from 'react-icons/ai';

import { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';
Expand Down
11 changes: 4 additions & 7 deletions src/common/components/BtcStxBlockLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use client';

import { useColorMode } from '@chakra-ui/react';
import * as React from 'react';
import { FC, Fragment } from 'react';
import { PiArrowRightLight } from 'react-icons/pi';

import { Flex } from '../../ui/Flex';
import { Icon } from '../../ui/Icon';
import { Text } from '../../ui/Text';
import { TextLink } from '../../ui/TextLink';
import { BitcoinIcon, StxIcon } from '../../ui/icons';
import { useGlobalContext } from '../context/useAppContext';
Expand All @@ -31,16 +28,16 @@ export const BtcStxBlockLinks: FC<BtcStxBlockLinksProps> = ({

return (
<Flex flexWrap={'wrap'} alignItems={'center'} gap={1.5}>
<Circle size={4.5} bg="purple.600">
<Icon as={StxIcon} size={2.5} color="white" />
<Circle size={'18px'} bg="purple.600">
<Icon as={StxIcon} size={'10px'} color="white" />
</Circle>
<BlockLink hash={stxBlockHash} fontWeight={'medium'} fontSize={'sm'}>
#{stxBlockHeight}
</BlockLink>
{btcBlockHeight && (
<Fragment>
<Icon as={PiArrowRightLight} size={4} color={'slate.700'} />
<Icon as={BitcoinIcon} size={4.5} />
<Icon as={PiArrowRightLight} size={'16px'} color={'slate.700'} />
<Icon as={BitcoinIcon} size={'18px'} />
<TextLink
href={`${btcBlockBaseUrl}/${btcBlockHeight}`}
target="_blank"
Expand Down
34 changes: 25 additions & 9 deletions src/common/components/ExplorerLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
'use client';

import { forwardRef } from '@chakra-ui/react';
import React from 'react';

import { Link, LinkProps } from '../../ui/Link';
import { useGlobalContext } from '../context/useAppContext';
import { buildUrl } from '../utils/buildUrl';

export const ExplorerLink = forwardRef<LinkProps, 'a'>(({ href, ...rest }, ref) => {
const network = useGlobalContext().activeNetwork;
return <Link ref={ref} href={buildUrl(href!, network)} {...rest} />;
});

export const TxLink = forwardRef<Partial<LinkProps> & { txId: string }, 'a'>(
({ txId, ...rest }, ref) => {
return <ExplorerLink ref={ref} href={`/txid/${encodeURIComponent(txId)}`} {...rest} />;
export const ExplorerLink = forwardRef<LinkProps & { openInNewTab?: boolean }, 'a'>(
({ href, openInNewTab, ...rest }, ref) => {
const network = useGlobalContext().activeNetwork;
return (
<Link
ref={ref}
href={buildUrl(href!, network)}
{...(openInNewTab && { target: '_blank' })}
{...rest}
/>
);
}
);

export const TxLink = forwardRef<
Partial<LinkProps> & { txId: string; openInNewTab?: boolean },
'a'
>(({ txId, openInNewTab = false, ...rest }, ref) => {
return (
<ExplorerLink
ref={ref}
href={`/txid/${encodeURIComponent(txId)}`}
openInNewTab={openInNewTab}
{...rest}
/>
);
});

export const TokenLink = forwardRef<Partial<LinkProps> & { tokenId: string }, 'a'>(
({ tokenId, ...rest }, ref) => {
return <ExplorerLink ref={ref} href={`/token/${encodeURIComponent(tokenId)}`} {...rest} />;
Expand Down
76 changes: 76 additions & 0 deletions src/common/components/FilterMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { useColorModeValue } from '@chakra-ui/react';
import { ReactNode, isValidElement } from 'react';
import { IconType } from 'react-icons';
import { BsChevronDown } from 'react-icons/bs';

import { Box } from '../../ui/Box';
import { Button } from '../../ui/Button';
import { Icon } from '../../ui/Icon';
import { Menu } from '../../ui/Menu';
import { MenuButton } from '../../ui/MenuButton';
import { MenuItem } from '../../ui/MenuItem';
import { MenuList } from '../../ui/MenuList';

interface MenuItem {
onClick: () => void;
label: string;
}

interface FilterMenuProps {
filterLabel: string | (() => string);
menuItems: MenuItem[] | ReactNode[];
leftIcon: IconType;
}

function isMenuItemArray(items: any[]): items is { label: string; onClick: () => void }[] {
return items.every(item => typeof item.label === 'string' && typeof item.onClick === 'function');
}

function isReactNodeArray(items: any[]): items is React.ReactNode[] {
return items.every(isValidElement);

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/FilterMenu.tsx#L29-L30

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

export function FilterMenu({ filterLabel, menuItems, leftIcon }: FilterMenuProps) {
const borderColor = useColorModeValue('slate.300', 'slate.900');
const filterLabelValue = typeof filterLabel === 'function' ? filterLabel?.() : filterLabel;

return (
<Menu>
{({ isOpen }) => (
<>
<MenuButton
as={Button}
rightIcon={<Icon as={BsChevronDown} size={3} color="text" />}
leftIcon={<Icon as={leftIcon} size={4} color={isOpen ? 'text' : 'secondaryText'} />}
fontSize={'sm'}
bg={'bg'}
fontWeight={'semibold'}
border={'1px'}
borderColor={borderColor}
_hover={{ color: 'text', backgroundColor: 'border' }}
_active={{ color: 'text', backgroundColor: 'border' }}
_focus={{ color: 'text', backgroundColor: 'border' }}
>
<Box display="inline" fontWeight="normal" color={isOpen ? 'text' : 'secondaryText'}>
Show:{' '}
</Box>
<Box display="inline" fontWeight="normal" color={'text'}>
{filterLabelValue}
</Box>
</MenuButton>
<MenuList fontSize={'sm'} padding="8px">
{isMenuItemArray(menuItems)
? menuItems.map(({ label, onClick }) => (
<MenuItem color={'text'} onClick={onClick}>
{label}
</MenuItem>
))
: isReactNodeArray(menuItems)
? menuItems
: null}

Check warning on line 70 in src/common/components/FilterMenu.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/FilterMenu.tsx#L69-L70

Added lines #L69 - L70 were not covered by tests
</MenuList>
</>
)}
</Menu>
);
}
64 changes: 64 additions & 0 deletions src/common/components/StxPrice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use client';

import { useColorModeValue } from '@chakra-ui/react';
import { FC, useMemo } from 'react';

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests

import { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';

import { ExplorerErrorBoundary } from '../../app/_components/ErrorBoundary';
import { Flex } from '../../ui/Flex';
import { useAppSelector } from '../state/hooks';
import { TransactionValueFilterTypes } from '../state/slices/transaction-value-filter-slice';
import { getUsdValue } from '../utils/utils';
import { useStxPriceForTx } from './StxPriceButton/useStxPriceForTx';

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L8-L13

Added lines #L8 - L13 were not covered by tests

interface StxPriceProps {
tx: Transaction | MempoolTransaction;
value: number;
}

const StxPriceBase: FC<StxPriceProps> = ({ tx, value }) => {
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
);
const currentPriceFormatted = useMemo(
() => getUsdValue(value, currentStxPrice, true),

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L26-L27

Added lines #L26 - L27 were not covered by tests
[currentStxPrice, value]
);
const historicalPriceFormatted = useMemo(
() => getUsdValue(value, historicalStxPrice, true),

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L30-L31

Added lines #L30 - L31 were not covered by tests
[historicalStxPrice, value]
);

return (
<Flex
height="24px"
justifyContent={'center'}
alignItems={'center'}
borderRadius="md"
padding="0px 8px"
ml={'5px'}
fontSize={'xs'}
_focus={{ outline: 0 }}
flexShrink={0}
suppressHydrationWarning={true}
bg={useColorModeValue('purple.200', 'purple.400')}
_hover={{ bg: useColorModeValue('purple.300', 'purple.300') }}
color={'black'}
>
{activeTransactionValueFilter === TransactionValueFilterTypes.CurrentValue
? currentPriceFormatted
: historicalPriceFormatted}

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L52-L53

Added lines #L52 - L53 were not covered by tests
</Flex>
);
};

export function StxPrice(props: StxPriceProps) {

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L58

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

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

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPrice.tsx#L60

Added line #L60 was not covered by tests
<StxPriceBase {...props} />
</ExplorerErrorBoundary>
);
}
4 changes: 1 addition & 3 deletions src/common/components/StxPriceButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use client';

import { useColorMode, useColorModeValue } from '@chakra-ui/react';
import { useColorModeValue } from '@chakra-ui/react';

Check warning on line 3 in src/common/components/StxPriceButton/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/common/components/StxPriceButton/index.tsx#L3

Added line #L3 was not covered by tests
import { FC, useCallback, useMemo, useState } from 'react';
import * as React from 'react';

import { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';

import { ExplorerErrorBoundary } from '../../../app/_components/ErrorBoundary';
import { Box } from '../../../ui/Box';
import { Button } from '../../../ui/Button';
import { Tooltip } from '../../../ui/Tooltip';
import { getUsdValue } from '../../utils/utils';
Expand Down
Loading
Loading