Skip to content

Commit

Permalink
Merge pull request #355 from reservoirprotocol/pedro/relay-6257-mute-…
Browse files Browse the repository at this point in the history
…external-liquidity-check-http-error

Handle unhandled http errors in usePrice
  • Loading branch information
ted-palmer authored Nov 7, 2024
2 parents 8736eeb + 1c68705 commit cff551c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-adults-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-hooks': patch
---

Fix usePrice error handling
20 changes: 13 additions & 7 deletions packages/hooks/src/hooks/usePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cff551c

Please sign in to comment.