Skip to content

Commit

Permalink
widget v2: invert swap logic
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Sep 2, 2024
1 parent a81fb70 commit 67249e8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/widget-v2/src/components/MainButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const LoadingButton = ({

const StyledMainButton = styled(Row).attrs({
as: "button",
})<{ backgroundColor?: string; disabled?: boolean; loading?: boolean }>`
}) <{ backgroundColor?: string; disabled?: boolean; loading?: boolean }>`
position: relative;
border: none;
background-color: ${({ theme, backgroundColor }) =>
Expand Down Expand Up @@ -168,7 +168,7 @@ const StyledTimeRemaining = styled(Row)`
border-radius: 10px;
`;

const StyledOverlay = styled(Row)<{ backgroundColor?: string }>`
const StyledOverlay = styled(Row) <{ backgroundColor?: string }>`
position: absolute;
height: 66px;
width: 476px;
Expand Down
10 changes: 5 additions & 5 deletions packages/widget-v2/src/pages/SwapPage/SwapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const SwapPage = () => {
const [drawerOpen, setDrawerOpen] = useState(false);
const [sourceAsset, setSourceAsset] = useAtom(sourceAssetAtom);
const [destinationAsset, setDestinationAsset] = useAtom(destinationAssetAtom);
const setSwapDirection = useSetAtom(swapDirectionAtom)
const [{ data: assets }] = useAtom(skipAssetsAtom);
const [{ data: chains }] = useAtom(skipChainsAtom);
const setSwapDirection = useSetAtom(swapDirectionAtom);
const { isLoading: isRouteLoading } = useAtomValue(skipRouteAtom);
const [{ data: chains }] = useAtom(skipChainsAtom);;
const { isLoading: isRouteLoading, isError: isRouteError, error: routeError } = useAtomValue(skipRouteAtom);
const swapFlowSettings = useModal(SwapPageSettings);
const tokenAndChainSelectorFlow = useModal(TokenAndChainSelectorModal);

Expand Down Expand Up @@ -168,9 +168,9 @@ export const SwapPage = () => {
}}
/>
</Column>
{!isRouteLoading && <MainButton label="Connect Wallet" icon={ICONS.plus} />}
{!isRouteLoading && !isRouteError && <MainButton label="Connect Wallet" icon={ICONS.plus} />}
{isRouteLoading && <MainButton label="Finding Best Route..." loading={true} />}

{isRouteError && !isRouteLoading && <MainButton label={routeError.message} disabled={true} />}
<SwapPageFooter
showRouteInfo
onClick={() =>
Expand Down
13 changes: 12 additions & 1 deletion packages/widget-v2/src/pages/SwapPage/SwapPageBridge.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { useTheme, styled } from "styled-components";
import { BridgeArrowIcon } from "@/icons/BridgeArrowIcon";
import { BridgeIcon } from "@/icons/BridgeIcon";
import { destinationAssetAtom, sourceAssetAtom, swapDirectionAtom } from "@/state/swapPage";
import { useAtom, useSetAtom } from "jotai";

export const SwapPageBridge = () => {
const theme = useTheme();
const [sourceAsset, setSourceAsset] = useAtom(sourceAssetAtom);
const [destinationAsset, setDestinationAsset] = useAtom(destinationAssetAtom);
const setSwapDirection = useSetAtom(swapDirectionAtom)
const onInvertSwap = () => {
setSwapDirection("swap-out");
setSourceAsset(destinationAsset);
setDestinationAsset(sourceAsset);
}

return (
<div style={{ position: "relative" }}>
<div style={{ position: "relative", cursor: "pointer" }} onClick={onInvertSwap}>
<BridgeIcon color={theme.primary.background.normal} />
<StyledBridgeArrow color={theme.primary.text.normal} />
</div>
Expand Down
15 changes: 0 additions & 15 deletions packages/widget-v2/src/pages/SwapPage/swapPageState.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/widget-v2/src/state/skipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ export const skipRouteAtom = atomWithQuery((get) => {
allowUnsafe: true,
});
},
enabled: !!params,
refetchInterval: 1000 * 10,
retry: 1,
enabled: !!params && ((Number(params.amountIn) > 0) || (Number(params.amountOut) > 0)),
refetchInterval: 1000 * 30,
};
});

Expand Down

0 comments on commit 67249e8

Please sign in to comment.