Commit cd7118ac authored by isstuev's avatar isstuev

add token logo and back links for token and address pages

parent 02977865
...@@ -7,6 +7,8 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types'; ...@@ -7,6 +7,8 @@ import type { RoutedTab } from 'ui/shared/RoutedTabs/types';
import iconSuccess from 'icons/status/success.svg'; import iconSuccess from 'icons/status/success.svg';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/appContext';
import isBrowser from 'lib/isBrowser';
import notEmpty from 'lib/notEmpty'; import notEmpty from 'lib/notEmpty';
import AddressBlocksValidated from 'ui/address/AddressBlocksValidated'; import AddressBlocksValidated from 'ui/address/AddressBlocksValidated';
import AddressCoinBalance from 'ui/address/AddressCoinBalance'; import AddressCoinBalance from 'ui/address/AddressCoinBalance';
...@@ -37,6 +39,13 @@ const TOKEN_TABS = Object.values(tokenTabsByType); ...@@ -37,6 +39,13 @@ const TOKEN_TABS = Object.values(tokenTabsByType);
const AddressPageContent = () => { const AddressPageContent = () => {
const router = useRouter(); const router = useRouter();
const appProps = useAppContext();
const isInBrowser = isBrowser();
const referrer = isInBrowser ? window.document.referrer : appProps.referrer;
const hasGoBackLink = referrer && referrer.includes('/accounts');
const tabsScrollRef = React.useRef<HTMLDivElement>(null); const tabsScrollRef = React.useRef<HTMLDivElement>(null);
const addressQuery = useApiQuery('address', { const addressQuery = useApiQuery('address', {
...@@ -121,7 +130,9 @@ const AddressPageContent = () => { ...@@ -121,7 +130,9 @@ const AddressPageContent = () => {
) : ( ) : (
<PageTitle <PageTitle
text={ `${ addressQuery.data?.is_contract ? 'Contract' : 'Address' } details` } text={ `${ addressQuery.data?.is_contract ? 'Contract' : 'Address' } details` }
additionals={ tagsNode } additionalsRight={ tagsNode }
backLinkUrl={ hasGoBackLink ? referrer : undefined }
backLinkLabel="Back to top accounts list"
/> />
) } ) }
<AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/> <AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/>
......
import { Skeleton, Box } from '@chakra-ui/react'; import { Skeleton, Box, Flex, SkeletonCircle } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import type { RoutedTab } from 'ui/shared/RoutedTabs/types'; import type { RoutedTab } from 'ui/shared/RoutedTabs/types';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/appContext';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import useQueryWithPages from 'lib/hooks/useQueryWithPages'; import useQueryWithPages from 'lib/hooks/useQueryWithPages';
import isBrowser from 'lib/isBrowser';
import Page from 'ui/shared/Page/Page'; import Page from 'ui/shared/Page/Page';
import PageTitle from 'ui/shared/Page/PageTitle'; import PageTitle from 'ui/shared/Page/PageTitle';
import type { Props as PaginationProps } from 'ui/shared/Pagination'; import type { Props as PaginationProps } from 'ui/shared/Pagination';
import Pagination from 'ui/shared/Pagination'; import Pagination from 'ui/shared/Pagination';
import RoutedTabs from 'ui/shared/RoutedTabs/RoutedTabs'; import RoutedTabs from 'ui/shared/RoutedTabs/RoutedTabs';
import TokenLogo from 'ui/shared/TokenLogo';
import TokenContractInfo from 'ui/token/TokenContractInfo'; import TokenContractInfo from 'ui/token/TokenContractInfo';
import TokenDetails from 'ui/token/TokenDetails'; import TokenDetails from 'ui/token/TokenDetails';
import TokenHolders from 'ui/token/TokenHolders/TokenHolders'; import TokenHolders from 'ui/token/TokenHolders/TokenHolders';
...@@ -23,6 +26,13 @@ const TokenPageContent = () => { ...@@ -23,6 +26,13 @@ const TokenPageContent = () => {
const router = useRouter(); const router = useRouter();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
const appProps = useAppContext();
const isInBrowser = isBrowser();
const referrer = isInBrowser ? window.document.referrer : appProps.referrer;
const hasGoBackLink = referrer && referrer.includes('/tokens');
const scrollRef = React.useRef<HTMLDivElement>(null); const scrollRef = React.useRef<HTMLDivElement>(null);
const tokenQuery = useApiQuery('token', { const tokenQuery = useApiQuery('token', {
...@@ -68,9 +78,21 @@ const TokenPageContent = () => { ...@@ -68,9 +78,21 @@ const TokenPageContent = () => {
return ( return (
<Page> <Page>
{ tokenQuery.isLoading ? { tokenQuery.isLoading ? (
<Skeleton w="500px" h={ 10 } mb={ 6 }/> : <Flex alignItems="center" mb={ 6 }>
<PageTitle text={ `${ tokenQuery.data?.name } (${ tokenQuery.data?.symbol }) token` }/> } <SkeletonCircle w={ 6 } h={ 6 } mr={ 3 }/>
<Skeleton w="500px" h={ 10 }/>
</Flex>
) : (
<PageTitle
text={ `${ tokenQuery.data?.name } (${ tokenQuery.data?.symbol }) token` }
backLinkUrl={ hasGoBackLink ? referrer : undefined }
backLinkLabel="Back to tokens list"
additionalsLeft={ (
<TokenLogo hash={ tokenQuery.data?.address } name={ tokenQuery.data?.name } boxSize={ 6 }/>
) }
/>
) }
<TokenContractInfo tokenQuery={ tokenQuery }/> <TokenContractInfo tokenQuery={ tokenQuery }/>
<TokenDetails tokenQuery={ tokenQuery }/> <TokenDetails tokenQuery={ tokenQuery }/>
......
...@@ -73,7 +73,7 @@ const TransactionPageContent = () => { ...@@ -73,7 +73,7 @@ const TransactionPageContent = () => {
<TextAd mb={ 6 }/> <TextAd mb={ 6 }/>
<PageTitle <PageTitle
text="Transaction details" text="Transaction details"
additionals={ additionals } additionalsRight={ additionals }
backLinkUrl={ hasGoBackLink ? referrer : undefined } backLinkUrl={ hasGoBackLink ? referrer : undefined }
backLinkLabel="Back to transactions list" backLinkLabel="Back to transactions list"
/> />
......
// import { Icon } from '@chakra-ui/react';
import { test, expect } from '@playwright/experimental-ct-react'; import { test, expect } from '@playwright/experimental-ct-react';
import React from 'react'; import React from 'react';
// import plusIcon from 'icons/plus.svg';
import * as textAdMock from 'mocks/ad/textAd'; import * as textAdMock from 'mocks/ad/textAd';
import TestApp from 'playwright/TestApp'; import TestApp from 'playwright/TestApp';
...@@ -32,6 +34,10 @@ test('default view +@mobile', async({ mount }) => { ...@@ -32,6 +34,10 @@ test('default view +@mobile', async({ mount }) => {
}); });
test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount }) => { test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount }) => {
// https://github.com/microsoft/playwright/issues/15620
// not possible to pass component as a prop in tests
// const left = <Icon as={ plusIcon }/>;
const component = await mount( const component = await mount(
<TestApp> <TestApp>
<PageTitle <PageTitle
...@@ -39,7 +45,8 @@ test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount }) ...@@ -39,7 +45,8 @@ test('with text ad, back link and addons +@mobile +@dark-mode', async({ mount })
withTextAd withTextAd
backLinkLabel="Back" backLinkLabel="Back"
backLinkUrl="back" backLinkUrl="back"
additionals="Privet" // additionalsLeft={ left }
additionalsRight="Privet"
/> />
</TestApp>, </TestApp>,
); );
...@@ -55,7 +62,7 @@ test('long title with text ad, back link and addons +@mobile', async({ mount }) ...@@ -55,7 +62,7 @@ test('long title with text ad, back link and addons +@mobile', async({ mount })
withTextAd withTextAd
backLinkLabel="Back" backLinkLabel="Back"
backLinkUrl="back" backLinkUrl="back"
additionals="Privet, kak dela?" additionalsRight="Privet, kak dela?"
/> />
</TestApp>, </TestApp>,
); );
......
import { Heading, Flex, Tooltip, Link, Icon, chakra } from '@chakra-ui/react'; import { Heading, Flex, Grid, Tooltip, Link, Icon, chakra } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import eastArrowIcon from 'icons/arrows/east.svg'; import eastArrowIcon from 'icons/arrows/east.svg';
...@@ -6,23 +6,20 @@ import TextAd from 'ui/shared/ad/TextAd'; ...@@ -6,23 +6,20 @@ import TextAd from 'ui/shared/ad/TextAd';
type Props = { type Props = {
text: string; text: string;
additionals?: React.ReactNode; additionalsLeft?: React.ReactNode;
additionalsRight?: React.ReactNode;
withTextAd?: boolean; withTextAd?: boolean;
className?: string; className?: string;
backLinkLabel?: string; backLinkLabel?: string;
backLinkUrl?: string; backLinkUrl?: string;
} }
const PageTitle = ({ text, additionals, withTextAd, backLinkUrl, backLinkLabel, className }: Props) => { const PageTitle = ({ text, additionalsLeft, additionalsRight, withTextAd, backLinkUrl, backLinkLabel, className }: Props) => {
const title = ( const title = (
<Heading <Heading
as="h1" as="h1"
size="lg" size="lg"
flex="none" flex="none"
overflow="hidden"
textOverflow="ellipsis"
whiteSpace="nowrap"
width={ backLinkUrl ? 'calc(100% - 36px)' : '100%' }
> >
{ text } { text }
</Heading> </Heading>
...@@ -39,22 +36,25 @@ const PageTitle = ({ text, additionals, withTextAd, backLinkUrl, backLinkLabel, ...@@ -39,22 +36,25 @@ const PageTitle = ({ text, additionals, withTextAd, backLinkUrl, backLinkLabel,
className={ className } className={ className }
> >
<Flex flexWrap="wrap" columnGap={ 3 } alignItems="center" width={ withTextAd ? 'unset' : '100%' }> <Flex flexWrap="wrap" columnGap={ 3 } alignItems="center" width={ withTextAd ? 'unset' : '100%' }>
<Flex <Grid
flexWrap="nowrap" templateColumns={ [ backLinkUrl && 'auto', additionalsLeft && 'auto', '1fr' ].filter(Boolean).join(' ') }
alignItems="center"
columnGap={ 3 } columnGap={ 3 }
overflow="hidden"
> >
{ backLinkUrl && ( { backLinkUrl && (
<Tooltip label={ backLinkLabel }> <Tooltip label={ backLinkLabel }>
<Link display="inline-flex" href={ backLinkUrl }> <Link display="inline-flex" href={ backLinkUrl } h="40px">
<Icon as={ eastArrowIcon } boxSize={ 6 } transform="rotate(180deg)"/> <Icon as={ eastArrowIcon } boxSize={ 6 } transform="rotate(180deg)" margin="auto"/>
</Link> </Link>
</Tooltip> </Tooltip>
) } ) }
{ additionalsLeft !== undefined && (
<Flex h="40px" alignItems="center">
{ additionalsLeft }
</Flex>
) }
{ title } { title }
</Flex> </Grid>
{ additionals } { additionalsRight }
</Flex> </Flex>
{ withTextAd && <TextAd flexShrink={ 100 }/> } { withTextAd && <TextAd flexShrink={ 100 }/> }
</Flex> </Flex>
......
...@@ -69,11 +69,6 @@ const TokenDetails = ({ tokenQuery }: Props) => { ...@@ -69,11 +69,6 @@ const TokenDetails = ({ tokenQuery }: Props) => {
); );
} }
// we show error in parent component, this is only for TS
if (tokenQuery.isError) {
return null;
}
const { const {
exchange_rate: exchangeRate, exchange_rate: exchangeRate,
total_supply: totalSupply, total_supply: totalSupply,
......
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