Skip to content

Commit

Permalink
Revert "feat: fetch and cache token price on server"
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr authored Jan 9, 2024
1 parent 79374b3 commit ff6c347
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 110 deletions.
42 changes: 34 additions & 8 deletions src/app/_components/NavBar/BtcStxPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import * as React from 'react';
import { ReactNode } from 'react';

import { Circle } from '../../../common/components/Circle';
import { TokenPrice } from '../../../common/types/tokenPrice';
import {
useCurrentBtcPrice,
useSuspenseCurrentStxPrice,
} from '../../../common/queries/useCurrentPrices';

Check warning on line 10 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L10

Added line #L10 was not covered by tests
import { usdFormatter } from '../../../common/utils/utils';
import { Flex, FlexProps } from '../../../ui/Flex';
import { Icon } from '../../../ui/Icon';
import { Skeleton } from '../../../ui/Skeleton';

Check warning on line 14 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L14

Added line #L14 was not covered by tests
import { BitcoinIcon, StxIcon } from '../../../ui/icons';
import { ExplorerErrorBoundary } from '../ErrorBoundary';

Expand All @@ -26,13 +30,29 @@ function PriceContainer({
);
}

function BtcStxPriceBase({ tokenPrice }: { tokenPrice: TokenPrice }) {
const formattedBtcPrice = tokenPrice.btcPrice ? usdFormatter.format(tokenPrice.btcPrice) : '';
const formattedStxPrice = tokenPrice.stxPrice ? usdFormatter.format(tokenPrice.stxPrice) : '';
function BtcStxPriceBase() {

Check warning on line 33 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L33

Added line #L33 was not covered by tests
const {
data: btcPrice,
isFetching: isBtcPriceFetching,
isError: isBtcPriceError,
} = useCurrentBtcPrice();

Check warning on line 38 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L38

Added line #L38 was not covered by tests
const {
data: stxPrice,
isFetching: isStxPriceFetching,
isError: isStxPriceError,
} = useSuspenseCurrentStxPrice();

Check warning on line 43 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L43

Added line #L43 was not covered by tests
const formattedBtcPrice = btcPrice ? usdFormatter.format(btcPrice) : '';
const formattedStxPrice = stxPrice ? usdFormatter.format(stxPrice) : '';
return (
<Flex gap={6} minWidth={'172px'}>
<PriceContainer icon={<Icon as={BitcoinIcon} size={4.5} />} minWidth={'92px'}>
{!formattedBtcPrice ? 'N/A' : formattedBtcPrice}
{isBtcPriceError || !formattedBtcPrice ? (
'N/A'

Check warning on line 50 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L50

Added line #L50 was not covered by tests
) : isBtcPriceFetching ? (
<Skeleton display={'flex'} flexGrow={1} height={3} />

Check warning on line 52 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L52

Added line #L52 was not covered by tests
) : (
formattedBtcPrice

Check warning on line 54 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L54

Added line #L54 was not covered by tests
)}
</PriceContainer>
<PriceContainer
icon={
Expand All @@ -42,16 +62,22 @@ function BtcStxPriceBase({ tokenPrice }: { tokenPrice: TokenPrice }) {
}
minWidth={'56px'}
>
{!formattedStxPrice ? 'N/A' : formattedStxPrice}
{isStxPriceError || !formattedStxPrice ? (
'N/A'

Check warning on line 66 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L66

Added line #L66 was not covered by tests
) : isStxPriceFetching ? (
<Skeleton display={'flex'} flexGrow={1} height={3} />

Check warning on line 68 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L68

Added line #L68 was not covered by tests
) : (
formattedStxPrice

Check warning on line 70 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L70

Added line #L70 was not covered by tests
)}
</PriceContainer>
</Flex>
);
}

export function BtcStxPrice({ tokenPrice }: { tokenPrice: TokenPrice }) {
export function BtcStxPrice() {

Check warning on line 77 in src/app/_components/NavBar/BtcStxPrice.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/BtcStxPrice.tsx#L77

Added line #L77 was not covered by tests
return (
<ExplorerErrorBoundary renderContent={() => null}>
<BtcStxPriceBase tokenPrice={tokenPrice} />
<BtcStxPriceBase />
</ExplorerErrorBoundary>
);
}
7 changes: 3 additions & 4 deletions src/app/_components/NavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { MODALS } from '../../../common/constants/constants';
import { useGlobalContext } from '../../../common/context/useAppContext';
import { useAppDispatch } from '../../../common/state/hooks';
import { Network } from '../../../common/types/network';
import { TokenPrice } from '../../../common/types/tokenPrice';
import { buildUrl } from '../../../common/utils/buildUrl';
import { capitalize } from '../../../common/utils/utils';
import { Search } from '../../../features/search/Search';
Expand All @@ -28,7 +27,7 @@ import { NetworkLabel } from './NetworkLabel';
import { NetworkModeBanner } from './NetworkModeBanner';
import { NavItem } from './types';

export function NavBar({ tokenPrice }: { tokenPrice: TokenPrice }) {
export const NavBar: FC = () => {

Check warning on line 30 in src/app/_components/NavBar/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/NavBar/index.tsx#L30

Added line #L30 was not covered by tests
const { isOpen, onToggle } = useDisclosure();
const { networks, activeNetwork } = useGlobalContext();
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -97,7 +96,7 @@ export function NavBar({ tokenPrice }: { tokenPrice: TokenPrice }) {
<ColorModeButton aria-label={'Change color mode'} />
<DesktopNav navItems={navItems} />
</Flex>
<BtcStxPrice tokenPrice={tokenPrice} />
<BtcStxPrice />
</Show>
<Show below="lg">
<IconButton
Expand All @@ -111,4 +110,4 @@ export function NavBar({ tokenPrice }: { tokenPrice: TokenPrice }) {
</Flex>
</Box>
);
}
};
11 changes: 2 additions & 9 deletions src/app/_components/PageWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useColorModeValue } from '@chakra-ui/react';
import React, { ReactNode } from 'react';

import { AddNetworkModal } from '../../common/components/modals/AddNetwork';
import { TokenPrice } from '../../common/types/tokenPrice';
import { Flex } from '../../ui/Flex';
import { Footer } from './Footer';
import { NavBar } from './NavBar';
Expand Down Expand Up @@ -46,19 +45,13 @@ function WrapperWithBg({ children }: { children: ReactNode }) {
);
}

export function PageWrapper({
tokenPrice,
children,
}: {
tokenPrice: TokenPrice;
children: ReactNode;
}) {
export function PageWrapper({ children }: { children: ReactNode }) {

Check warning on line 48 in src/app/_components/PageWrapper.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/PageWrapper.tsx#L48

Added line #L48 was not covered by tests
return (
<>
<IncidentsStatusBarWithErrorBoundary />
<WrapperWithBg>
<Flex mx="auto" width="full" maxWidth="container.xl" flexDirection="column" p={6}>
<NavBar tokenPrice={tokenPrice} />
<NavBar />
<Flex direction={'column'} mt={10} gap={7}>
{children}
</Flex>
Expand Down
46 changes: 0 additions & 46 deletions src/app/getTokenPriceInfo.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ import { Analytics } from './_components/Analytics';
import { GA } from './_components/GA';
import { PageWrapper } from './_components/PageWrapper';
import { Providers } from './_components/Providers';
import { getTokenPrice } from './getTokenPriceInfo';
import './global.css';

export async function generateMetadata(): Promise<Metadata> {
return Promise.resolve(meta);
}

export default async function RootLayout({ children }: { children: ReactNode }) {
export default function RootLayout({ children }: { children: ReactNode }) {

Check warning on line 24 in src/app/layout.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/layout.tsx#L24

Added line #L24 was not covered by tests
const headersList = headers();
const tokenPrice = await getTokenPrice();
return (
<html lang="en">
<body>
Expand All @@ -36,7 +34,7 @@ export default async function RootLayout({ children }: { children: ReactNode })
btcAddressBaseUrls={NetworkModeBtcAddressBaseUrlMap}
>
<Providers headerCookies={headersList.get('cookie')}>
<PageWrapper tokenPrice={tokenPrice}>{children}</PageWrapper>
<PageWrapper>{children}</PageWrapper>
</Providers>
</AppContextProvider>
</body>
Expand Down
21 changes: 13 additions & 8 deletions src/app/transactions/MempoolFeeStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { MempoolFeePrioritiesAll } from '@stacks/blockchain-api-client/src/gener

import { getTxTypeIcon } from '../../common/components/TxIcon';
import { useSuspenseMempoolFee } from '../../common/queries/usMempoolFee';
import { TokenPrice } from '../../common/types/tokenPrice';
import {
useCurrentStxPrice,
useSuspenseCurrentStxPrice,
} from '../../common/queries/useCurrentPrices';

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

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L11

Added line #L11 was not covered by tests
import { MICROSTACKS_IN_STACKS, capitalize, getUsdValue } from '../../common/utils/utils';
import { Box } from '../../ui/Box';
import { Flex, FlexProps } from '../../ui/Flex';
Expand Down Expand Up @@ -94,41 +97,43 @@ function MempoolFeeSection({
);
}

export function MempoolFeeStats({ tokenPrice }: { tokenPrice: TokenPrice }) {
export function MempoolFeeStats() {

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

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/MempoolFeeStats.tsx#L100

Added line #L100 was not covered by tests
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#L102-L103

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

export function MempoolFeeStatsWithErrorBoundary({ tokenPrice }: { tokenPrice: TokenPrice }) {
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}>
<MempoolFeeStats tokenPrice={tokenPrice} />
<MempoolFeeStats />
</ExplorerErrorBoundary>
);
}
21 changes: 0 additions & 21 deletions src/app/transactions/TransactionPage.tsx

This file was deleted.

53 changes: 47 additions & 6 deletions src/app/transactions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
'use client';

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';

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

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L9

Added line #L9 was not covered by tests
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

import { getTokenPrice } from '../getTokenPriceInfo';
import TransactionsPage from './TransactionPage';
const TransactionsPage: NextPage = () => {

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

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L38

Added line #L38 was not covered by tests
return (
<>
<Flex justifyContent={'space-between'} alignItems={'flex-end'}>
<PageTitle>Transactions</PageTitle>
</Flex>
<MempoolFeeStatsWithErrorBoundary />
<TxListTabs />
</>
);
};

export default async function () {
const tokenPrice = await getTokenPrice();
return <TransactionsPage tokenPrice={tokenPrice} />;
}
export default TransactionsPage;

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

View check run for this annotation

Codecov / codecov/patch

src/app/transactions/page.tsx#L50

Added line #L50 was not covered by tests
4 changes: 0 additions & 4 deletions src/common/types/tokenPrice.ts

This file was deleted.

0 comments on commit ff6c347

Please sign in to comment.