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
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import type { AddressFromToFilter } from 'types/api/address';
|
|
import { AddressFromToFilterValues } from 'types/api/address';
|
|
import type { TokenType } from 'types/api/token';
|
|
|
|
import getFilterValueFromQuery from 'lib/getFilterValueFromQuery';
|
|
import getFilterValuesFromQuery from 'lib/getFilterValuesFromQuery';
|
|
import { TOKEN_TYPE_IDS } from 'lib/token/tokenTypes';
|
|
import { getTokenTransfersStub } from 'stubs/token';
|
|
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages';
|
|
|
|
export type Filters = {
|
|
type: Array<TokenType>;
|
|
filter: AddressFromToFilter | undefined;
|
|
};
|
|
|
|
const getTokenFilterValue = (getFilterValuesFromQuery<TokenType>).bind(null, TOKEN_TYPE_IDS);
|
|
const getAddressFilterValue = (getFilterValueFromQuery<AddressFromToFilter>).bind(null, AddressFromToFilterValues);
|
|
|
|
interface Props {
|
|
currentAddress: string;
|
|
enabled?: boolean;
|
|
isMultichain?: boolean;
|
|
}
|
|
|
|
export default function useAddressTokenTransfersQuery({ currentAddress, enabled, isMultichain }: Props) {
|
|
const router = useRouter();
|
|
|
|
const [ filters, setFilters ] = React.useState<Filters>(
|
|
{
|
|
type: getTokenFilterValue(router.query.type) || [],
|
|
filter: getAddressFilterValue(router.query.filter),
|
|
},
|
|
);
|
|
|
|
const query = useQueryWithPages({
|
|
resourceName: 'general:address_token_transfers',
|
|
pathParams: { hash: currentAddress },
|
|
filters,
|
|
options: {
|
|
enabled,
|
|
placeholderData: getTokenTransfersStub(undefined, {
|
|
block_number: 7793535,
|
|
index: 46,
|
|
items_count: 50,
|
|
}),
|
|
},
|
|
isMultichain,
|
|
});
|
|
|
|
const onTypeFilterChange = React.useCallback((nextValue: Array<TokenType>) => {
|
|
query.onFilterChange({ ...filters, type: nextValue });
|
|
setFilters((prevState) => ({ ...prevState, type: nextValue }));
|
|
}, [ filters, query ]);
|
|
|
|
const onAddressFilterChange = React.useCallback((nextValue: string) => {
|
|
const filterVal = getAddressFilterValue(nextValue);
|
|
query.onFilterChange({ ...filters, filter: filterVal });
|
|
setFilters((prevState) => ({ ...prevState, filter: filterVal }));
|
|
}, [ filters, query ]);
|
|
|
|
return React.useMemo(() => ({
|
|
query,
|
|
filters,
|
|
onTypeFilterChange,
|
|
onAddressFilterChange,
|
|
}), [ query, filters, onTypeFilterChange, onAddressFilterChange ]);
|
|
}
|