Skip to content

Commit 244f3fe

Browse files
authoredSep 9, 2024··
Add graceful error handling for failed route quotes (#2537)
* fix(redesign/quotes): add graceful error handling for failed route quotes. * fix(routes): PR suggestions
1 parent 8461714 commit 244f3fe

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed
 

‎wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx

+20-6
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,36 @@ const SingleRoute = (props: Props) => {
282282
}, [quote]);
283283

284284
const routeCardHeader = useMemo(() => {
285-
return typeof receiveAmount === 'undefined' ? (
286-
<CircularProgress size={18} />
287-
) : (
285+
if (props.error) {
286+
return <Typography color="error">Route is unavailable</Typography>;
287+
}
288+
289+
if (props.isFetchingQuote) {
290+
return <CircularProgress size={18} />;
291+
}
292+
293+
if (receiveAmount === undefined) {
294+
return null;
295+
}
296+
297+
return (
288298
<Typography>
289299
{receiveAmountTrunc} {destTokenConfig.symbol}
290300
</Typography>
291301
);
292302
}, [destToken, receiveAmountTrunc]);
293303

294304
const routeCardSubHeader = useMemo(() => {
295-
if (typeof receiveAmount === 'undefined') {
305+
if (props.error || !destChain) {
306+
return null;
307+
}
308+
309+
if (props.isFetchingQuote) {
296310
return <CircularProgress size={18} />;
297311
}
298312

299-
if (!destChain) {
300-
return <></>;
313+
if (receiveAmount === undefined) {
314+
return null;
301315
}
302316

303317
const receiveAmountPrice = calculateUSDPrice(

‎wormhole-connect/src/views/v2/Bridge/Routes/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,18 @@ const Routes = ({ sortedSupportedRoutes, ...props }: Props) => {
115115
const isSelected = routeConfig.name === props.selectedRoute;
116116
const quoteResult = quotesMap[name];
117117
const quote = quoteResult?.success ? quoteResult : undefined;
118+
// Default message added as precaution, as 'Error' type cannot be trusted
119+
const quoteError =
120+
quoteResult?.success === false
121+
? quoteResult?.error?.message ??
122+
`Error while getting a quote for ${name}.`
123+
: undefined;
118124
return (
119125
<SingleRoute
120126
key={name}
121127
route={routeConfig}
122128
available={available}
123-
error={availabilityError}
129+
error={availabilityError || quoteError}
124130
isSelected={isSelected}
125131
onSelect={props.onRouteChange}
126132
quote={quote}

0 commit comments

Comments
 (0)
Please sign in to comment.