Skip to content

Commit

Permalink
feat: copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Sep 10, 2024
1 parent b241385 commit 00af817
Show file tree
Hide file tree
Showing 11 changed files with 1,269 additions and 17 deletions.
2 changes: 2 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"title": "ZKsync",
"subtitle": "Ecosystem",
"home": "Home",
"copy": "Copy",
"copied": "Copied!",
"LOCKEDASSETS": {
"lockedAssets": "Locked assets",
"others": "Others",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"HOME": {
"title": "ZKsync",
"subtitle": "Ecosistema",

"home": "Inicio",
"copy": "Copiar",
"copied": "Copiado!",
"LOCKEDASSETS": {
"lockedAssets": "Activos bloqueados",
"others": "Otros",
Expand Down
5 changes: 3 additions & 2 deletions src/components/ChainTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const STableCellHead = styled(TableCell)(() => {
const { currentTheme } = useCustomTheme();
return {
color: currentTheme.textSecondary,
textAlign: 'left',
textAlign: 'center',
borderBottom: 'none',
};
});
Expand All @@ -204,7 +204,7 @@ export const STableCell = styled(TableCell)(({ theme }) => {
const { currentTheme } = useCustomTheme();
return {
color: currentTheme.textPrimary,
textAlign: 'left',
textAlign: 'center',
border: 'none',
fontSize: '1rem',
[theme.breakpoints.down('md')]: {
Expand Down Expand Up @@ -247,6 +247,7 @@ export const ContractCell = styled(Link)(() => {
return {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: currentTheme.gap,
color: currentTheme.textPrimary,
};
Expand Down
24 changes: 12 additions & 12 deletions src/components/RPC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'next-i18next';
import { Box, Typography, Tooltip, styled, Skeleton, Button } from '@mui/material';

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

export const RPC = () => {
Expand All @@ -12,6 +12,7 @@ export const RPC = () => {
const [rpcData, setRpcData] = useState<{ url: string; status: boolean }[]>([]);
const [rpcIsLoading, setRpcIsLoading] = useState(true);
const [showAll, setShowAll] = useState(false);
const [copiedState, copy] = useCopyToClipboard();

useEffect(() => {
const updateRpcStatuses = async () => {
Expand Down Expand Up @@ -77,8 +78,9 @@ export const RPC = () => {
</RPCIcon>
</Tooltip>
)}

<RPCUrl>{rpc.url}</RPCUrl>
<STooltip title={rpc.url === copiedState[`${rpc.url}`] ? t('HOME.copied') : t('HOME.copy')}>
<RPCUrl onClick={() => copy(rpc.url, rpc.url)}>{rpc.url}</RPCUrl>
</STooltip>
</RPCBox>
))}

Expand Down Expand Up @@ -121,9 +123,9 @@ const RPCBox = styled(Box)(() => {
const { currentTheme } = useCustomTheme();
return {
display: 'flex',
gap: currentTheme.gap,
height: '4.5rem',
alignItems: 'center',
width: '100%',
padding: currentTheme.padding,
};
});
Expand All @@ -132,21 +134,19 @@ const RPCIcon = styled(Box)(() => {
return {
display: 'flex',
alignItems: 'center',
marginRight: '0.5rem',
};
});

const RPCUrl = styled(Typography)(({ theme }) => {
const RPCUrl = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();
return {
textDecoration: 'underline',
textUnderlineOffset: currentTheme.gap,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
maxWidth: '15rem',
[theme.breakpoints.down('md')]: {
maxWidth: '25rem',
},
wordBreak: 'break-all',
whiteSpace: 'normal',
cursor: 'pointer',
};
});

Expand Down
14 changes: 14 additions & 0 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Tooltip, TooltipProps, styled } from '@mui/material';

export const STooltip = styled(({ className, placement = 'top', ...props }: TooltipProps) => (
<Tooltip classes={{ popper: className }} placement={placement} disableInteractive arrow {...props} />
))(() => {
return {
'& .MuiTooltip-tooltip': {
fontSize: '1rem',
borderRadius: '0.5rem',
padding: '0.25rem 0.5rem',
maxWidth: 'max-content',
},
};
});
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './TVLGraph/DesktopTVLGraph';
export * from './TVLGraph/MobileTVLGraph';
export * from './AddNetworkButton';
export * from './TVLGraph';
export * from './Tooltip';
25 changes: 23 additions & 2 deletions src/containers/Tokens/TokensTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'next-i18next';
import { Table, Typography, Box } from '@mui/material';
import { Table, Typography, Box, styled } from '@mui/material';

import { TotalValueLockedProps, TvlData } from '~/types';
import {
Expand All @@ -15,11 +15,14 @@ import {
FirstCellWithLogo,
TableCellHeadFirst,
NotAvailable,
STooltip,
} from '~/components';
import { useCopyToClipboard, useCustomTheme } from '~/hooks';
import { formatDataNumber, truncateAddress } from '~/utils';

export const TokensTable = ({ tvl }: TotalValueLockedProps) => {
const { t } = useTranslation();
const [copiedState, copy] = useCopyToClipboard();

return (
<Box>
Expand Down Expand Up @@ -53,7 +56,17 @@ export const TokensTable = ({ tvl }: TotalValueLockedProps) => {
</FirstCellWithLogo>

<STableCell>
{token.contractAddress && <Typography>{truncateAddress(token.contractAddress || '')}</Typography>}
{token.contractAddress && (
<STooltip
title={
token.contractAddress === copiedState['token contract'] ? t('HOME.copied') : t('HOME.copy')
}
>
<CopyText onClick={() => copy('token contract', token.contractAddress || '')}>
{truncateAddress(token.contractAddress || '')}
</CopyText>
</STooltip>
)}
{!token.contractAddress && <NotAvailable>{t('CHAIN.CHAININFORMATION.notAvailable')}</NotAvailable>}
</STableCell>

Expand All @@ -74,3 +87,11 @@ export const TokensTable = ({ tvl }: TotalValueLockedProps) => {
</Box>
);
};

const CopyText = styled(Typography)(() => {
const { currentTheme } = useCustomTheme();
return {
color: currentTheme.textPrimary,
cursor: 'pointer',
};
});
Loading

0 comments on commit 00af817

Please sign in to comment.