Commit c2183e47 authored by isstuev's avatar isstuev

fixes 4

parent 9892f404
...@@ -22,7 +22,7 @@ const BLOCK_MARGIN = 24; ...@@ -22,7 +22,7 @@ const BLOCK_MARGIN = 24;
const LatestBlocks = () => { const LatestBlocks = () => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const blocksCount = isMobile ? 2 : 4; const blocksMaxCount = isMobile ? 2 : 4;
const fetch = useFetch(); const fetch = useFetch();
const { data, isLoading, isError } = useQuery<unknown, unknown, Array<Block>>( const { data, isLoading, isError } = useQuery<unknown, unknown, Array<Block>>(
[ QueryKeys.indexBlocks ], [ QueryKeys.indexBlocks ],
...@@ -36,9 +36,9 @@ const LatestBlocks = () => { ...@@ -36,9 +36,9 @@ const LatestBlocks = () => {
const newData = prevData ? [ ...prevData ] : []; const newData = prevData ? [ ...prevData ] : [];
return [ payload.block, ...newData ].slice(0, blocksCount); return [ payload.block, ...newData ].slice(0, blocksMaxCount);
}); });
}, [ queryClient, blocksCount ]); }, [ queryClient, blocksMaxCount ]);
const channel = useSocketChannel({ const channel = useSocketChannel({
topic: 'blocks:new_block', topic: 'blocks:new_block',
...@@ -56,8 +56,13 @@ const LatestBlocks = () => { ...@@ -56,8 +56,13 @@ const LatestBlocks = () => {
content = ( content = (
<> <>
<Skeleton w="100%" h={ 6 } mb={ 9 }/> <Skeleton w="100%" h={ 6 } mb={ 9 }/>
<VStack spacing={ `${ BLOCK_MARGIN }px` } mb={ 6 } height={ `${ BLOCK_HEIGHT * blocksCount + BLOCK_MARGIN * (blocksCount - 1) }px` } overflow="hidden"> <VStack
{ Array.from(Array(blocksCount)).map((item, index) => <LatestBlocksItemSkeleton key={ index }/>) } spacing={ `${ BLOCK_MARGIN }px` }
mb={ 6 }
height={ `${ BLOCK_HEIGHT * blocksMaxCount + BLOCK_MARGIN * (blocksMaxCount - 1) }px` }
overflow="hidden"
>
{ Array.from(Array(blocksMaxCount)).map((item, index) => <LatestBlocksItemSkeleton key={ index }/>) }
</VStack> </VStack>
</> </>
); );
...@@ -68,6 +73,9 @@ const LatestBlocks = () => { ...@@ -68,6 +73,9 @@ const LatestBlocks = () => {
} }
if (data) { if (data) {
const dataToShow = data.slice(0, blocksMaxCount);
const blocksCount = dataToShow.length;
content = ( content = (
<> <>
<Box mb={{ base: 6, lg: 9 }}> <Box mb={{ base: 6, lg: 9 }}>
...@@ -81,7 +89,7 @@ const LatestBlocks = () => { ...@@ -81,7 +89,7 @@ const LatestBlocks = () => {
</Box> </Box>
<VStack spacing={ `${ BLOCK_MARGIN }px` } mb={ 6 } height={ `${ BLOCK_HEIGHT * blocksCount + BLOCK_MARGIN * (blocksCount - 1) }px` } overflow="hidden"> <VStack spacing={ `${ BLOCK_MARGIN }px` } mb={ 6 } height={ `${ BLOCK_HEIGHT * blocksCount + BLOCK_MARGIN * (blocksCount - 1) }px` } overflow="hidden">
<AnimatePresence initial={ false } > <AnimatePresence initial={ false } >
{ data.slice(0, blocksCount).map((block => <LatestBlocksItem key={ block.height } block={ block } h={ BLOCK_HEIGHT }/>)) } { dataToShow.map((block => <LatestBlocksItem key={ block.height } block={ block } h={ BLOCK_HEIGHT }/>)) }
</AnimatePresence> </AnimatePresence>
</VStack> </VStack>
<Flex justifyContent="center"> <Flex justifyContent="center">
......
...@@ -3,8 +3,16 @@ import { ...@@ -3,8 +3,16 @@ import {
Flex, Flex,
HStack, HStack,
Icon, Icon,
Modal,
ModalContent,
ModalCloseButton,
Text, Text,
Popover,
PopoverTrigger,
PopoverContent,
PopoverBody,
useColorModeValue, useColorModeValue,
useDisclosure,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
...@@ -14,11 +22,14 @@ import appConfig from 'configs/app/config'; ...@@ -14,11 +22,14 @@ import appConfig from 'configs/app/config';
import rightArrowIcon from 'icons/arrows/east.svg'; import rightArrowIcon from 'icons/arrows/east.svg';
import transactionIcon from 'icons/transactions.svg'; import transactionIcon from 'icons/transactions.svg';
import getValueWithUnit from 'lib/getValueWithUnit'; import getValueWithUnit from 'lib/getValueWithUnit';
import useIsMobile from 'lib/hooks/useIsMobile';
import useTimeAgoIncrement from 'lib/hooks/useTimeAgoIncrement'; import useTimeAgoIncrement from 'lib/hooks/useTimeAgoIncrement';
import AdditionalInfoButton from 'ui/shared/AdditionalInfoButton';
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 TxStatus from 'ui/shared/TxStatus'; import TxStatus from 'ui/shared/TxStatus';
import TxAdditionalInfo from 'ui/txs/TxAdditionalInfo';
import TxType from 'ui/txs/TxType'; import TxType from 'ui/txs/TxType';
type Props = { type Props = {
...@@ -32,6 +43,9 @@ const LatestBlocksItem = ({ tx }: Props) => { ...@@ -32,6 +43,9 @@ const LatestBlocksItem = ({ tx }: Props) => {
const dataTo = tx.to && tx.to.hash ? tx.to : tx.created_contract; const dataTo = tx.to && tx.to.hash ? tx.to : tx.created_contract;
const timeAgo = useTimeAgoIncrement(tx.timestamp || '0', true); const timeAgo = useTimeAgoIncrement(tx.timestamp || '0', true);
const isMobile = useIsMobile();
const { isOpen, onOpen, onClose } = useDisclosure();
return ( return (
<Box <Box
width="100%" width="100%"
...@@ -42,13 +56,30 @@ const LatestBlocksItem = ({ tx }: Props) => { ...@@ -42,13 +56,30 @@ const LatestBlocksItem = ({ tx }: Props) => {
_last={{ borderBottom: '1px solid', borderColor }} _last={{ borderBottom: '1px solid', borderColor }}
> >
<Flex justifyContent="space-between" width="100%" alignItems="start" flexDirection={{ base: 'column', lg: 'row' }}> <Flex justifyContent="space-between" width="100%" alignItems="start" flexDirection={{ base: 'column', lg: 'row' }}>
<Box width="100%"> { !isMobile && (
<HStack> <Popover placement="right-start" openDelay={ 300 } isLazy>
{ /* FIXME: mb only one type must be here */ } { ({ isOpen }) => (
<TxType type={ tx.tx_types[0] }/> <>
{ /* { tx.tx_types.map(item => <TxType key={ item } type={ item }/>) } */ } <PopoverTrigger>
<TxStatus status={ tx.status } errorText={ tx.status === 'error' ? tx.result : undefined }/> <AdditionalInfoButton isOpen={ isOpen } mr={ 3 }/>
</HStack> </PopoverTrigger>
<PopoverContent border="1px solid" borderColor={ borderColor }>
<PopoverBody>
<TxAdditionalInfo tx={ tx }/>
</PopoverBody>
</PopoverContent>
</>
) }
</Popover>
) }
<Box width={{ base: '100%', lg: 'calc(50% - 32px)' }}>
<Flex justifyContent="space-between">
<HStack>
<TxType types={ tx.tx_types }/>
<TxStatus status={ tx.status } errorText={ tx.status === 'error' ? tx.result : undefined }/>
</HStack>
{ isMobile && <AdditionalInfoButton onClick={ onOpen }/> }
</Flex>
<Flex <Flex
mt={ 2 } mt={ 2 }
alignItems="center" alignItems="center"
...@@ -76,8 +107,8 @@ const LatestBlocksItem = ({ tx }: Props) => { ...@@ -76,8 +107,8 @@ const LatestBlocksItem = ({ tx }: Props) => {
{ tx.timestamp && <Text variant="secondary" fontWeight="400" fontSize="sm">{ timeAgo }</Text> } { tx.timestamp && <Text variant="secondary" fontWeight="400" fontSize="sm">{ timeAgo }</Text> }
</Flex> </Flex>
</Box> </Box>
<Box> <Box width={{ base: '100%', lg: '50%' }}>
<Flex alignItems="center" mb={ 3 }> <Flex alignItems="center" mb={ 3 } justifyContent={{ base: 'start', lg: 'end' }}>
<Address> <Address>
<AddressIcon hash={ tx.from.hash }/> <AddressIcon hash={ tx.from.hash }/>
<AddressLink <AddressLink
...@@ -107,7 +138,7 @@ const LatestBlocksItem = ({ tx }: Props) => { ...@@ -107,7 +138,7 @@ const LatestBlocksItem = ({ tx }: Props) => {
/> />
</Address> </Address>
</Flex> </Flex>
<Flex fontSize="sm" mt={ 3 } justifyContent="end" flexDirection={{ base: 'column', lg: 'row' }}> <Flex fontSize="sm" justifyContent="end" flexDirection={{ base: 'column', lg: 'row' }}>
<Box mr={{ base: 0, lg: 2 }} mb={{ base: 2, lg: 0 }}> <Box mr={{ base: 0, lg: 2 }} mb={{ base: 2, lg: 0 }}>
<Text as="span">Value { appConfig.network.currency.symbol } </Text> <Text as="span">Value { appConfig.network.currency.symbol } </Text>
<Text as="span" variant="secondary">{ getValueWithUnit(tx.value).toFormat() }</Text> <Text as="span" variant="secondary">{ getValueWithUnit(tx.value).toFormat() }</Text>
...@@ -119,6 +150,12 @@ const LatestBlocksItem = ({ tx }: Props) => { ...@@ -119,6 +150,12 @@ const LatestBlocksItem = ({ tx }: Props) => {
</Flex> </Flex>
</Box> </Box>
</Flex> </Flex>
<Modal isOpen={ isOpen } onClose={ onClose } size="full">
<ModalContent paddingTop={ 4 }>
<ModalCloseButton/>
<TxAdditionalInfo tx={ tx }/>
</ModalContent>
</Modal>
</Box> </Box>
); );
}; };
......
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