Skip to content

Commit

Permalink
feat: create swap modal (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
honeymaro authored Mar 12, 2024
1 parent e6a281b commit d2e1885
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
47 changes: 47 additions & 0 deletions src/components/Modal/SwapModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import ReactModal from "react-modal";
import { useScreenClass } from "react-grid-system";
import { useNavigate } from "react-router-dom";
import SwapPage from "pages/Trade/Swap";
import IconButton from "components/IconButton";
import { MOBILE_SCREEN_CLASS } from "constants/layout";
import useSettingsModal from "hooks/modals/useSettingsModal";
import Modal from "components/Modal";

import iconSetting from "assets/icons/icon-setting.svg";
import iconSettingHover from "assets/icons/icon-setting-hover.svg";

function SwapModal(props: ReactModal.Props) {
const navigate = useNavigate();
const screenClass = useScreenClass();
const settingsModal = useSettingsModal();

const {
onRequestClose = () => {
navigate("..", { replace: true, relative: "route" });
},
...modalProps
} = props;

return (
<Modal
id="swap-modal"
className="modal-parent"
title="Swap"
hasCloseButton
drawer={screenClass === MOBILE_SCREEN_CLASS}
onRequestClose={onRequestClose}
headerExtra={
<IconButton
size={38}
icons={{ default: iconSetting, hover: iconSettingHover }}
onClick={() => settingsModal.open()}
/>
}
{...modalProps}
>
<SwapPage />
</Modal>
);
}

export default SwapModal;
11 changes: 6 additions & 5 deletions src/pages/Tokens/TokenDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Visible,
useScreenClass,
} from "react-grid-system";
import { Link, useNavigate, useParams } from "react-router-dom";
import { Link, Outlet, useNavigate, useParams } from "react-router-dom";

import iconBookmark from "assets/icons/icon-bookmark-default.svg";
import iconBookmarkSelected from "assets/icons/icon-bookmark-selected.svg";
Expand Down Expand Up @@ -124,12 +124,12 @@ function TokenDetailPage() {
)}
</Col>
<Col xs={6}>
{tokenAddress && (
{asset?.token && (
<Link
to={{
pathname: "/trade/swap",
pathname: "swap",
search: new URLSearchParams({
q: tokenAddress,
q: asset.token,
}).toString(),
}}
>
Expand All @@ -141,7 +141,7 @@ function TokenDetailPage() {
</Col>
</Row>
),
[asset, tokenAddress],
[asset],
);

return (
Expand Down Expand Up @@ -352,6 +352,7 @@ function TokenDetailPage() {
/>
{tokenAddress && <TokenTransactions tokenAddress={tokenAddress} />}
</Container>
<Outlet />
</Wrapper>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Wallet/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function Assets() {
{typeof row.token === "string" && (
<Link
to={{
pathname: "/trade/swap",
pathname: "swap",
search: new URLSearchParams({
q: row.token,
}).toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Wallet/MobileAssetItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function MobileAssetItem({
<div>
<Link
to={{
pathname: "/trade/swap",
pathname: "swap",
search: new URLSearchParams({
q: asset.token,
}).toString(),
Expand Down
3 changes: 3 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import TokenDetailPage from "pages/Tokens/TokenDetail";
import PoolDetailPage from "pages/Earn/Pools/PoolDetail";
import MainLayout from "layout/Main";
import withDisclaimerAgreement from "hocs/withDisclaimerAgreement";
import SwapPageAsModal from "components/Modal/SwapModal";
// TODO: uncomment when lockdrop is ready
// import LockdropPage from "pages/Earn/Lockdrop";
// import StakePage from "pages/Earn/Lockdrop/Stake";
Expand Down Expand Up @@ -56,13 +57,15 @@ const routes = createBrowserRouter([
{
path: "tokens/:tokenAddress",
element: <TokenDetailPage />,
children: [{ path: "swap", element: <SwapPageAsModal isOpen /> }],
},
{
path: "wallet",
element: <WalletPage />,
children: [
{ path: ":poolAddress/add", element: <ProvidePage /> },
{ path: ":poolAddress/remove", element: <WithdrawPage /> },
{ path: "swap", element: <SwapPageAsModal isOpen /> },
],
},
{
Expand Down

0 comments on commit d2e1885

Please sign in to comment.