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

Add graceful error handling for failed route quotes #2537

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
26 changes: 20 additions & 6 deletions wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,36 @@ const SingleRoute = (props: Props) => {
}, [quote]);

const routeCardHeader = useMemo(() => {
return typeof receiveAmount === 'undefined' ? (
<CircularProgress size={18} />
) : (
if (props.error) {
return <Typography color="error">Route is unavailable</Typography>;
}

if (props.isFetchingQuote) {
return <CircularProgress size={18} />;
}

if (receiveAmount === undefined) {
return null;
}

return (
<Typography>
{receiveAmount} {destTokenConfig.symbol}
</Typography>
);
}, [destToken, receiveAmount]);

const routeCardSubHeader = useMemo(() => {
if (typeof receiveAmount === 'undefined') {
if (props.error || !destChain) {
return null;
}

if (props.isFetchingQuote) {
return <CircularProgress size={18} />;
}

if (!destChain) {
return <></>;
if (receiveAmount === undefined) {
return null;
}

const receiveAmountPrice = calculateUSDPrice(
Expand Down
8 changes: 7 additions & 1 deletion wormhole-connect/src/views/v2/Bridge/Routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,18 @@ const Routes = ({ sortedSupportedRoutes, ...props }: Props) => {
const isSelected = routeConfig.name === props.selectedRoute;
const quoteResult = quotesMap[name];
const quote = quoteResult?.success ? quoteResult : undefined;
// Default message added as precaution, as 'Error' type cannot be trusted
const quoteError =
quoteResult?.success === false
? quoteResult?.error?.message ??
`Error while getting a quote for ${name}.`
: undefined;
return (
<SingleRoute
key={name}
route={routeConfig}
available={available}
error={availabilityError}
error={availabilityError || quoteError}
isSelected={isSelected}
onSelect={props.onRouteChange}
quote={quote}
Expand Down
Loading