diff --git a/.changeset/sixty-adults-provide.md b/.changeset/sixty-adults-provide.md new file mode 100644 index 00000000..60b242ab --- /dev/null +++ b/.changeset/sixty-adults-provide.md @@ -0,0 +1,5 @@ +--- +'@reservoir0x/relay-kit-hooks': patch +--- + +Fix usePrice error handling diff --git a/packages/hooks/src/hooks/usePrice.ts b/packages/hooks/src/hooks/usePrice.ts index 6d21abe6..82945ca5 100644 --- a/packages/hooks/src/hooks/usePrice.ts +++ b/packages/hooks/src/hooks/usePrice.ts @@ -59,14 +59,20 @@ export default function usePrice( const response = (useQuery as QueryType)({ queryKey: ['usePrice', options], queryFn: () => { - if (options && client?.source && !options.referrer) { - options.referrer = client.source - } - const promise = queryPrice(client?.baseApiUrl, options) - promise.then((response: any) => { - onResponse?.(response) + return new Promise((resolve, reject) => { + if (options && client?.source && !options.referrer) { + options.referrer = client.source + } + const promise = queryPrice(client?.baseApiUrl, options) + promise + .then((response: any) => { + resolve(response) + onResponse?.(response) + }) + .catch((e) => { + reject(e) + }) }) - return promise }, enabled: client !== undefined && options !== undefined, retry: false,