diff --git a/src/hooks/query/useCapacity.ts b/src/hooks/query/useCapacity.ts index 10a3c75..29e828a 100644 --- a/src/hooks/query/useCapacity.ts +++ b/src/hooks/query/useCapacity.ts @@ -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({ queryKey: ['capacity', address], - queryFn: async () => fetch(`/api/capacity/${address}`).then((res) => res.text()), + queryFn: async (): Promise => { + try { + const res = await fetch(`/api/capacity/${address}`); + return await res.text(); + } catch { + return defaultValue ?? void 0; + } + }, enabled: !!address, }); return {