mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* envs and feature setup * home page layout * cross-chain txs page * cross-chain transfers page * cross-chain transfers on tx page * cross-chain messages on tx page * cross-chain tx page * cross-chain tx details token transfers * stats and counters for lists * migrate to new API version * add swagger * mobile lists * placeholder views on address page * tests * fix adaptive tabs initial state when there is only one tab in the list * tweaks * bug fixes * fix tests * update screenshots * migrate to new api version * add chain label tooltip, copy button to txs in lists and same address highlight * list views on address page * fix tests * fix links to current address in the list views * update tooltips * update tables layout * review fixes * fix spelling * update screenshots * update screenshot
66 lines
2.4 KiB
TypeScript
66 lines
2.4 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 { TransactionsSorting, TransactionsSortingField, TransactionsSortingValue } from 'types/api/transaction';
|
|
|
|
import getFilterValueFromQuery from 'lib/getFilterValueFromQuery';
|
|
import { TX } from 'stubs/tx';
|
|
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 'ui/txs/useTxsSort';
|
|
|
|
const getFilterValue = (getFilterValueFromQuery<AddressFromToFilter>).bind(null, AddressFromToFilterValues);
|
|
|
|
interface Props {
|
|
addressHash: string;
|
|
enabled: boolean;
|
|
isMultichain?: boolean;
|
|
chainIds?: Array<string>;
|
|
}
|
|
|
|
export default function useAddressTxsQuery({ addressHash, enabled, isMultichain, chainIds }: Props) {
|
|
const router = useRouter();
|
|
|
|
const [ sort, setSort ] = React.useState<TransactionsSortingValue>(getSortValueFromQuery<TransactionsSortingValue>(router.query, SORT_OPTIONS) || 'default');
|
|
|
|
const initialFilterValue = getFilterValue(router.query.filter);
|
|
const [ filterValue, setFilterValue ] = React.useState<AddressFromToFilter>(initialFilterValue);
|
|
|
|
const query = useQueryWithPages({
|
|
resourceName: 'general:address_txs',
|
|
pathParams: { hash: addressHash },
|
|
filters: { filter: filterValue },
|
|
sorting: getSortParamsFromValue<TransactionsSortingValue, TransactionsSortingField, TransactionsSorting['order']>(sort),
|
|
options: {
|
|
enabled: enabled,
|
|
placeholderData: generateListStub<'general:address_txs'>(TX, 50, { next_page_params: {
|
|
block_number: 9005713,
|
|
index: 5,
|
|
items_count: 50,
|
|
} }),
|
|
},
|
|
isMultichain,
|
|
chainIds,
|
|
});
|
|
|
|
const onFilterChange = React.useCallback((val: string | Array<string>) => {
|
|
const newVal = getFilterValue(val);
|
|
setFilterValue(newVal);
|
|
query.onFilterChange({ filter: newVal });
|
|
}, [ query ]);
|
|
|
|
return React.useMemo(() => ({
|
|
query,
|
|
filterValue,
|
|
setFilterValue,
|
|
initialFilterValue,
|
|
onFilterChange,
|
|
sort,
|
|
setSort,
|
|
}), [ query, filterValue, initialFilterValue, setFilterValue, onFilterChange, sort, setSort ]);
|
|
}
|