Skip to content

Commit

Permalink
feat: token graph design
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Aug 3, 2024
1 parent 8caa5ff commit f4281ac
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 7 deletions.
146 changes: 143 additions & 3 deletions src/components/TotalValueLocked.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,150 @@
import { Box, Typography, Grid, styled } from '@mui/material';
import { TvlData } from '~/types';
import { Box } from '@mui/material';
import { TvlContentBox } from './TvlContentBox';

interface TotalValueLockedProps {
tvl: TvlData[];
}

export const TotalValueLocked = ({ tvl }: TotalValueLockedProps) => {
console.log(tvl);
return <Box>{/* Token graph tvl */}</Box>;
const firstTvl = tvl[0];
const secondTvl = tvl[1];
const thirdTvl = tvl[2];
const fourthTvl = tvl[3];
const fifthTvl = tvl[4];
const sixthTvl = tvl[5];

return (
<TvlContainer container spacing={0.5}>
{/* First tvl row */}
<Grid item xs={12}>
<GridContainer imageUrl={firstTvl.imageUrl} height={'12rem'}>
<TvlContentBox
avatar={firstTvl.imageUrl}
token={firstTvl.token}
total={firstTvl.total}
tokenName={firstTvl.tokenName}
/>
</GridContainer>
</Grid>

{/* Second tvl row */}
<Grid item container xs={12} spacing={0.5}>
<Grid item xs={6}>
<GridContainer imageUrl={secondTvl.imageUrl} height={'12rem'}>
<TvlContentBox
avatar={secondTvl.imageUrl}
token={secondTvl.token}
total={secondTvl.total}
tokenName={secondTvl.tokenName}
/>
</GridContainer>
</Grid>

<Grid item container xs={6} spacing={0.5}>
<Grid item xs={4}>
<GridContainer imageUrl={thirdTvl.imageUrl} height={'12rem'}>
<TvlContentBox
avatar={thirdTvl.imageUrl}
token={thirdTvl.token}
total={thirdTvl.total}
tokenName={thirdTvl.tokenName}
/>
</GridContainer>
</Grid>

<Grid item xs={4}>
<GridContainer imageUrl={fourthTvl.imageUrl} height={'12rem'}>
<TvlContentBox
avatar={fourthTvl.imageUrl}
token={fourthTvl.token}
total={fourthTvl.total}
tokenName={fourthTvl.tokenName}
/>
</GridContainer>
</Grid>

{/* Last tvl container */}
<Grid item container xs={4} direction='column'>
<Grid item xs={6}>
<GridContainer imageUrl={fifthTvl.imageUrl} height={'5.75rem'}>
<TvlContentBox
avatar={fifthTvl.imageUrl}
token={fifthTvl.token}
total={fifthTvl.total}
tokenName={fifthTvl.tokenName}
isLast={true}
/>
</GridContainer>
</Grid>

<Grid item container xs={6} spacing={0.5}>
<Grid item xs={9}>
<GridContainer imageUrl={sixthTvl.imageUrl} height={'5.75rem'}>
<TvlContentBox
avatar={sixthTvl.imageUrl}
token={sixthTvl.token}
total={sixthTvl.total}
tokenName={sixthTvl.tokenName}
isLast={true}
/>
</GridContainer>
</Grid>

<Grid item xs={3}>
<GridContainer height={'5.75rem'}>
<OthersBox>
<Typography style={{ writingMode: 'vertical-rl', transform: 'rotate(180deg)' }}>Others</Typography>
</OthersBox>
</GridContainer>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</TvlContainer>
);
};

const TvlContainer = styled(Grid)({
display: 'flex',
flexWrap: 'wrap',
width: '75rem',
});

interface GridContainerProps {
imageUrl?: string;
height?: string;
}

const GridContainer = styled(Grid)(({ imageUrl, height }: GridContainerProps) => ({
position: 'relative',
height: height || 'fit-content',
display: 'flex',
color: '#fff',
textShadow: '0 0 5px rgba(0, 0, 0, 0.5)',
overflow: 'hidden',
backgroundColor: 'rgba(250, 250, 250, 0.2)',
borderRadius: '1rem',
padding: '1rem',
'&::before': {
content: '""',
position: 'absolute',
top: -20,
left: -450,
right: 0,
bottom: 0,
backgroundImage: `url(${imageUrl})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
filter: 'blur(130px)',
},
}));

const OthersBox = styled(Box)({
position: 'relative',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
});
62 changes: 62 additions & 0 deletions src/components/TvlContentBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Box, Avatar, Typography, styled } from '@mui/material';
import { useCustomTheme } from '~/hooks';
import { formatDataNumber } from '~/utils';

interface TvlContentBoxProps {
avatar: string;
token: string;
total: number;
tokenName: string;
isLast?: boolean;
}

export const TvlContentBox = ({ avatar, token, total, tokenName, isLast }: TvlContentBoxProps) => {
return (
<ContentBox>
<TopBox>
<TokenLogo src={avatar} alt={token} isLast={isLast || false} />
<TokenName>{tokenName}</TokenName>
<TokenTicker>{token}</TokenTicker>
</TopBox>

<Typography>{formatDataNumber(total, 0, true)}</Typography>
</ContentBox>
);
};

const ContentBox = styled(Box)({
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'center',
zIndex: 1,
});

const TopBox = styled(Box)({
display: 'flex',
alignItems: 'center',
gap: '0.5rem',
});

interface TokenLogoProps {
isLast: boolean;
}

const TokenLogo = styled(Avatar)<TokenLogoProps>(({ isLast }) => ({
width: `${isLast ? '1.25rem' : '2rem'}`,
height: `${isLast ? '1.25rem' : '2rem'}`,
}));

const TokenTicker = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();
return {
fontSize: '0.75rem',
fontWeight: 400,
color: currentTheme.textSecondary,
};
});

const TokenName = styled(Typography)({
fontSize: '0.75rem',
fontWeight: 400,
});
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './ChainInformation';
export * from './BasicSelect';
export * from './NotFound';
export * from './Gas';
export * from './TvlContentBox';
16 changes: 12 additions & 4 deletions src/data/ecosystemMockData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,49 @@
"l1Tvl": [
{
"token": "ETH",
"tokenName": "Ethereum",
"total": 557596566000,
"imageUrl": "https://coin-images.coingecko.com/coins/images/279/large/ethereum.png?1696501628"
},
{
"token": "USDT",
"tokenName": "Tether USD",
"total": 114493849618,
"imageUrl": "https://coin-images.coingecko.com/coins/images/325/large/tether.png"
},
{
"token": "USDC",
"tokenName": "Bridged USD",
"total": 34115209093,
"imageUrl": "https://coin-images.coingecko.com/coins/images/6319/large/usd-coin.png"
"imageUrl": "https://assets.coingecko.com/coins/images/6319/standard/usdc.png?1696506694"
},
{
"token": "KOI",
"tokenName": "Koi Finance",
"total": 24115209093,
"imageUrl": "https://assets.coingecko.com/coins/images/35766/standard/Koi_logo.png?1709782399"
},
{
"token": "WBTC",
"tokenName": "Wrapped BTC",
"total": 12620248,
"imageUrl": "https://coin-images.coingecko.com/coins/images/5757/large/wrapped-bitcoin.png"
"imageUrl": "https://assets.coingecko.com/coins/images/7598/standard/wrapped_bitcoin_wbtc.png?1696507857"
},
{
"token": "wsETH",
"token": "wstETH",
"tokenName": "Lido wstETH",
"total": 3552439,
"imageUrl": "https://coin-images.coingecko.com/coins/images/11320/large/staked-ether.png"
"imageUrl": "https://assets.coingecko.com/coins/images/18834/standard/wstETH.png?1696518295"
},
{
"token": "cbETH",
"tokenName": "Curve cbETH",
"total": 2552439,
"imageUrl": "https://assets.coingecko.com/coins/images/27008/standard/cbeth.png?1709186989"
},
{
"token": "BAL",
"tokenName": "Balancer",
"total": 1552439,
"imageUrl": "https://coin-images.coingecko.com/coins/images/671/large/balancer.png"
}
Expand Down
1 change: 1 addition & 0 deletions src/types/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface EcosystemData {

export interface TvlData {
token: string;
tokenName: string;
total: number;
imageUrl: string;
}

0 comments on commit f4281ac

Please sign in to comment.