Skip to content

Commit

Permalink
feat: got stacking page rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Feb 7, 2025
1 parent f9bdd77 commit b70d8ee
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 101 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"eslint-plugin-import": "2.29.0",
"express": "4.19.2",
"formik": "2.4.3",
"gsap": "^3.12.7",
"http-status-codes": "2.3.0",
"husky": "8.0.3",
"ioredis": "5.3.2",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/app/block/[hash]/BlockBtcAnchorBlockCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { useBlockByHash } from '../../../common/queries/useBlockByHash';
import { useBlockByHeightOrHash } from '../../../common/queries/useBlockByHash';

Check warning on line 3 in src/app/block/[hash]/BlockBtcAnchorBlockCard.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/BlockBtcAnchorBlockCard.tsx#L3

Added line #L3 was not covered by tests
import { BtcAnchorBlockCardBase } from '../../_components/BtcAnchorBlockCard';
import { ExplorerErrorBoundary } from '../../_components/ErrorBoundary';
import { useParamsBlockHash } from './useParamsBlockHash';

function BlockBtcAnchorBlockCardBase() {
const { data: block } = useBlockByHash(useParamsBlockHash(), {
const { data: block } = useBlockByHeightOrHash(useParamsBlockHash(), {

Check warning on line 9 in src/app/block/[hash]/BlockBtcAnchorBlockCard.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/block/[hash]/BlockBtcAnchorBlockCard.tsx#L9

Added line #L9 was not covered by tests
refetchOnWindowFocus: true,
});
return <BtcAnchorBlockCardBase block={block} />;
Expand Down
11 changes: 6 additions & 5 deletions src/app/stacking/CycleInformation.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Box, Stack, Flex, Icon } from '@chakra-ui/react';
import { Text } from '@/ui/Text';
import { Box, Flex, Icon, Stack } from '@chakra-ui/react';
import { ArrowRight } from '@phosphor-icons/react';
import gsap from 'gsap';
import { useEffect, useRef } from 'react';

Check warning on line 5 in src/app/stacking/CycleInformation.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/CycleInformation.tsx#L1-L5

Added lines #L1 - L5 were not covered by tests

import { Text } from '@/ui/Text';

function CountdownBadge({ daysLeft }: { daysLeft: number }) {
const outerDotRef = useRef<HTMLDivElement>(null);
const middleDotRef = useRef<HTMLDivElement>(null);

Check warning on line 9 in src/app/stacking/CycleInformation.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/CycleInformation.tsx#L7-L9

Added lines #L7 - L9 were not covered by tests
Expand Down Expand Up @@ -96,7 +95,9 @@ export const CycleInformation = ({
<Text fontSize={40} fontWeight="400">
{id}
</Text>
<Icon as={ArrowRight} size={6} weight="bold" />
<Icon h={6} w={6} color="iconPrimary">
<ArrowRight weight="bold" />
</Icon>
</Flex>
<StackedStxMetric stxStacked={stxStacked} />
</Stack>
Expand All @@ -113,7 +114,7 @@ const StackedStxMetric = ({ stxStacked }: { stxStacked: number }) => {
{`${stackedStxString} STX`}
</Text>
&nbsp;
<Text as="span" fontSize="xl" fontWeight="bold" color="textSubdued" whiteSpace="nowrap">
<Text fontSize="xl" fontWeight="bold" color="textSubdued" whiteSpace="nowrap">
($124.3M)
</Text>
&nbsp;
Expand Down
20 changes: 5 additions & 15 deletions src/app/stacking/PoxCycleDiagram.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { useBreakpointValue } from '../../ui/hooks/useBreakpointValue';
import { VerticalPoxCycleDiagram } from './VerticalPoxCycleDiagram';
import { HorizontalPoxCycleDiagram } from './horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram';
import { usePoxCycle } from './usePoxCycle';

Check warning on line 3 in src/app/stacking/PoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/PoxCycleDiagram.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

export const PoxCycleDiagram = () => {
const poxCycleData = usePoxCycle();

Check warning on line 6 in src/app/stacking/PoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/PoxCycleDiagram.tsx#L5-L6

Added lines #L5 - L6 were not covered by tests

const poxCycleDiagram = useBreakpointValue(
{
lg: <HorizontalPoxCycleDiagram data={poxCycleData} />,
md: <VerticalPoxCycleDiagram data={poxCycleData} />,
sm: <VerticalPoxCycleDiagram data={poxCycleData} />,
xs: <VerticalPoxCycleDiagram data={poxCycleData} />,
base: <VerticalPoxCycleDiagram data={poxCycleData} />,
},
{
fallback: 'lg',
ssr: false,
}
return (
<>
<HorizontalPoxCycleDiagram data={poxCycleData} hideBelow="lg" />
<VerticalPoxCycleDiagram data={poxCycleData} hideFrom="lg" />
</>
);

return poxCycleDiagram ?? null;
};
16 changes: 12 additions & 4 deletions src/app/stacking/PreviousCyclesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ export function PreviousCyclesTable() {
return (
<Flex gap={2}>
<Flex gap={1} alignItems="center">
<Icon as={BitcoinIcon} size={2} />
<Icon h={2} w={2}>
<BitcoinIcon />
</Icon>
<Text fontSize="sm">{val.bitcoin}</Text>
</Flex>
<Flex gap={1} alignItems="center">
<Icon as={StxIcon} size={2} />
<Icon h={2} w={2}>
<StxIcon />
</Icon>
<Text fontSize="sm">{val.stx}</Text>
</Flex>
</Flex>
Expand All @@ -81,11 +85,15 @@ export function PreviousCyclesTable() {
return (
<Flex gap={2}>
<Flex gap={1} alignItems="center">
<Icon as={BitcoinIcon} size={2} />
<Icon h={2} w={2}>
<BitcoinIcon />
</Icon>
<Text fontSize="sm">{val.bitcoin}</Text>
</Flex>
<Flex gap={1} alignItems="center">
<Icon as={StxIcon} size={2} />
<Icon h={2} w={2}>
<StxIcon />
</Icon>
<Text fontSize="sm">{val.stx}</Text>
</Flex>
</Flex>
Expand Down
14 changes: 6 additions & 8 deletions src/app/stacking/ReverseAccordion.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Plus, X } from '@phosphor-icons/react';
import { RefObject, createRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';

import { Button } from '@/ui/Button';
import { Text } from '@/ui/Text';
import { Box, Flex, Icon, Stack } from '@chakra-ui/react';
import { Plus, X } from '@phosphor-icons/react';
import { RefObject, createRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';

Check warning on line 5 in src/app/stacking/ReverseAccordion.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/ReverseAccordion.tsx#L1-L5

Added lines #L1 - L5 were not covered by tests

import useResizeObserver from './useResizeObserver';

Check warning on line 7 in src/app/stacking/ReverseAccordion.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/ReverseAccordion.tsx#L7

Added line #L7 was not covered by tests

const cardPaddingY = 3;
Expand Down Expand Up @@ -102,11 +102,9 @@ function ReverseAccordionItem({
w="full"
>
<Text fontWeight="medium">{title}</Text>
<Icon
as={isExpanded ? X : Plus}
onClick={() => (isExpanded ? setIsExpanded(index, false) : null)}
size={4}
/>
<Icon onClick={() => (isExpanded ? setIsExpanded(index, false) : null)} h={4} w={4}>
{isExpanded ? <X /> : <Plus />}
</Icon>
</Flex>
</Flex>
<Flex ref={contentRef} height="fit-content" flexDirection="column" gap={4} px={3} pb={3}>
Expand Down
52 changes: 25 additions & 27 deletions src/app/stacking/StackersEarnings.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import { Card } from '@/common/components/Card';
import { Text } from '@/ui/Text';
import { Box, Flex, Stack, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react';
import { Box, Flex, Stack, Tabs } from '@chakra-ui/react';

Check warning on line 3 in src/app/stacking/StackersEarnings.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/StackersEarnings.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

function CustomTab({ children }: { children: React.ReactNode }) {
function CustomTab({ children, value }: { children: React.ReactNode; value: string }) {

Check warning on line 5 in src/app/stacking/StackersEarnings.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/StackersEarnings.tsx#L5

Added line #L5 was not covered by tests
return (
<Tab>
<Tabs.Trigger value={value}>
<Box py={2} px={4} bg="sand.150" borderRadius="full">
{children}
</Box>
</Tab>
</Tabs.Trigger>
);
}

export function StackersEarnings() {

Check warning on line 15 in src/app/stacking/StackersEarnings.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/StackersEarnings.tsx#L15

Added line #L15 was not covered by tests
return (
<Card p={5} bg="sand.50" border="1px solid var(--stacks-colors-sand-150)" w="full">
<Flex>
<Tabs>
<TabList mb={4} p={0} border="none">
<Tab>All Time</Tab>
<Tab>Last Cycle</Tab>
</TabList>
<TabPanels>
<TabPanel gap={0}>
<Stack gap={2}>
<Text fontSize={20}>Stackers have earned</Text>
<Flex alignItems="self-end" gap={1}>
<Text fontSize={30} fontWeight="semi-bold">
142,532 BTC
</Text>
<Text fontSize={20} color="textSubdued">
($8.4M)
</Text>
</Flex>
<Text fontSize={20}>in rewards ✨</Text>
</Stack>
</TabPanel>
<TabPanel gap={0}></TabPanel>
</TabPanels>
</Tabs>
<Tabs.Root>
<Tabs.List mb={4} p={0} border="none">
<Tabs.Trigger value="all-time">All Time</Tabs.Trigger>
<Tabs.Trigger value="last-cycle">Last Cycle</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="all-time" gap={0}>
<Stack gap={2}>
<Text fontSize={20}>Stackers have earned</Text>
<Flex alignItems="self-end" gap={1}>
<Text fontSize={30} fontWeight="semi-bold">
142,532 BTC
</Text>
<Text fontSize={20} color="textSubdued">
($8.4M)
</Text>
</Flex>
<Text fontSize={20}>in rewards ✨</Text>
</Stack>
</Tabs.Content>
<Tabs.Content value="last-cycle" gap={0}></Tabs.Content>
</Tabs.Root>
</Flex>
</Card>
);
Expand Down
6 changes: 3 additions & 3 deletions src/app/stacking/VerticalPoxCycleDiagram.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useRef, useState } from 'react';

Check warning on line 1 in src/app/stacking/VerticalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/VerticalPoxCycleDiagram.tsx#L1

Added line #L1 was not covered by tests

import { Text } from '@/ui/Text';
import { Box, Flex, Stack } from '@chakra-ui/react';
import { Box, Flex, Stack, StackProps } from '@chakra-ui/react';
import { CycleInformation } from './CycleInformation';

Check warning on line 5 in src/app/stacking/VerticalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/VerticalPoxCycleDiagram.tsx#L3-L5

Added lines #L3 - L5 were not covered by tests
import { PoxCycleInfo } from './usePoxCycle';

export const VerticalPoxCycleDiagram = ({ data }: { data: PoxCycleInfo }) => {
export const VerticalPoxCycleDiagram = ({ data, ...stackProps }: { data: PoxCycleInfo } & StackProps) => {

Check warning on line 8 in src/app/stacking/VerticalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/VerticalPoxCycleDiagram.tsx#L8

Added line #L8 was not covered by tests
const {
currentCycleId,
currentCycleStackedStx,
Expand All @@ -21,7 +21,7 @@ export const VerticalPoxCycleDiagram = ({ data }: { data: PoxCycleInfo }) => {
} = data;

Check warning on line 21 in src/app/stacking/VerticalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/VerticalPoxCycleDiagram.tsx#L21

Added line #L21 was not covered by tests

return (
<Stack bg="sand.150" w="full" alignItems="center" borderRadius="2xl" pl={8} py={6}>
<Stack bg="sand.150" w="full" alignItems="center" borderRadius="2xl" pl={8} py={6} {...stackProps}>
<Box w="full">
<Flex pb={6} pr={8} justifyContent="space-between">
<CycleInformation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react';

Check warning on line 1 in src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx#L1

Added line #L1 was not covered by tests

import { Box, Flex, Grid, Stack } from '@chakra-ui/react';
import { Box, Flex, Grid, GridProps, Stack } from '@chakra-ui/react';
import { CycleInformation } from '../CycleInformation';

Check warning on line 4 in src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests
import { PoxCycleInfo } from '../usePoxCycle';
import { useResizeObserver } from '../useResizeObserver';
Expand All @@ -11,7 +11,7 @@ const sizePadding = 4;
const progressBarSize = 2 + 2 + 2 + 15 + 4;
const size = sizePadding * 2 + progressBarSize;

Check warning on line 12 in src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx#L10-L12

Added lines #L10 - L12 were not covered by tests

export const HorizontalPoxCycleDiagram = ({ data }: { data: PoxCycleInfo }) => {
export const HorizontalPoxCycleDiagram = ({ data, ...gridProps }: { data: PoxCycleInfo } & GridProps) => {

Check warning on line 14 in src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx#L14

Added line #L14 was not covered by tests
const {
currentCycleId,
prepareCycleProgress,
Expand Down Expand Up @@ -53,7 +53,7 @@ export const HorizontalPoxCycleDiagram = ({ data }: { data: PoxCycleInfo }) => {
console.log({ progressBarBottom });

Check warning on line 53 in src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/horizontal-pox-cycle-diagram/HorizontalPoxCycleDiagram.tsx#L53

Added line #L53 was not covered by tests

return (
<Grid templateColumns="2fr 1fr" w="full" h="full" className="pox-cycle-diagram">
<Grid templateColumns="2fr 1fr" w="full" h="full" className="pox-cycle-diagram" {...gridProps}>
<Stack bg="sand.150" w="full" alignItems="center" borderRadius="2xl" pl={8} py={6}>
<Stack w="full" h="full" className="cycle-section-container">
<Flex pr={8}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ export function NextCycleProgressBar({
</Text>
</Box>
<Flex gap={1}>
<Icon as={BitcoinIcon} size={4} position={'relative'} bottom={'1px'} />
<Icon h={4} w={4} position={'relative'} bottom={'1px'}>
<BitcoinIcon />
</Icon>
<Text whiteSpace="nowrap" fontSize="xs">
#{start.bitcoinBlockNumber}
</Text>
Expand All @@ -128,7 +130,9 @@ export function NextCycleProgressBar({
Bitcoin block {start.bitcoinBlockNumber}
</Text> */}
<Flex gap={1}>
<Icon as={StxIcon} size={4} position={'relative'} bottom={'1px'} />
<Icon h={4} w={4} position={'relative'} bottom={'1px'}>
<StxIcon />
</Icon>
<Text whiteSpace="nowrap" fontSize="xs">
#{start.stacksBlockNumber}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions src/app/stacking/usePoxCycle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NUM_SECONDS_IN_TEN_MINUTES } from '../../common/constants/constants';
import { useBlockByHeight } from '../../common/queries/useBlockByHeight';
import { useBlockByHeightOrHash } from '../../common/queries/useBlockByHash';
import { useSuspensePoxInfoRaw } from '../../common/queries/usePoxInforRaw';

Check warning on line 3 in src/app/stacking/usePoxCycle.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/usePoxCycle.tsx#L1-L3

Added lines #L1 - L3 were not covered by tests

export interface PoxCycleInfo {
Expand Down Expand Up @@ -33,7 +33,7 @@ export function usePoxCycle(): PoxCycleInfo {
const { data: poxInfo } = useSuspensePoxInfoRaw();

Check warning on line 33 in src/app/stacking/usePoxCycle.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/usePoxCycle.tsx#L32-L33

Added lines #L32 - L33 were not covered by tests

const currentBurnChainBlockHeight = poxInfo.current_burnchain_block_height;
const { data: currentBlockData } = useBlockByHeight(currentBurnChainBlockHeight);
const { data: currentBlockData } = useBlockByHeightOrHash(currentBurnChainBlockHeight.toString());

Check warning on line 36 in src/app/stacking/usePoxCycle.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/usePoxCycle.tsx#L35-L36

Added lines #L35 - L36 were not covered by tests
const currentBlockDate = currentBlockData?.block_time_iso
? new Date(currentBlockData.block_time_iso)
: undefined;

Check warning on line 39 in src/app/stacking/usePoxCycle.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/stacking/usePoxCycle.tsx#L38-L39

Added lines #L38 - L39 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions src/app/txid/[txId]/useTxBlock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';

import { useBlockByHash } from '../../../common/queries/useBlockByHash';
import { useBlockByHeightOrHash } from '../../../common/queries/useBlockByHash';

Check warning on line 3 in src/app/txid/[txId]/useTxBlock.ts

View check run for this annotation

Codecov / codecov/patch

src/app/txid/[txId]/useTxBlock.ts#L3

Added line #L3 was not covered by tests

export function useTxBlock(tx: Transaction | MempoolTransaction) {
const hash = 'block_hash' in tx && tx.block_hash !== '0x' ? tx.block_hash : undefined;
return useBlockByHash(hash);
return useBlockByHeightOrHash(hash);

Check warning on line 7 in src/app/txid/[txId]/useTxBlock.ts

View check run for this annotation

Codecov / codecov/patch

src/app/txid/[txId]/useTxBlock.ts#L7

Added line #L7 was not covered by tests
}
Loading

0 comments on commit b70d8ee

Please sign in to comment.