sui-explorer-local
Version:
Local Sui Explorer
30 lines (26 loc) • 845 B
text/typescript
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { useSuiClient } from '@mysten/dapp-kit';
import { PaginatedCoins } from '@mysten/sui.js/client';
import { useInfiniteQuery } from '@tanstack/react-query';
const MAX_COINS_PER_REQUEST = 10;
export function useGetCoins(
coinType: string,
address?: string | null,
maxCoinsPerRequest = MAX_COINS_PER_REQUEST,
) {
const client = useSuiClient();
return useInfiniteQuery<PaginatedCoins>({
queryKey: ['get-coins', address, coinType, maxCoinsPerRequest],
initialPageParam: null,
getNextPageParam: ({ hasNextPage, nextCursor }) => (hasNextPage ? nextCursor : null),
queryFn: ({ pageParam }) =>
client.getCoins({
owner: address!,
coinType,
cursor: pageParam as string | null,
limit: maxCoinsPerRequest,
}),
enabled: !!address,
});
}