Commit 7cebfd81 authored by tom's avatar tom

review fixes

parent be2ce560
...@@ -5,7 +5,6 @@ import Address from 'ui/shared/address/Address'; ...@@ -5,7 +5,6 @@ import Address from 'ui/shared/address/Address';
import AddressIcon from 'ui/shared/address/AddressIcon'; import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
interface Props { interface Props {
address: string; address: string;
...@@ -15,12 +14,10 @@ interface Props { ...@@ -15,12 +14,10 @@ interface Props {
const AddressSnippet = ({ address, subtitle }: Props) => { const AddressSnippet = ({ address, subtitle }: Props) => {
return ( return (
<Box maxW="100%"> <Box maxW="100%">
<Address hash={ address }> <Address>
<AddressIcon hash={ address }/> <AddressIcon hash={ address }/>
<AddressLink fontWeight="600" ml={ 2 }> <AddressLink hash={ address } fontWeight="600" ml={ 2 }/>
<HashStringShortenDynamic fontWeight="600"/> <CopyToClipboard text={ address } ml={ 1 }/>
</AddressLink>
<CopyToClipboard ml={ 1 }/>
</Address> </Address>
{ subtitle && <Text fontSize="sm" variant="secondary" mt={ 0.5 } ml={{ base: 0, lg: 8 }}>{ subtitle }</Text> } { subtitle && <Text fontSize="sm" variant="secondary" mt={ 0.5 } ml={{ base: 0, lg: 8 }}>{ subtitle }</Text> }
</Box> </Box>
......
...@@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'; ...@@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import CopyIcon from 'icons/copy.svg'; import CopyIcon from 'icons/copy.svg';
const CopyToClipboard = ({ text = '', className }: {text?: string; className?: string}) => { const CopyToClipboard = ({ text, className }: {text: string; className?: string}) => {
const { hasCopied, onCopy } = useClipboard(text, 3000); const { hasCopied, onCopy } = useClipboard(text, 3000);
const [ copied, setCopied ] = useState(false); const [ copied, setCopied ] = useState(false);
......
...@@ -2,10 +2,10 @@ import { Tooltip } from '@chakra-ui/react'; ...@@ -2,10 +2,10 @@ import { Tooltip } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
interface Props { interface Props {
hash?: string; hash: string;
} }
const HashStringShorten = ({ hash = '' }: Props) => { const HashStringShorten = ({ hash }: Props) => {
return ( return (
<Tooltip label={ hash }> <Tooltip label={ hash }>
{ hash.slice(0, 4) + '...' + hash.slice(-4) } { hash.slice(0, 4) + '...' + hash.slice(-4) }
......
...@@ -20,11 +20,11 @@ const TAIL_LENGTH = 4; ...@@ -20,11 +20,11 @@ const TAIL_LENGTH = 4;
const HEAD_MIN_LENGTH = 4; const HEAD_MIN_LENGTH = 4;
interface Props { interface Props {
hash?: string; hash: string;
fontWeight?: string | number; fontWeight?: string | number;
} }
const HashStringShortenDynamic = ({ hash = '', fontWeight = '400' }: Props) => { const HashStringShortenDynamic = ({ hash, fontWeight = '400' }: Props) => {
const elementRef = useRef<HTMLSpanElement>(null); const elementRef = useRef<HTMLSpanElement>(null);
const [ displayedString, setDisplayedString ] = React.useState(hash); const [ displayedString, setDisplayedString ] = React.useState(hash);
......
...@@ -5,7 +5,6 @@ import transactionIcon from 'icons/transactions.svg'; ...@@ -5,7 +5,6 @@ import transactionIcon from 'icons/transactions.svg';
import Address from 'ui/shared/address/Address'; import Address from 'ui/shared/address/Address';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
interface Props { interface Props {
hash: string; hash: string;
...@@ -13,12 +12,10 @@ interface Props { ...@@ -13,12 +12,10 @@ interface Props {
const TransactionSnippet = ({ hash }: Props) => { const TransactionSnippet = ({ hash }: Props) => {
return ( return (
<Address hash={ hash } maxW="100%"> <Address maxW="100%">
<Icon as={ transactionIcon } boxSize={ 6 } color={ useColorModeValue('gray.500', 'gray.400') }/> <Icon as={ transactionIcon } boxSize={ 6 } color={ useColorModeValue('gray.500', 'gray.400') }/>
<AddressLink fontWeight="600" type="transaction" ml={ 2 }> <AddressLink hash={ hash } fontWeight="600" type="transaction" ml={ 2 }/>
<HashStringShortenDynamic fontWeight="600"/> <CopyToClipboard text={ hash } ml={ 1 }/>
</AddressLink>
<CopyToClipboard ml={ 1 }/>
</Address> </Address>
); );
}; };
......
...@@ -2,21 +2,12 @@ import { Flex, chakra } from '@chakra-ui/react'; ...@@ -2,21 +2,12 @@ import { Flex, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
interface Props { interface Props {
hash: string;
className?: string; className?: string;
children: React.ReactNode; children: React.ReactNode;
} }
const Address = ({ children, className, ...props }: Props) => { const Address = ({ children, className }: Props) => {
const childrenWithProps = React.Children.map(children, (child) => { return <Flex alignItems="center" overflow="hidden" className={ className }>{ children }</Flex>;
if (React.isValidElement(child)) {
return React.cloneElement(child, { ...props, text: props.hash } as Partial<unknown>);
}
return child;
});
return <Flex alignItems="center" overflow="hidden" className={ className }>{ childrenWithProps }</Flex>;
}; };
const AddressChakra = chakra(Address); const AddressChakra = chakra(Address);
......
...@@ -2,10 +2,10 @@ import { Box, chakra } from '@chakra-ui/react'; ...@@ -2,10 +2,10 @@ import { Box, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon'; import Jazzicon, { jsNumberForAddress } from 'react-jazzicon';
const AddressIcon = ({ hash, className }: {hash?: string; className?: string}) => { const AddressIcon = ({ hash, className }: {hash: string; className?: string}) => {
return ( return (
<Box className={ className } width="24px" display="inline-flex"> <Box className={ className } width="24px" display="inline-flex">
<Jazzicon diameter={ 24 } seed={ jsNumberForAddress(hash || 'random') }/> <Jazzicon diameter={ 24 } seed={ jsNumberForAddress(hash) }/>
</Box> </Box>
); );
}; };
......
import { Link, chakra } from '@chakra-ui/react'; import { Link, chakra, shouldForwardProp } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useLink from 'lib/link/useLink'; import useLink from 'lib/link/useLink';
import HashStringShorten from 'ui/shared/HashStringShorten';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
interface Props { interface Props {
children: React.ReactNode;
type?: 'address' | 'transaction' | 'token'; type?: 'address' | 'transaction' | 'token';
hash?: string;
className?: string; className?: string;
hash: string;
truncation?: 'constant' | 'dynamic'| 'none';
fontWeight?: string;
} }
const AddressLink = ({ children, type, className, ...props }: Props) => { const AddressLink = ({ type, className, truncation = 'dynamic', hash, fontWeight }: Props) => {
const link = useLink(); const link = useLink();
let url; let url;
if (type === 'transaction') { if (type === 'transaction') {
url = link('tx_index', { id: props.hash }); url = link('tx_index', { id: hash });
} else if (type === 'token') { } else if (type === 'token') {
url = link('token_index', { id: props.hash }); url = link('token_index', { id: hash });
} else { } else {
url = link('address_index', { id: props.hash }); url = link('address_index', { id: hash });
} }
const childrenWithProps = React.Children.map(children, child => { const content = (() => {
if (React.isValidElement(child)) { switch (truncation) {
return React.cloneElement(child, { ...props }); case 'constant':
return <HashStringShorten hash={ hash }/>;
case 'dynamic':
return <HashStringShortenDynamic hash={ hash } fontWeight={ fontWeight }/>;
case 'none':
return <span>{ hash }</span>;
} }
})();
return child;
});
return ( return (
<Link <Link
...@@ -37,11 +43,22 @@ const AddressLink = ({ children, type, className, ...props }: Props) => { ...@@ -37,11 +43,22 @@ const AddressLink = ({ children, type, className, ...props }: Props) => {
overflow="hidden" overflow="hidden"
whiteSpace="nowrap" whiteSpace="nowrap"
> >
{ childrenWithProps } { content }
</Link> </Link>
); );
}; };
const AddressLinkChakra = chakra(AddressLink); const AddressLinkChakra = chakra(AddressLink, {
shouldForwardProp: (prop) => {
const isChakraProp = !shouldForwardProp(prop);
// forward fontWeight to the AddressLink since it's needed for underlying HashStringShortenDynamic component
if (isChakraProp && prop !== 'fontWeight') {
return false;
}
return true;
},
});
export default React.memo(AddressLinkChakra); export default React.memo(AddressLinkChakra);
...@@ -4,7 +4,6 @@ import React from 'react'; ...@@ -4,7 +4,6 @@ import React from 'react';
import rightArrowIcon from 'icons/arrows/right.svg'; import rightArrowIcon from 'icons/arrows/right.svg';
import { space } from 'lib/html-entities'; import { space } from 'lib/html-entities';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import HashStringShorten from 'ui/shared/HashStringShorten';
import Token from 'ui/shared/Token'; import Token from 'ui/shared/Token';
interface Props { interface Props {
...@@ -18,13 +17,9 @@ interface Props { ...@@ -18,13 +17,9 @@ interface Props {
const TokenTransfer = ({ from, to, amount, usd, token }: Props) => { const TokenTransfer = ({ from, to, amount, usd, token }: Props) => {
return ( return (
<Center> <Center>
<AddressLink fontWeight="500" hash={ from }> <AddressLink fontWeight="500" hash={ from } truncation="constant"/>
<HashStringShorten/>
</AddressLink>
<Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } color="gray.500"/> <Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } color="gray.500"/>
<AddressLink fontWeight="500" hash={ to }> <AddressLink fontWeight="500" hash={ to } truncation="constant"/>
<HashStringShorten/>
</AddressLink>
<Text fontWeight={ 500 } as="span" ml={ 4 }>For:{ space } <Text fontWeight={ 500 } as="span" ml={ 4 }>For:{ space }
<Text fontWeight={ 600 } as="span">{ amount }</Text>{ space } <Text fontWeight={ 600 } as="span">{ amount }</Text>{ space }
<Text fontWeight={ 400 } variant="secondary" as="span">(${ usd.toFixed(2) })</Text> <Text fontWeight={ 400 } variant="secondary" as="span">(${ usd.toFixed(2) })</Text>
......
...@@ -4,7 +4,6 @@ import React from 'react'; ...@@ -4,7 +4,6 @@ import React from 'react';
import Address from 'ui/shared/address/Address'; import Address from 'ui/shared/address/Address';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
interface RowProps { interface RowProps {
children: React.ReactNode; children: React.ReactNode;
...@@ -111,19 +110,15 @@ const TxDecodedInputData = () => { ...@@ -111,19 +110,15 @@ const TxDecodedInputData = () => {
Data Data
</GridItem> </GridItem>
<TableRow name="from" type="address"> <TableRow name="from" type="address">
<Address hash="0x0000000000000000000000000000000000000000" justifyContent="space-between"> <Address justifyContent="space-between">
<AddressLink> <AddressLink hash="0x0000000000000000000000000000000000000000"/>
<HashStringShortenDynamic/> <CopyToClipboard text="0x0000000000000000000000000000000000000000"/>
</AddressLink>
<CopyToClipboard/>
</Address> </Address>
</TableRow> </TableRow>
<TableRow name="from" type="address"> <TableRow name="from" type="address">
<Address hash="0xcf0c50b7ea8af37d57380a0ac199d55b0782c718" justifyContent="space-between"> <Address justifyContent="space-between">
<AddressLink> <AddressLink hash="0xcf0c50b7ea8af37d57380a0ac199d55b0782c718"/>
<HashStringShortenDynamic/> <CopyToClipboard text="0xcf0c50b7ea8af37d57380a0ac199d55b0782c718"/>
</AddressLink>
<CopyToClipboard/>
</Address> </Address>
</TableRow> </TableRow>
<TableRow name="tokenId" type="uint256" isLast> <TableRow name="tokenId" type="uint256" isLast>
......
...@@ -12,7 +12,6 @@ import AddressIcon from 'ui/shared/address/AddressIcon'; ...@@ -12,7 +12,6 @@ import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import CopyToClipboard from 'ui/shared/CopyToClipboard'; import CopyToClipboard from 'ui/shared/CopyToClipboard';
import DetailsInfoItem from 'ui/shared/DetailsInfoItem'; import DetailsInfoItem from 'ui/shared/DetailsInfoItem';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
import RawInputData from 'ui/shared/RawInputData'; import RawInputData from 'ui/shared/RawInputData';
import Token from 'ui/shared/Token'; import Token from 'ui/shared/Token';
import Utilization from 'ui/shared/Utilization'; import Utilization from 'ui/shared/Utilization';
...@@ -79,24 +78,20 @@ const TxDetails = () => { ...@@ -79,24 +78,20 @@ const TxDetails = () => {
hint="Address (external or contract) sending the transaction." hint="Address (external or contract) sending the transaction."
mt={ 8 } mt={ 8 }
> >
<Address hash={ tx.address_from }> <Address>
<AddressIcon/> <AddressIcon hash={ tx.address_from }/>
<AddressLink ml={ 2 }> <AddressLink ml={ 2 } hash={ tx.address_from }/>
<HashStringShortenDynamic/> <CopyToClipboard text={ tx.address_from }/>
</AddressLink>
<CopyToClipboard/>
</Address> </Address>
</DetailsInfoItem> </DetailsInfoItem>
<DetailsInfoItem <DetailsInfoItem
title="Interacted with contract" title="Interacted with contract"
hint="Address (external or contract) receiving the transaction." hint="Address (external or contract) receiving the transaction."
> >
<Address hash={ tx.address_to }> <Address>
<AddressIcon/> <AddressIcon hash={ tx.address_to }/>
<AddressLink ml={ 2 }> <AddressLink ml={ 2 } hash={ tx.address_to }/>
<HashStringShortenDynamic/> <CopyToClipboard text={ tx.address_to }/>
</AddressLink>
<CopyToClipboard/>
</Address> </Address>
<Tag colorScheme="orange" variant="solid" ml={ 3 }>SANA</Tag> <Tag colorScheme="orange" variant="solid" ml={ 3 }>SANA</Tag>
<Icon as={ successIcon } boxSize={ 4 } ml={ 2 } color="green.500"/> <Icon as={ successIcon } boxSize={ 4 } ml={ 2 } color="green.500"/>
......
import { Tr, Td, Tag, Flex, Icon } from '@chakra-ui/react'; import { Tr, Td, Tag, Icon } from '@chakra-ui/react';
import capitalize from 'lodash/capitalize'; import capitalize from 'lodash/capitalize';
import React from 'react'; import React from 'react';
...@@ -6,7 +6,6 @@ import rightArrowIcon from 'icons/arrows/right.svg'; ...@@ -6,7 +6,6 @@ import rightArrowIcon from 'icons/arrows/right.svg';
import Address from 'ui/shared/address/Address'; import Address from 'ui/shared/address/Address';
import AddressIcon from 'ui/shared/address/AddressIcon'; import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
import TxStatus from 'ui/tx/TxStatus'; import TxStatus from 'ui/tx/TxStatus';
interface Props { interface Props {
...@@ -26,25 +25,17 @@ const TxInternalTableItem = ({ type, status, from, to, value, gasLimit }: Props) ...@@ -26,25 +25,17 @@ const TxInternalTableItem = ({ type, status, from, to, value, gasLimit }: Props)
<TxStatus status={ status }/> <TxStatus status={ status }/>
</Td> </Td>
<Td pr="0"> <Td pr="0">
<Flex alignItems="center"> <Address>
<Address hash={ from }> <AddressIcon hash={ from }/>
<AddressIcon/> <AddressLink ml={ 2 } fontWeight="500" hash={ from }/>
<AddressLink ml={ 2 } fontWeight="500"> <Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } flexShrink={ 0 } color="gray.500"/>
<HashStringShortenDynamic/> </Address>
</AddressLink>
</Address>
<Icon as={ rightArrowIcon } boxSize={ 6 } mx={ 2 } color="gray.500"/>
</Flex>
</Td> </Td>
<Td pl="0"> <Td pl="0">
<Flex alignItems="center"> <Address>
<Address hash={ to }> <AddressIcon hash={ to }/>
<AddressIcon/> <AddressLink ml={ 2 } fontWeight="500" hash={ to }/>
<AddressLink ml={ 2 } fontWeight="500"> </Address>
<HashStringShortenDynamic/>
</AddressLink>
</Address>
</Flex>
</Td> </Td>
<Td isNumeric> <Td isNumeric>
{ value } { value }
......
...@@ -5,7 +5,6 @@ import React from 'react'; ...@@ -5,7 +5,6 @@ import React from 'react';
import Address from 'ui/shared/address/Address'; import Address from 'ui/shared/address/Address';
import AddressIcon from 'ui/shared/address/AddressIcon'; import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink'; import AddressLink from 'ui/shared/address/AddressLink';
import HashStringShortenDynamic from 'ui/shared/HashStringShortenDynamic';
import TxLogTopic from 'ui/tx/logs/TxLogTopic'; import TxLogTopic from 'ui/tx/logs/TxLogTopic';
import DecodedInputData from 'ui/tx/TxDecodedInputData'; import DecodedInputData from 'ui/tx/TxDecodedInputData';
...@@ -26,11 +25,9 @@ const TxLogItem = ({ address, index, topics, data }: Props) => { ...@@ -26,11 +25,9 @@ const TxLogItem = ({ address, index, topics, data }: Props) => {
<Grid gridTemplateColumns="200px 1fr" gap={ 8 } py={ 8 } _notFirst={{ borderTopWidth: '1px', borderTopColor: borderColor }}> <Grid gridTemplateColumns="200px 1fr" gap={ 8 } py={ 8 } _notFirst={{ borderTopWidth: '1px', borderTopColor: borderColor }}>
<RowHeader>Address</RowHeader> <RowHeader>Address</RowHeader>
<GridItem display="flex" alignItems="center"> <GridItem display="flex" alignItems="center">
<Address hash={ address }> <Address>
<AddressIcon/> <AddressIcon hash={ address }/>
<AddressLink ml={ 2 }> <AddressLink hash={ address } ml={ 2 }/>
<HashStringShortenDynamic/>
</AddressLink>
</Address> </Address>
<Tooltip label="Find matches topic"> <Tooltip label="Find matches topic">
<Link ml={ 2 }> <Link ml={ 2 }>
......
...@@ -7,7 +7,6 @@ import { ...@@ -7,7 +7,6 @@ import {
Box, Box,
Tr, Tr,
Td, Td,
Flex,
Stat, Stat,
StatArrow, StatArrow,
Portal, Portal,
...@@ -18,8 +17,9 @@ import React, { useRef } from 'react'; ...@@ -18,8 +17,9 @@ import React, { useRef } from 'react';
import type { TTxStateItem } from 'data/txState'; import type { TTxStateItem } from 'data/txState';
import { nbsp } from 'lib/html-entities'; import { nbsp } from 'lib/html-entities';
import AddressIcon from 'ui/shared/AddressIcon'; import Address from 'ui/shared/address/Address';
import AddressLinkWithTooltip from 'ui/shared/AddressLinkWithTooltip'; import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink';
import TxStateStorageItem from './TxStateStorageItem'; import TxStateStorageItem from './TxStateStorageItem';
...@@ -57,10 +57,10 @@ const TxStateTableItem = ({ txStateItem }: { txStateItem: TTxStateItem }) => { ...@@ -57,10 +57,10 @@ const TxStateTableItem = ({ txStateItem }: { txStateItem: TTxStateItem }) => {
</AccordionButton> </AccordionButton>
</Td> </Td>
<Td border={ 0 }> <Td border={ 0 }>
<Flex height="30px" alignItems="center"> <Address height="30px">
<AddressIcon address={ txStateItem.address }/> <AddressIcon hash={ txStateItem.address }/>
<AddressLinkWithTooltip address={ txStateItem.address } fontWeight="500" truncated withCopy={ false } ml={ 2 }/> <AddressLink hash={ txStateItem.address } fontWeight="500" truncation="constant" ml={ 2 }/>
</Flex> </Address>
</Td> </Td>
<Td border={ 0 } lineHeight="30px"><Link>{ txStateItem.miner }</Link></Td> <Td border={ 0 } lineHeight="30px"><Link>{ txStateItem.miner }</Link></Td>
<Td border={ 0 } isNumeric lineHeight="30px"> <Td border={ 0 } isNumeric lineHeight="30px">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment