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

Add Category Leaders Section #470

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions src/components/DataRoom/AssetsSecured/SlidingContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import css from './styles.module.css'
import type { RefObject } from 'react'
import { motion } from 'framer-motion'
import { Typography } from '@mui/material'
import { Cex, type CEX } from './Cex'
import { useSafeDataRoomStats } from '@/hooks/useSafeDataRoomStats'
import { getNormalizationFactor } from './utils/getNormalizationFactor'
import { formatDate } from '@/lib/formatDate'
import { useIsMediumScreen } from '@/hooks/useMaxWidth'
import { formatValue } from '@/lib/formatValue'
import useContainerSize from '@/hooks/useContainerSize'
import useScrollProgress from '@/hooks/useScrollProgress'
import type { ComparisonProps } from '@/components/common/ExternalComparison'
import { ExternalComparison } from '@/components/common/ExternalComparison'

const LAST_UPDATED_FALLBACK = 1722946836.34
const MOBILE_VIEWPORT_FRACTION = 0.8
Expand All @@ -22,7 +23,7 @@ export default function SlidingContent({
caption,
cexes,
containerRef,
}: Omit<BaseBlock, 'text'> & { cexes: CEX[]; containerRef: RefObject<HTMLDivElement> }) {
}: Omit<BaseBlock, 'text'> & { cexes: ComparisonProps[]; containerRef: RefObject<HTMLDivElement> }) {
const { tvlRobinhoodCEX, tvlOKX, tvlBinance, tvlSafe, lastUpdated } = useSafeDataRoomStats()
const { width: viewportWidth } = useContainerSize(containerRef)

Expand Down Expand Up @@ -55,10 +56,10 @@ export default function SlidingContent({

const squareRatio = formatValue(normalizationFactor)

const transformLTR = useTransform(scrollYProgress, [0.5, 0.75], ['0%', '100%'])
const transformRTL = useTransform(scrollYProgress, [0.5, 0.75], ['0', '-100%'])
const opacityLTR = useTransform(scrollYProgress, [0.25, 0.35, 0.5, 0.75], [0, 1, 1, 0])
const opacityRTL = useTransform(scrollYProgress, [0.1, 0.35, 0.5, 0.75], [0, 1, 1, 0])
const transformLTR = useTransform(scrollYProgress, [0.5, 1.0], ['0%', '100%'])
const transformRTL = useTransform(scrollYProgress, [0.5, 1.0], ['0', '-100%'])
const opacityLTR = useTransform(scrollYProgress, [0.25, 0.35, 0.5, 1.0], [0, 1, 1, 0])
const opacityRTL = useTransform(scrollYProgress, [0.1, 0.35, 0.5, 1.0], [0, 1, 1, 0])

return (
<>
Expand All @@ -79,7 +80,8 @@ export default function SlidingContent({
const tvl = dynamicTvl.find((item) => item.name === cex.name)?.tvl || cex.tvl

return (
<Cex
<ExternalComparison
type="CEX"
key={index}
tvl={tvl}
boxColor={cex.boxColor}
Expand Down
4 changes: 2 additions & 2 deletions src/components/DataRoom/AssetsSecured/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { BaseBlock } from '@/components/Home/types'
import dynamic from 'next/dynamic'
import { useRef } from 'react'
import { type CEX } from './Cex'
import css from './styles.module.css'
import type { ComparisonProps } from '@/components/common/ExternalComparison'

const SlidingContent = dynamic(() => import('./SlidingContent'))

const Cexes = ({ title, caption, cexes }: BaseBlock & { cexes: CEX[] }) => {
const Cexes = ({ title, caption, cexes }: BaseBlock & { cexes: ComparisonProps[] }) => {
const backgroundRef = useRef<HTMLDivElement>(null)

return (
Expand Down
52 changes: 0 additions & 52 deletions src/components/DataRoom/AssetsSecured/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,6 @@
gap: 32px;
}

.cexEntry {
display: flex;
flex-direction: row;
align-items: center;
gap: 22px;
}

.squareGrid {
display: flex;
flex-direction: row;
column-gap: 8px;
align-items: center;
}

.gridItem {
width: 16px;
height: 16px;
border-radius: 3px;
background-color: var(--mui-palette-primary-light);
}

.gridItemMain {
background-color: var(--mui-palette-primary-main);
}

.labelContainer {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 22px;
}

.labelCaption {
white-space: nowrap;
color: var(--mui-palette-primary-light);
}

@media (max-width: 1000px) {
.sectionContainer {
height: 200lvh;
Expand All @@ -98,20 +60,6 @@
padding-bottom: 12px;
}

.labelCaption {
font-size: 18px;
}

.labelContainer {
gap: 12px;
}

.cexEntry {
flex-direction: column;
align-items: start;
gap: 8px;
}

.title {
margin-top: 40px;
text-align: left;
Expand Down
78 changes: 78 additions & 0 deletions src/components/DataRoom/CategoryLeaders/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { BaseBlock } from '@/components/Home/types'
import { useTransform } from 'framer-motion'
import css from './styles.module.css'
import type { RefObject } from 'react'
import { motion } from 'framer-motion'
import { Typography } from '@mui/material'
import { type ComparisonProps } from '@/components/common/ExternalComparison'
import { useSafeDataRoomStats } from '@/hooks/useSafeDataRoomStats'
import { useIsMediumScreen } from '@/hooks/useMaxWidth'
import { formatValue } from '@/lib/formatValue'
import useScrollProgress from '@/hooks/useScrollProgress'
import { ExternalComparison } from '@/components/common/ExternalComparison'

export default function Content({
title,
leaders,
containerRef,
}: Omit<BaseBlock, 'text'> & { leaders: ComparisonProps[]; containerRef: RefObject<HTMLDivElement> }) {
const { tvlLido, tvlEigenLayer, tvlUniswap, tvlAAVE, tvlSafe } = useSafeDataRoomStats()

const isMobile = useIsMediumScreen()
const { scrollYProgress } = useScrollProgress(containerRef)

// Create a mapping object for TVL values
const tvlMapping: Record<string, number | null> = {
tvlLido,
tvlUniswap,
tvlSafe,
tvlEigenLayer,
tvlAAVE,
}

// Get the TVL values for each LEADER
const dynamicTvl = leaders.map(({ name, tvl: tvlFallback }) => {
// get the varibale name of the dynamic TVL
const dynamicTvlString = `tvl${name.split(' ')[0]}`

return { name, tvl: tvlMapping[dynamicTvlString] || tvlFallback }
})

const normalizationFactor = 1000000000

const squareRatio = formatValue(normalizationFactor)

const opacity = useTransform(scrollYProgress, isMobile ? [0, 0.35, 0.5, 1.0] : [0.1, 0.35, 0.5, 0.75], [0, 1, 1, 0])

return (
<motion.div
style={{
opacity,
}}
className={css.leadersContainer}
>
<Typography className={css.title} variant="h1">
{title}
</Typography>
<Typography className={css.label} variant="h5">
1 square - ${squareRatio}
</Typography>
<div className={css.columnsContainer}>
{[[0, 1], [2], [3, 4]].map((column, columnIndex) => (
<div key={columnIndex} className={css.leaderColumn}>
{column.map((index) => (
<ExternalComparison
type="Leader"
key={index}
tvl={dynamicTvl.find((item) => item.name === leaders[index].name)?.tvl || leaders[index].tvl}
boxColor={leaders[index].boxColor}
name={leaders[index].name}
normalizationFactor={normalizationFactor}
/>
))}
</div>
))}
</div>
</motion.div>
)
}
21 changes: 21 additions & 0 deletions src/components/DataRoom/CategoryLeaders/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { BaseBlock } from '@/components/Home/types'
import dynamic from 'next/dynamic'
import { useRef } from 'react'
import css from './styles.module.css'
import type { ComparisonProps } from '@/components/common/ExternalComparison'

const Content = dynamic(() => import('./Content'))

const Leaders = ({ title, leaders }: BaseBlock & { leaders: ComparisonProps[] }) => {
const backgroundRef = useRef<HTMLDivElement>(null)

return (
<div ref={backgroundRef} className={css.sectionContainer}>
<div className={css.stickyContainer}>
<Content title={title} leaders={leaders} containerRef={backgroundRef} />
</div>
</div>
)
}

export default Leaders
92 changes: 92 additions & 0 deletions src/components/DataRoom/CategoryLeaders/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.sectionContainer {
height: 200vh;
display: flex;
}

.stickyContainer {
position: sticky;
top: 0;
width: 100%;
height: 100dvh;
display: flex;
flex-direction: column;
padding: 100px 128px;
overflow: hidden;
}

.columnsContainer {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 100px;
}

.leaderColumn {
display: flex;
flex-direction: column;
width: 30%;
gap: 100px;
justify-items: self-start;
}

.label {
position: absolute;
top: 0;
right: 0;
padding: 100px 128px;
color: var(--mui-palette-primary-light);
font-size: 18px;
padding-bottom: 12px;
}

@media (max-width: 1000px) {
.sectionContainer {
height: 200lvh;
}

.stickyContainer {
padding: 30px;
overflow: hidden;
padding-top: 72px;
height: 100lvh;
justify-content: space-between;
}

.leadersContainer {
display: flex;
flex-direction: column;
height: 100%;
justify-content: space-around;
}

.columnsContainer {
display: flex;
flex-direction: column;
justify-content: space-between;
margin-top: 12px;
gap: 18px;
}

.leaderColumn {
display: flex;
flex-direction: column;
width: 100%;
gap: 18px;
justify-items: flex-start;
}

.label {
position: absolute;
top: 0;
right: 0;
padding: 80px 30px;
color: var(--mui-palette-primary-light);
}

.title {
margin-top: 0px;
text-align: left;
font-size: 40px;
line-height: 48px;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file moved to the /common folder? It's a Dataroom component

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { motion, type MotionProps } from 'framer-motion'
import { Typography } from '@mui/material'
import { formatValue } from '@/lib/formatValue'

export type CEX = {
export type ComparisonProps = {
name: string
boxColor: string
tvl: number
normalizationFactor: number
date: string
date?: string
type: 'CEX' | 'Leader'
}

const textMotionProps: MotionProps = {
Expand All @@ -22,23 +23,23 @@ const textMotionProps: MotionProps = {
},
}

const gridMotionProps: MotionProps = {
const getGridMotionProps = (type: 'CEX' | 'Leader'): MotionProps => ({
initial: { scale: 0, x: -10 },
whileInView: { scale: 1, x: 0 },
viewport: { once: true },
transition: {
type: 'spring',
stiffness: 260,
damping: 20,
...(type === 'CEX' ? { stiffness: 260, damping: 20 } : { stiffness: 400, damping: 30, mass: 0.8 }),
},
}
})

export const Cex = ({ boxColor, name, normalizationFactor, tvl, date }: CEX) => {
const boxes = Math.round(tvl / normalizationFactor)
export const ExternalComparison = ({ boxColor, name, normalizationFactor, tvl, date, type }: ComparisonProps) => {
const boxes = type === 'CEX' ? Math.round(tvl / normalizationFactor) : Math.floor(tvl / normalizationFactor)
const gridMotionProps = getGridMotionProps(type)

return (
<div className={css.cexEntry}>
<div className={css.squareGrid}>
<div className={type === 'CEX' ? css.cex : css.leader}>
<div className={type === 'CEX' ? css.cexGrid : css.leaderGrid}>
{Array.from({ length: boxes }).map((_, index) => (
<motion.div
key={index}
Expand All @@ -49,16 +50,17 @@ export const Cex = ({ boxColor, name, normalizationFactor, tvl, date }: CEX) =>
))}
</div>

<div className={css.labelContainer}>
<div className={type === 'CEX' ? css.cexLabelContainer : css.leaderLabelContainer}>
<motion.div {...textMotionProps} transition={{ ...textMotionProps.transition, delay: 0.2 }}>
<Typography className={css.cexTitle} variant="h4">
<Typography className={type === 'CEX' ? css.cexTitle : css.labelCaption} variant="h4">
{name}
{type === 'Leader' && '\u00A0'}
</Typography>
</motion.div>

<motion.div {...textMotionProps} transition={{ ...textMotionProps.transition, delay: 0.4 }}>
<Typography className={css.labelCaption} variant="h5">
{'$' + formatValue(tvl) + ' as of ' + date}
<Typography className={css.labelCaption} variant="h4">
{type === 'CEX' ? '$' + formatValue(tvl) + ' as of ' + date : ' - $' + formatValue(tvl)}
</Typography>
</motion.div>
</div>
Expand Down
Loading
Loading