Skip to content

Commit

Permalink
feat: backend integration schema
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Aug 15, 2024
1 parent 27cdd66 commit 0f47dfb
Show file tree
Hide file tree
Showing 14 changed files with 1,207 additions and 211 deletions.
2 changes: 1 addition & 1 deletion src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Breadcrumb = ({ isChain }: BreadcrumbProps) => {

const breadcrumbItems = pathNames.map((path, index) => {
const isLast = index === pathNames.length - 1;
const displayName = isChain && isLast ? chainData?.metadata?.chainName || path : path;
const displayName = isChain && isLast ? chainData?.metadata?.name || path : path;
const href = `/${pathNames.slice(0, index + 1).join('/')}`;

return {
Expand Down
12 changes: 6 additions & 6 deletions src/components/ChainInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import ChainTypeDark from '~/assets/icons/chainTypeDark.svg';
import ChainTypeLight from '~/assets/icons/chainTypeLight.svg';
import CheckBlockDark from '~/assets/icons/checkBlockDark.svg';
import CheckBlockLight from '~/assets/icons/checkBlockLight.svg';
import SpeedDark from '~/assets/icons/speedDark.svg';
import SpeedLight from '~/assets/icons/speedLight.svg';
// import SpeedDark from '~/assets/icons/speedDark.svg';
// import SpeedLight from '~/assets/icons/speedLight.svg';

export const ChainInformation = () => {
const { t } = useTranslation();
Expand All @@ -32,7 +32,7 @@ export const ChainInformation = () => {
alt='chain-type-icon'
/>

<InfoBox
{/* <InfoBox
title={t('CHAIN.CHAININFORMATION.lastBlock')}
description={chainData?.l2ChainInfo.lastBlock}
darkIcon={BlockDark}
Expand All @@ -57,7 +57,7 @@ export const ChainInformation = () => {
lightIcon={SpeedLight}
size={22}
alt='speed-icon'
/>
/> */}

<InfoBox
title={t('CHAIN.CHAININFORMATION.totalBatchesCommitted')}
Expand Down Expand Up @@ -86,14 +86,14 @@ export const ChainInformation = () => {
alt='check-block'
/>

<InfoBox
{/* <InfoBox
title={t('CHAIN.CHAININFORMATION.averageBlockTime')}
description={chainData?.l2ChainInfo.avgBlockTime}
darkIcon={SpeedDark}
lightIcon={SpeedLight}
size={22}
alt='speed-icon'
/>
/> */}
</DataContainer>
</article>
);
Expand Down
11 changes: 6 additions & 5 deletions src/components/ChainTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ChainTable = ({ chains }: TableProps) => {
const { t } = useTranslation();
const router = useRouter();

const handleChainNavigation = (id: number) => {
const handleChainNavigation = (id: string) => {
router.push(`/${id}`);
};

Expand All @@ -51,8 +51,9 @@ export const ChainTable = ({ chains }: TableProps) => {
<STableBodyRow key={index} onClick={() => handleChainNavigation(data.chainId)}>
{/* Chain Name with Logo and Tags */}
<FirstCellWithLogo>
<ChainAvatar alt={`${data.chainName} logo`} src={data.iconUrl} />
<ChainName>{data.chainName}</ChainName>
{/* TODO: INSTEAD OF BASE TOKEN IS CHAIN DATA */}
<ChainAvatar alt={`${data.baseToken.name} logo`} src={data.baseToken.imageUrl} />
<ChainName>{data.baseToken.name}</ChainName>
<InfoTagsContainer>
{!data.rpc && <InfoTag information={t('HOME.DASHBOARD.noRPC')} />}
{!data.metadata && <InfoTag information={t('HOME.DASHBOARD.noMetadata')} />}
Expand All @@ -62,8 +63,8 @@ export const ChainTable = ({ chains }: TableProps) => {
<STableCell sx={{ width: '10%' }}>{data.chainId}</STableCell>

<LogoCell sx={{ width: '10%' }}>
<TokenAvatar alt={`${data.nativeToken} logo`} src={data.tokenImgUrl} />
<Typography>{data.nativeToken}</Typography>
<TokenAvatar alt={`${data.baseToken.symbol} logo`} src={data.baseToken.imageUrl} />
<Typography>{data.baseToken.symbol}</Typography>
</LogoCell>

<STableCell sx={{ width: '10%' }}>{formatDataNumber(data.tvl, 0, true)}</STableCell>
Expand Down
42 changes: 31 additions & 11 deletions src/components/RPC.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'next-i18next';
import { Box, Typography, Tooltip, styled } from '@mui/material';
import { CheckCircle as CheckIcon, Cancel as CancelIcon } from '@mui/icons-material';

import { useData, useCustomTheme } from '~/hooks';
import { DataContainer, STitle } from '~/components';
import { checkRpcStatus } from '~/utils';

export const RPC = () => {
const { t } = useTranslation();
const { chainData } = useData();
const [rpcData, setRpcData] = useState<{ url: string; status: boolean }[]>([]);

useEffect(() => {
const updateRpcStatuses = async () => {
if (!chainData?.metadata?.publicRpcs) return;

const updatedRpcData = await Promise.all(
chainData.metadata.publicRpcs.map(async (rpc) => {
const status = await checkRpcStatus(rpc);
return { url: rpc, status };
}),
);

setRpcData(updatedRpcData);
};

updateRpcStatuses();
}, [chainData]);

return (
<article>
<STitle>{t('CHAIN.RPC.title')}</STitle>
<DataContainer>
{chainData?.metadata?.publicRpcs &&
chainData.metadata.publicRpcs.map((rpc, index) => (
<RPCBox key={index}>
<Tooltip title={rpc.status ? t('CHAIN.RPC.statusActive') : t('CHAIN.RPC.statusInactive')}>
{rpc.status ? <CheckIcon color='success' /> : <CancelIcon color='error' />}
</Tooltip>
<RPCUrl>{rpc.url}</RPCUrl>
</RPCBox>
))}
{rpcData.map((rpc, index) => (
<RPCBox key={index}>
<Tooltip title={rpc.status ? t('CHAIN.RPC.statusActive') : t('CHAIN.RPC.statusInactive')}>
{rpc.status ? <CheckIcon color='success' /> : <CancelIcon color='error' />}
</Tooltip>
<RPCUrl>{rpc.url}</RPCUrl>
</RPCBox>
))}
</DataContainer>
</article>
);
};

export const RPCBox = styled(Box)(() => {
const RPCBox = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
return {
display: 'flex',
Expand All @@ -37,7 +57,7 @@ export const RPCBox = styled(Box)(() => {
};
});

export const RPCUrl = styled(Typography)(() => {
const RPCUrl = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();
return {
textDecoration: 'underline',
Expand Down
2 changes: 1 addition & 1 deletion src/components/TvlContentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatDataNumber } from '~/utils';
interface TvlContentBoxProps {
avatar: string;
token: string;
total: number;
total: string;
tokenName: string;
isLast?: boolean;
}
Expand Down
17 changes: 10 additions & 7 deletions src/containers/ChainDetail/ChainMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Avatar, Box, Button, Typography, styled } from '@mui/material';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import Image from 'next/image';

import { useCustomTheme, useData } from '~/hooks';
Expand All @@ -20,6 +21,8 @@ import SettingsLight from '~/assets/icons/settingsLight.svg';

export const ChainMetadata = () => {
const { t } = useTranslation();
const router = useRouter();
const { chain } = router.query;
const { chainData } = useData();
const { theme } = useCustomTheme();
const data = chainData?.metadata;
Expand All @@ -29,17 +32,17 @@ export const ChainMetadata = () => {
<MetadataContainer>
<FirstRow>
<ChainIdentity>
<Avatar src={data?.iconUrl} alt={data?.chainName} sx={{ width: 72, height: 72 }} />
<Avatar src={data?.iconUrl} alt={data?.name} sx={{ width: 72, height: 72 }} />
<Box>
<ChainName>{data?.chainName}</ChainName>
<ChainName>{data?.name}</ChainName>
<ChainId>
{t('CHAIN.chainId')}: <ChainIdValue>{data?.chainId}</ChainIdValue>
{t('CHAIN.chainId')}: <ChainIdValue>{chain}</ChainIdValue>
</ChainId>
</Box>
</ChainIdentity>

<ButtonsContainer>
<MetadataButton variant='contained' href={data?.websiteUrl}>
<MetadataButton variant='contained' href={data?.explorerUrl}>
<WebIcon src={dark ? WebDark : WebLight} alt='web icon' />
{t('CHAIN.website')}
<SIcon src={dark ? LinkDark : LinkLight} alt='link icon' />
Expand Down Expand Up @@ -74,15 +77,15 @@ export const ChainMetadata = () => {
<Label variant='subtitle1' color='textSecondary' gutterBottom>
{t('CHAIN.environment')}
</Label>
<Value>{data?.environment}</Value>
<Value>{data?.chainType}</Value>
</Box>
</MetadataItem>

<MetadataItem>
<NativeTokenAvatar src={data?.nativeTokenIconUrl} alt={data?.nativeToken} />
<NativeTokenAvatar src={data?.baseToken.imageUrl} alt={data?.baseToken.symbol} />
<Box>
<Label>{t('CHAIN.nativeToken')}</Label>
<Value>{data?.nativeToken}</Value>
<Value>{data?.baseToken.symbol}</Value>
</Box>
</MetadataItem>
</SecondRow>
Expand Down
3 changes: 2 additions & 1 deletion src/containers/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const Dashboard = () => {
const chainIdStr = String(chain.chainId);
const formattedSearchTerm = String(searchTerm).toLowerCase();

const matchesName = chain.chainName.toLowerCase().includes(formattedSearchTerm);
// TODO: REPLACE WITH CHAIN NAME
const matchesName = chain.baseToken.name.toLowerCase().includes(formattedSearchTerm);
const matchesId = chainIdStr.includes(formattedSearchTerm);

return matchesName || matchesId;
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Tokens/TokensTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const TokensTable = ({ tvl }: TotalValueLockedProps) => {

<STableCell>${token.price.toLocaleString()}</STableCell>

<STableCell>${((token.amountUsd * token.price) / 1e18).toLocaleString()}</STableCell>
<STableCell>${((Number(token.amountUsd) * Number(token.price)) / 1e18).toLocaleString()}</STableCell>
</STableBodyRow>
))}
</STableBody>
Expand Down
Loading

0 comments on commit 0f47dfb

Please sign in to comment.