Skip to content

Commit

Permalink
Add disabling SwapPageFooter when route is error
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao committed Sep 19, 2024
1 parent cb3e003 commit 8e6a249
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/widget-v2/src/pages/SwapPage/SwapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export const SwapPage = () => {
{swapButton}
<SwapPageFooter
showRouteInfo
disabled={isRouteError}
onClick={() =>
swapDetailsModal.show({
drawer: true,
Expand Down
32 changes: 27 additions & 5 deletions packages/widget-v2/src/pages/SwapPage/SwapPageFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,33 @@ export const SwapPageFooterItems = ({
showRouteInfo,
}: SwapPageFooterItemsProps) => {
const { data: route, isLoading } = useAtomValue(skipRouteAtom);
const estimatedTime = convertSecondsToMinutesOrHours(route?.estimatedRouteDurationSeconds);
const estimatedTime = convertSecondsToMinutesOrHours(
route?.estimatedRouteDurationSeconds
);

const renderRightContent = useMemo(() => {
if (showRouteInfo && route) {
return (
<Row align="center" gap={8}>
<Row gap={4} align="center">
{isLoading ? <SkeletonElement width={40} height={16} /> : <><SignatureIcon />{route?.txsRequired} tx required</>}
{isLoading ? (
<SkeletonElement width={40} height={16} />
) : (
<>
<SignatureIcon />
{route?.txsRequired} tx required
</>
)}
</Row>
<Row gap={4} align="center">
{isLoading ? <SkeletonElement width={80} height={16} /> : estimatedTime ? <><SpeedometerIcon />{estimatedTime}</> : null}
{isLoading ? (
<SkeletonElement width={80} height={16} />
) : estimatedTime ? (
<>
<SpeedometerIcon />
{estimatedTime}
</>
) : null}
</Row>
</Row>
);
Expand All @@ -49,18 +65,24 @@ export const SwapPageFooterItems = ({

export const SwapPageFooter = ({
onClick,
rightContent,
showRouteInfo,
...props
}: {
onClick?: () => void;
} & SwapPageFooterItemsProps) => {
} & SwapPageFooterItemsProps & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
return (
<GhostButton
gap={5}
align="center"
justify="space-between"
onClick={onClick}
{...props}
>
<SwapPageFooterItems {...props} />
<SwapPageFooterItems
rightContent={rightContent}
showRouteInfo={showRouteInfo}
/>
</GhostButton>
);
};
2 changes: 1 addition & 1 deletion packages/widget-v2/src/pages/SwapPage/useSetMaxAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ export const useSetMaxAmount = () => {
setSourceAssetAmount(maxAmountMinusGasFees);
}
};
};
};
2 changes: 1 addition & 1 deletion packages/widget-v2/src/pages/SwapPage/useSourceBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const useSourceBalance = () => {
if (!denom || !chainID) return;

return skipBalances?.chains?.[chainID]?.denoms?.[denom];
};
};

0 comments on commit 8e6a249

Please sign in to comment.