mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* Support redirect to a correct view from search * show domains on address page * migrate to new API version to display address domains * another api update * new design for chain widget on home page + tests * chain widget styles for mobile devices * ecosystems page * update types * add ecosystems to navigation * address portfolio: pt.1 * portfolio tokens list * filter portfolio by chain * skip redirect when navigating to search result by clicking on "show all results" link * net worth block design * add filter input to chain select and fix tokens table * calculate address portfolio * adjust card logic * support custom token types in multichain explorer * handle case when new worth is 0 * add text filter to tokens list * fixes * demo envs * portfolio tests * ecosystems test * change signature for getTokenTypes function * fix adding token to the wallet from the list * lazy load all address domains * show contract creator and implementations info * fix tests * add poor reputation tokens toggle * tweaks * dim celo native tokens * disable env validator * fix tests * remove tokens with 0 usd value from top tokens * fixes * preserve selected chain when switching tabs on address page * add hints to stats widgets on home page * update envs for demo * fix portfolio cards and home page * update styles for contract creator and implementations * fix select issues * add chains from cluster to network menu * hide csv export link on empty logs page * update screenshots * rollback select fix * update cut length calculation for portfolio cards * fix chain select * update screenshots * fix tests * more fixes * add sorting to ecosystems table * fix test * fixes * fix loading state in ecosystems page * review fixes * fix tests
103 lines
4.1 KiB
TypeScript
103 lines
4.1 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query';
|
|
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import type { SocketMessage } from 'lib/socket/types';
|
|
import type { Address } from 'types/api/address';
|
|
|
|
import { getResourceKey } from 'lib/api/useApiQuery';
|
|
import delay from 'lib/delay';
|
|
import useIsMobile from 'lib/hooks/useIsMobile';
|
|
import getQueryParamString from 'lib/router/getQueryParamString';
|
|
import useSocketChannel from 'lib/socket/useSocketChannel';
|
|
import useSocketMessage from 'lib/socket/useSocketMessage';
|
|
import type { Props as RoutedTabsProps } from 'toolkit/components/AdaptiveTabs/AdaptiveTabs';
|
|
import RoutedTabs from 'toolkit/components/RoutedTabs/RoutedTabs';
|
|
import { SECOND } from 'toolkit/utils/consts';
|
|
|
|
import type { TContractAutoVerificationStatus } from './contract/ContractAutoVerificationStatus';
|
|
import ContractAutoVerificationStatus from './contract/ContractAutoVerificationStatus';
|
|
import useContractTabs from './contract/useContractTabs';
|
|
import { CONTRACT_TAB_IDS } from './contract/utils';
|
|
|
|
interface Props extends Pick<RoutedTabsProps, 'leftSlot' | 'leftSlotProps'> {
|
|
addressData: Address | undefined;
|
|
isLoading?: boolean;
|
|
hasMudTab?: boolean;
|
|
}
|
|
|
|
const AddressContract = ({ addressData, isLoading = false, hasMudTab, ...rest }: Props) => {
|
|
const [ isQueryEnabled, setIsQueryEnabled ] = React.useState(false);
|
|
const [ autoVerificationStatus, setAutoVerificationStatus ] = React.useState<TContractAutoVerificationStatus | null>(null);
|
|
|
|
const router = useRouter();
|
|
const queryClient = useQueryClient();
|
|
const isMobile = useIsMobile();
|
|
const handleChannelJoin = React.useCallback(() => {
|
|
setIsQueryEnabled(true);
|
|
}, []);
|
|
const handleChannelError = React.useCallback(() => {
|
|
setIsQueryEnabled(true);
|
|
}, []);
|
|
|
|
const tab = getQueryParamString(router.query.tab);
|
|
const isSocketEnabled = Boolean(addressData?.hash) && addressData?.is_contract && !isLoading && CONTRACT_TAB_IDS.concat('contract' as never).includes(tab);
|
|
|
|
const channel = useSocketChannel({
|
|
topic: `addresses:${ addressData?.hash?.toLowerCase() }`,
|
|
isDisabled: !isSocketEnabled,
|
|
onJoin: handleChannelJoin,
|
|
onSocketError: handleChannelError,
|
|
});
|
|
|
|
const contractTabs = useContractTabs({
|
|
addressData,
|
|
isEnabled: isQueryEnabled && !isLoading,
|
|
hasMudTab,
|
|
channel,
|
|
});
|
|
|
|
const handleLookupStartedMessage: SocketMessage.EthBytecodeDbLookupStarted['handler'] = React.useCallback(() => {
|
|
setAutoVerificationStatus('pending');
|
|
}, []);
|
|
|
|
const handleContractWasVerifiedMessage: SocketMessage.SmartContractWasVerified['handler'] = React.useCallback(async() => {
|
|
setAutoVerificationStatus('success');
|
|
await queryClient.refetchQueries({
|
|
queryKey: getResourceKey('general:address', { pathParams: { hash: addressData?.hash } }),
|
|
});
|
|
await queryClient.refetchQueries({
|
|
queryKey: getResourceKey('general:contract', { pathParams: { hash: addressData?.hash } }),
|
|
});
|
|
setAutoVerificationStatus(null);
|
|
}, [ addressData?.hash, queryClient ]);
|
|
|
|
const handleContractWasNotVerifiedMessage: SocketMessage.SmartContractWasNotVerified['handler'] = React.useCallback(async() => {
|
|
setAutoVerificationStatus('failed');
|
|
await delay(10 * SECOND);
|
|
setAutoVerificationStatus(null);
|
|
}, []);
|
|
|
|
useSocketMessage({ channel, event: 'eth_bytecode_db_lookup_started', handler: handleLookupStartedMessage });
|
|
useSocketMessage({ channel, event: 'smart_contract_was_verified', handler: handleContractWasVerifiedMessage });
|
|
useSocketMessage({ channel, event: 'smart_contract_was_not_verified', handler: handleContractWasNotVerifiedMessage });
|
|
|
|
const rightSlot = autoVerificationStatus && !contractTabs.isPartiallyVerified ?
|
|
<ContractAutoVerificationStatus status={ autoVerificationStatus } mode={ isMobile && contractTabs.tabs.length > 1 ? 'tooltip' : 'inline' }/> :
|
|
null;
|
|
|
|
return (
|
|
<RoutedTabs
|
|
tabs={ contractTabs.tabs }
|
|
variant="secondary"
|
|
size="sm"
|
|
isLoading={ contractTabs.isLoading }
|
|
rightSlot={ rightSlot }
|
|
rightSlotProps={{ ml: contractTabs.tabs.length > 1 ? { base: 'auto', md: 6 } : 0 }}
|
|
{ ...rest }
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default React.memo(AddressContract);
|