Commit 997c4dde authored by tom goriunov's avatar tom goriunov Committed by GitHub

Fix loading state for the address hash in address page subtitle (#2752)

* fix loading state for the address hash in address page subtitle

* fix ts
parent b75a926f
...@@ -31,9 +31,10 @@ import type { AddressQuery } from './utils/useAddressQuery'; ...@@ -31,9 +31,10 @@ import type { AddressQuery } from './utils/useAddressQuery';
interface Props { interface Props {
addressQuery: AddressQuery; addressQuery: AddressQuery;
isLoading?: boolean;
} }
const AddressDetails = ({ addressQuery }: Props) => { const AddressDetails = ({ addressQuery, isLoading }: Props) => {
const router = useRouter(); const router = useRouter();
const addressHash = getQueryParamString(router.query.hash); const addressHash = getQueryParamString(router.query.hash);
...@@ -85,9 +86,9 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -85,9 +86,9 @@ const AddressDetails = ({ addressQuery }: Props) => {
return ( return (
<> <>
{ addressQuery.isDegradedData && <ServiceDegradationWarning isLoading={ addressQuery.isPlaceholderData } mb={ 6 }/> } { addressQuery.isDegradedData && <ServiceDegradationWarning isLoading={ isLoading } mb={ 6 }/> }
<DetailedInfo.Container templateColumns={{ base: 'minmax(0, 1fr)', lg: 'auto minmax(0, 1fr)' }} > <DetailedInfo.Container templateColumns={{ base: 'minmax(0, 1fr)', lg: 'auto minmax(0, 1fr)' }} >
<AddressAlternativeFormat isLoading={ addressQuery.isPlaceholderData } addressHash={ addressHash }/> <AddressAlternativeFormat isLoading={ isLoading } addressHash={ addressHash }/>
{ data.filecoin?.id && ( { data.filecoin?.id && (
<> <>
...@@ -133,13 +134,13 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -133,13 +134,13 @@ const AddressDetails = ({ addressQuery }: Props) => {
</> </>
) } ) }
<AddressNameInfo data={ data } isLoading={ addressQuery.isPlaceholderData }/> <AddressNameInfo data={ data } isLoading={ isLoading }/>
{ data.is_contract && data.creation_transaction_hash && (creatorAddressHash) && ( { data.is_contract && data.creation_transaction_hash && (creatorAddressHash) && (
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Transaction and address of creation" hint="Transaction and address of creation"
isLoading={ addressQuery.isPlaceholderData } isLoading={ isLoading }
> >
Creator Creator
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
...@@ -154,15 +155,15 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -154,15 +155,15 @@ const AddressDetails = ({ addressQuery }: Props) => {
</DetailedInfo.ItemValue> </DetailedInfo.ItemValue>
</> </>
) } ) }
{ !addressQuery.isPlaceholderData && data.is_contract && data.implementations && data.implementations?.length > 0 && ( { !isLoading && data.is_contract && data.implementations && data.implementations?.length > 0 && (
<AddressImplementations <AddressImplementations
data={ data.implementations } data={ data.implementations }
isLoading={ addressQuery.isPlaceholderData } isLoading={ isLoading }
proxyType={ data.proxy_type } proxyType={ data.proxy_type }
/> />
) } ) }
<AddressBalance data={ data } isLoading={ addressQuery.isPlaceholderData }/> <AddressBalance data={ data } isLoading={ isLoading }/>
{ data.has_tokens && ( { data.has_tokens && (
<> <>
...@@ -180,12 +181,12 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -180,12 +181,12 @@ const AddressDetails = ({ addressQuery }: Props) => {
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Total net worth in USD of all tokens for the address" hint="Total net worth in USD of all tokens for the address"
isLoading={ addressQuery.isPlaceholderData } isLoading={ isLoading }
> >
Net worth Net worth
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
<DetailedInfo.ItemValue alignSelf="center" py={ 0 }> <DetailedInfo.ItemValue alignSelf="center" py={ 0 }>
<AddressNetWorth addressData={ addressQuery.data } addressHash={ addressHash } isLoading={ addressQuery.isPlaceholderData }/> <AddressNetWorth addressData={ addressQuery.data } addressHash={ addressHash } isLoading={ isLoading }/>
</DetailedInfo.ItemValue> </DetailedInfo.ItemValue>
</> </>
) )
...@@ -193,7 +194,7 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -193,7 +194,7 @@ const AddressDetails = ({ addressQuery }: Props) => {
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Number of transactions related to this address" hint="Number of transactions related to this address"
isLoading={ addressQuery.isPlaceholderData || countersQuery.isPlaceholderData } isLoading={ isLoading || countersQuery.isPlaceholderData }
> >
Transactions Transactions
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
...@@ -214,7 +215,7 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -214,7 +215,7 @@ const AddressDetails = ({ addressQuery }: Props) => {
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Number of transfers to/from this address" hint="Number of transfers to/from this address"
isLoading={ addressQuery.isPlaceholderData || countersQuery.isPlaceholderData } isLoading={ isLoading || countersQuery.isPlaceholderData }
> >
Transfers Transfers
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
...@@ -237,7 +238,7 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -237,7 +238,7 @@ const AddressDetails = ({ addressQuery }: Props) => {
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Gas used by the address" hint="Gas used by the address"
isLoading={ addressQuery.isPlaceholderData || countersQuery.isPlaceholderData } isLoading={ isLoading || countersQuery.isPlaceholderData }
> >
Gas used Gas used
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
...@@ -266,7 +267,7 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -266,7 +267,7 @@ const AddressDetails = ({ addressQuery }: Props) => {
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint={ `Number of blocks ${ getNetworkValidationActionText() } by this ${ getNetworkValidatorTitle() }` } hint={ `Number of blocks ${ getNetworkValidationActionText() } by this ${ getNetworkValidatorTitle() }` }
isLoading={ addressQuery.isPlaceholderData || countersQuery.isPlaceholderData } isLoading={ isLoading || countersQuery.isPlaceholderData }
> >
{ `Blocks ${ getNetworkValidationActionText() }` } { `Blocks ${ getNetworkValidationActionText() }` }
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
...@@ -289,20 +290,20 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -289,20 +290,20 @@ const AddressDetails = ({ addressQuery }: Props) => {
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
hint="Block number in which the address was updated" hint="Block number in which the address was updated"
isLoading={ addressQuery.isPlaceholderData } isLoading={ isLoading }
> >
Last balance update Last balance update
</DetailedInfo.ItemLabel> </DetailedInfo.ItemLabel>
<DetailedInfo.ItemValue> <DetailedInfo.ItemValue>
<BlockEntity <BlockEntity
number={ data.block_number_balance_updated_at } number={ data.block_number_balance_updated_at }
isLoading={ addressQuery.isPlaceholderData } isLoading={ isLoading }
/> />
</DetailedInfo.ItemValue> </DetailedInfo.ItemValue>
</> </>
) } ) }
<DetailedInfoSponsoredItem isLoading={ addressQuery.isPlaceholderData }/> <DetailedInfoSponsoredItem isLoading={ isLoading }/>
</DetailedInfo.Container> </DetailedInfo.Container>
</> </>
); );
......
...@@ -7,7 +7,7 @@ import * as DetailedInfo from 'ui/shared/DetailedInfo/DetailedInfo'; ...@@ -7,7 +7,7 @@ import * as DetailedInfo from 'ui/shared/DetailedInfo/DetailedInfo';
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import AddressEntity from 'ui/shared/entities/address/AddressEntity';
interface Props { interface Props {
isLoading: boolean; isLoading?: boolean;
addressHash: string; addressHash: string;
} }
......
...@@ -15,7 +15,7 @@ import NativeTokenIcon from 'ui/shared/NativeTokenIcon'; ...@@ -15,7 +15,7 @@ import NativeTokenIcon from 'ui/shared/NativeTokenIcon';
interface Props { interface Props {
data: Pick<Address, 'block_number_balance_updated_at' | 'coin_balance' | 'hash' | 'exchange_rate'>; data: Pick<Address, 'block_number_balance_updated_at' | 'coin_balance' | 'hash' | 'exchange_rate'>;
isLoading: boolean; isLoading?: boolean;
} }
const AddressBalance = ({ data, isLoading }: Props) => { const AddressBalance = ({ data, isLoading }: Props) => {
......
...@@ -8,7 +8,7 @@ import TokenEntity from 'ui/shared/entities/token/TokenEntity'; ...@@ -8,7 +8,7 @@ import TokenEntity from 'ui/shared/entities/token/TokenEntity';
interface Props { interface Props {
data: Pick<Address, 'name' | 'token' | 'is_contract'>; data: Pick<Address, 'name' | 'token' | 'is_contract'>;
isLoading: boolean; isLoading?: boolean;
} }
const AddressNameInfo = ({ data, isLoading }: Props) => { const AddressNameInfo = ({ data, isLoading }: Props) => {
......
...@@ -155,7 +155,7 @@ const AddressPageContent = () => { ...@@ -155,7 +155,7 @@ const AddressPageContent = () => {
{ {
id: 'index', id: 'index',
title: 'Details', title: 'Details',
component: <AddressDetails addressQuery={ addressQuery }/>, component: <AddressDetails addressQuery={ addressQuery } isLoading={ isTabsLoading }/>,
}, },
addressQuery.data?.is_contract ? { addressQuery.data?.is_contract ? {
id: 'contract', id: 'contract',
...@@ -370,7 +370,13 @@ const AddressPageContent = () => { ...@@ -370,7 +370,13 @@ const AddressPageContent = () => {
// API always returns hash in check-summed format except for addresses that are not in the database // API always returns hash in check-summed format except for addresses that are not in the database
// In this case it returns 404 with empty payload, so we calculate check-summed hash on the client // In this case it returns 404 with empty payload, so we calculate check-summed hash on the client
const checkSummedHash = React.useMemo(() => addressQuery.data?.hash ?? getCheckedSummedAddress(hash), [ hash, addressQuery.data?.hash ]); const checkSummedHash = React.useMemo(() => {
if (isLoading) {
return getCheckedSummedAddress(hash);
}
return addressQuery.data?.hash ?? getCheckedSummedAddress(hash);
}, [ hash, addressQuery.data?.hash, isLoading ]);
const titleSecondRow = ( const titleSecondRow = (
<Flex alignItems="center" w="100%" columnGap={ 2 } rowGap={ 2 } flexWrap={{ base: 'wrap', lg: 'nowrap' }}> <Flex alignItems="center" w="100%" columnGap={ 2 } rowGap={ 2 } flexWrap={{ base: 'wrap', lg: 'nowrap' }}>
......
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