Skip to content

Commit

Permalink
fix: the capacity api sometimes throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
ShookLyngs committed Jan 19, 2024
1 parent fcd20da commit 0138436
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/hooks/query/useCapacity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { useQuery } from '@tanstack/react-query';
import { HexNumber } from '@ckb-lumos/base';

export function useCapacity(address: string) {
const { data, isLoading } = useQuery({
export function useCapacity(address: string, defaultValue?: HexNumber) {
const { data, isLoading } = useQuery<HexNumber | undefined>({
queryKey: ['capacity', address],
queryFn: async () => fetch(`/api/capacity/${address}`).then((res) => res.text()),
queryFn: async (): Promise<string | undefined> => {
try {
const res = await fetch(`/api/capacity/${address}`);
return await res.text();
} catch {
return defaultValue ?? void 0;
}
},
enabled: !!address,
});
return {
Expand Down

0 comments on commit 0138436

Please sign in to comment.