Files
tom goriunovandGitHub ebbee2ba57 Multichain explorer v2 (#3259)
* 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
2026-02-25 10:45:09 +01:00

93 lines
3.0 KiB
TypeScript

import { Box, createListCollection, Separator } from '@chakra-ui/react';
import React from 'react';
import type { ExternalChain } from 'types/externalChains';
import useIsInitialLoading from 'lib/hooks/useIsInitialLoading';
import useIsMobile from 'lib/hooks/useIsMobile';
import type { SelectOption, SelectProps, ViewMode } from 'toolkit/chakra/select';
import { Select } from 'toolkit/chakra/select';
import { FilterInput } from 'toolkit/components/filters/FilterInput';
import IconSvg from 'ui/shared/IconSvg';
import ChainIcon from './ChainIcon';
const ALL_OPTION: SelectOption = {
value: 'all',
label: 'All chains',
icon: <IconSvg name="pie_chart" boxSize={ 5 }/>,
afterElement: <Separator orientation="horizontal" w="full"/>,
};
export interface Props extends Omit<SelectProps, 'collection' | 'placeholder'> {
loading?: boolean;
mode?: ViewMode;
chainsConfig: Array<Omit<ExternalChain, 'explorer_url'>>;
chainIds?: Array<string>;
withAllOption?: boolean;
}
const ChainSelect = ({ loading, mode, chainsConfig, chainIds, withAllOption, ...props }: Props) => {
const [ inputValue, setInputValue ] = React.useState('');
const isInitialLoading = useIsInitialLoading(loading);
const isMobile = useIsMobile();
const allItems = React.useMemo(() => {
const chainItems = chainsConfig
.filter((chain) => !chainIds || isInitialLoading || chainIds.includes(chain.id))
.map((chain) => ({
value: chain.id,
label: chain.name || `Chain ${ chain.id }`,
icon: <ChainIcon data={ chain } alt={ `${ chain.name } logo` } borderRadius="none" noTooltip/>,
})) || [];
return [ withAllOption ? ALL_OPTION : undefined, ...chainItems ].filter(Boolean);
}, [ chainsConfig, chainIds, withAllOption, isInitialLoading ]);
const collection = React.useMemo(() => {
return createListCollection<SelectOption>({ items: allItems });
}, [ allItems ]);
const handleFilterChange = React.useCallback((value: string) => {
setInputValue(value);
}, [ ]);
const itemFilter = React.useCallback((item: SelectOption) => {
return item.label.toLowerCase().includes(inputValue.toLowerCase());
}, [ inputValue ]);
const contentHeader = allItems.length > 10 ? (
<Box px="4" pt={ 4 } pb={ 2 } position="sticky" top={ 0 } zIndex={ 1 } bgColor="popover.bg">
<FilterInput
placeholder="Find chain"
initialValue={ inputValue }
onChange={ handleFilterChange }
/>
</Box>
) : null;
if (allItems.length === 0) {
return null;
}
return (
<Select
collection={ collection }
defaultValue={ allItems.length > 0 ? [ allItems[0].value ] : undefined }
placeholder="Select chain"
loading={ isInitialLoading }
mode={ isMobile && !mode ? 'compact' : mode }
w="fit-content"
flexShrink={ 0 }
contentHeader={ contentHeader }
contentProps={ contentHeader ? { pt: 0 } : undefined }
itemFilter={ itemFilter }
{ ...props }
/>
);
};
export default React.memo(ChainSelect);