Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel quoting when quote errors but price doesn't #326

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-teachers-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Fix parallel quoting when quote returns errror but price does not
13 changes: 9 additions & 4 deletions packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({

const {
data: _priceData,
isLoading: isFetchingPrice,
isLoading: _isFetchingPrice,
error: priceError
} = usePrice(
relayClient ? relayClient : undefined,
Expand All @@ -409,7 +409,11 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
}
)

const { data: _quoteData, error: quoteError } = useQuote(
const {
data: _quoteData,
error: quoteError,
isLoading: isFetchingQuote
} = useQuote(
relayClient ? relayClient : undefined,
wallet,
quoteParameters,
Expand All @@ -427,8 +431,9 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
)

//Here we fetch the price data and quote data in parallel and then merge into one data model
const error = _quoteData ? null : quoteError ?? priceError
const price = _quoteData ?? _priceData
const isFetchingPrice = isFetchingQuote ?? _isFetchingPrice
const error = _quoteData || isFetchingQuote ? null : quoteError ?? priceError
const price = error ? undefined : _quoteData ?? _priceData

useDisconnected(address, () => {
setCustomToAddress(undefined)
Expand Down