mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* update styles for chain widgets on home page * update latest txs styles and slug creation algorithm * list of local txs * list of local blocks * local view for address internal tx tab * local view for address coin history * local view for address logs * local view for address token transfers * address details, kind of * [wip] local view for address contract tab * user ops views * chain popover * csv-export page * advanced filter page * block countdown pages * fixes for contract tab * refactor address txs and transfers tabs * refactor getServerSideProps * internal txs page * tokens and token transfers pages * simple tag for address page and details info placeholders * add chain icon to the local lists * show creator in contract tab * OP Superchain: local views for chains in the cluster Fixes #2827 * highlight current chain in the title of local entities * tokens nfts tab for address * allow entity icon to be an image * adjust cross-chain txs table and add placeholder to home page * cross-chain txs for address * fetch multichain config from microservice * fix skeleton in token transfers table * tests, pt.1 * wtf with gh * verified contracts page * change chain info in block and token page header * fix some tests * update styles for token icon with chain logo in header * fix links and address internal txs tab * update screenshots * fix margins for tx info button and chain icon in tx tables * add some tests * fix screenshots
82 lines
3.1 KiB
TypeScript
82 lines
3.1 KiB
TypeScript
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import type { VerifiedContractsFilters } from 'types/api/contracts';
|
|
import type { VerifiedContractsSorting, VerifiedContractsSortingField, VerifiedContractsSortingValue } from 'types/api/verifiedContracts';
|
|
|
|
import useDebounce from 'lib/hooks/useDebounce';
|
|
import getQueryParamString from 'lib/router/getQueryParamString';
|
|
import { VERIFIED_CONTRACT_INFO } from 'stubs/contract';
|
|
import { generateListStub } from 'stubs/utils';
|
|
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages';
|
|
import getSortParamsFromValue from 'ui/shared/sort/getSortParamsFromValue';
|
|
import getSortValueFromQuery from 'ui/shared/sort/getSortValueFromQuery';
|
|
|
|
import { SORT_OPTIONS } from './utils';
|
|
|
|
interface Props {
|
|
isMultichain?: boolean;
|
|
}
|
|
|
|
export default function useVerifiedContractsQuery({ isMultichain }: Props = {}) {
|
|
const router = useRouter();
|
|
const [ searchTerm, setSearchTerm ] = React.useState(getQueryParamString(router.query.q) || undefined);
|
|
const [ type, setType ] = React.useState(getQueryParamString(router.query.filter) as VerifiedContractsFilters['filter'] || undefined);
|
|
const [ sort, setSort ] =
|
|
React.useState<VerifiedContractsSortingValue>(getSortValueFromQuery<VerifiedContractsSortingValue>(router.query, SORT_OPTIONS) ?? 'default');
|
|
|
|
const debouncedSearchTerm = useDebounce(searchTerm || '', 300);
|
|
|
|
const query = useQueryWithPages({
|
|
resourceName: 'general:verified_contracts',
|
|
filters: { q: debouncedSearchTerm, filter: type },
|
|
sorting: getSortParamsFromValue<VerifiedContractsSortingValue, VerifiedContractsSortingField, VerifiedContractsSorting['order']>(sort),
|
|
options: {
|
|
placeholderData: generateListStub<'general:verified_contracts'>(
|
|
VERIFIED_CONTRACT_INFO,
|
|
50,
|
|
{
|
|
next_page_params: {
|
|
items_count: '50',
|
|
smart_contract_id: '50',
|
|
},
|
|
},
|
|
),
|
|
},
|
|
isMultichain,
|
|
});
|
|
const { onFilterChange, onSortingChange } = query;
|
|
|
|
const onSearchTermChange = React.useCallback((value: string) => {
|
|
onFilterChange({ q: value, filter: type });
|
|
setSearchTerm(value);
|
|
}, [ type, onFilterChange ]);
|
|
|
|
const onTypeChange = React.useCallback((value: string | Array<string>) => {
|
|
if (Array.isArray(value)) {
|
|
return;
|
|
}
|
|
|
|
const filter = value === 'all' ? undefined : value as VerifiedContractsFilters['filter'];
|
|
|
|
onFilterChange({ q: debouncedSearchTerm, filter });
|
|
setType(filter);
|
|
}, [ debouncedSearchTerm, onFilterChange ]);
|
|
|
|
const onSortChange = React.useCallback(({ value }: { value: Array<string> }) => {
|
|
setSort(value[0] as VerifiedContractsSortingValue);
|
|
onSortingChange(value[0] === 'default' ? undefined : getSortParamsFromValue(value[0] as VerifiedContractsSortingValue));
|
|
}, [ onSortingChange ]);
|
|
|
|
return React.useMemo(() => ({
|
|
query,
|
|
type,
|
|
searchTerm,
|
|
debouncedSearchTerm,
|
|
sort,
|
|
onSearchTermChange,
|
|
onTypeChange,
|
|
onSortChange,
|
|
}), [ query, type, searchTerm, debouncedSearchTerm, sort, onSearchTermChange, onTypeChange, onSortChange ]);
|
|
}
|