Commit ee968da1 authored by Igor Stuev's avatar Igor Stuev Committed by GitHub

Merge pull request #1934 from blockscout/fe-1933

token balance design update
parents 2a182909 7437d53f
...@@ -8,6 +8,8 @@ import { ZERO } from 'lib/consts'; ...@@ -8,6 +8,8 @@ import { ZERO } from 'lib/consts';
import getCurrencyValue from 'lib/getCurrencyValue'; import getCurrencyValue from 'lib/getCurrencyValue';
import { currencyUnits } from 'lib/units'; import { currencyUnits } from 'lib/units';
import DataFetchAlert from 'ui/shared/DataFetchAlert'; import DataFetchAlert from 'ui/shared/DataFetchAlert';
import IconSvg from 'ui/shared/IconSvg';
import NativeTokenIcon from 'ui/shared/NativeTokenIcon';
import { getTokensTotalInfo } from '../utils/tokenUtils'; import { getTokensTotalInfo } from '../utils/tokenUtils';
import useFetchTokens from '../utils/useFetchTokens'; import useFetchTokens from '../utils/useFetchTokens';
...@@ -42,28 +44,30 @@ const TokenBalances = () => { ...@@ -42,28 +44,30 @@ const TokenBalances = () => {
const prefix = tokensInfo.isOverflow ? '>' : ''; const prefix = tokensInfo.isOverflow ? '>' : '';
const totalUsd = nativeUsd.plus(tokensInfo.usd); const totalUsd = nativeUsd.plus(tokensInfo.usd);
const tokensNumText = tokensInfo.num > 0 ? const tokensNumText = tokensInfo.num > 0 ?
` | ${ prefix }${ tokensInfo.num } ${ tokensInfo.num > 1 ? 'tokens' : 'token' }` : `${ prefix }${ tokensInfo.num } ${ tokensInfo.num > 1 ? 'tokens' : 'token' }` :
''; '';
return ( return (
<Flex columnGap={ 3 } rowGap={ 3 } mt={{ base: '6px', lg: 0 }} flexDirection={{ base: 'column', lg: 'row' }}> <Flex columnGap={ 3 } rowGap={ 3 } mt={{ base: '6px', lg: 0 }} flexDirection={{ base: 'column', lg: 'row' }}>
<TokenBalancesItem <TokenBalancesItem
name="Net Worth" name="Net Worth"
value={ addressData?.exchange_rate ? `${ prefix }$${ totalUsd.toFormat(2) } USD` : 'N/A' } value={ addressData?.exchange_rate ? `${ prefix }$${ totalUsd.toFormat(2) }` : 'N/A' }
isLoading={ addressQuery.isPending || tokenQuery.isPending } isLoading={ addressQuery.isPending || tokenQuery.isPending }
icon={ <IconSvg name="wallet" boxSize="24px" flexShrink={ 0 }/> }
/> />
<TokenBalancesItem <TokenBalancesItem
name={ `${ currencyUnits.ether } Balance` } name={ `${ currencyUnits.ether } Balance` }
value={ (!nativeUsd.eq(ZERO) ? `$${ nativeUsd.toFormat(2) } USD | ` : '') + `${ nativeValue } ${ currencyUnits.ether }` } value={ `${ nativeValue } ${ currencyUnits.ether }` }
valueSecondary={ !nativeUsd.eq(ZERO) ? `$${ nativeUsd.toFormat(2) }` : '' }
isLoading={ addressQuery.isPending || tokenQuery.isPending } isLoading={ addressQuery.isPending || tokenQuery.isPending }
icon={ <NativeTokenIcon boxSize="20px"/> }
/> />
<TokenBalancesItem <TokenBalancesItem
name="Tokens" name="Tokens"
value={ value={ tokensNumText }
`${ prefix }$${ tokensInfo.usd.toFormat(2) } USD ` + valueSecondary={ `${ prefix }$${ tokensInfo.usd.toFormat(2) }` }
tokensNumText
}
isLoading={ addressQuery.isPending || tokenQuery.isPending } isLoading={ addressQuery.isPending || tokenQuery.isPending }
icon={ <IconSvg name="tokens" boxSize="20px" flexShrink={ 0 }/> }
/> />
</Flex> </Flex>
); );
......
import { Box, Flex, Skeleton, Text, useColorModeValue } from '@chakra-ui/react'; import { Box, Flex, Skeleton, Text, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import IconSvg from 'ui/shared/IconSvg'; type Props = {
name: string;
value: string;
icon: React.ReactNode;
valueSecondary?: string;
isLoading: boolean;
}
const TokenBalancesItem = ({ name, value, isLoading }: {name: string; value: string; isLoading: boolean }) => { const TokenBalancesItem = ({ name, icon, value, valueSecondary, isLoading }: Props) => {
const bgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50'); const bgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
return ( return (
<Flex p={ 5 } bgColor={ bgColor } borderRadius="16px" alignItems="center"> <Box px="12px" py="10px" bgColor={ bgColor } borderRadius="16px">
<IconSvg name="wallet" boxSize="30px" mr={ 3 } flexShrink={ 0 }/>
<Box>
<Text variant="secondary" fontSize="xs">{ name }</Text> <Text variant="secondary" fontSize="xs">{ name }</Text>
<Skeleton isLoaded={ !isLoading } fontWeight="500" whiteSpace="pre-wrap" wordBreak="break-word">{ value }</Skeleton> <Flex alignItems="center">
</Box> { icon }
<Skeleton isLoaded={ !isLoading } fontWeight="500" whiteSpace="pre-wrap" wordBreak="break-word" display="flex" ml={ 2 }>
{ value }
{ Boolean(valueSecondary) && <Text color="text_secondary"> ({ valueSecondary })</Text> }
</Skeleton>
</Flex> </Flex>
</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