Skip to content

Commit

Permalink
remove limit orders
Browse files Browse the repository at this point in the history
  • Loading branch information
pingustar committed Nov 20, 2023
1 parent 5580a44 commit cd385c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 102 deletions.
27 changes: 2 additions & 25 deletions src/elements/swapHeader/SwapHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
import { classNameGenerator } from 'utils/pureFunctions';
import 'elements/swapHeader/SwapHeader.css';
import { SwapSwitch } from 'elements/swapSwitch/SwapSwitch';
import { PopoverV3 } from 'components/popover/PopoverV3';
import { ReactComponent as IconSettings } from 'assets/icons/settings.svg';
import { SlippageSettings } from 'elements/settings/SlippageSettings';

interface SwapHeaderProps {
isLimit: boolean;
setIsLimit: Function;
}

export const SwapHeader = ({ isLimit, setIsLimit }: SwapHeaderProps) => {
const marketActive = classNameGenerator({
'swap-header-active': !isLimit,
});

const limitActive = classNameGenerator({
'swap-header-active': isLimit,
});

export const SwapHeader = () => {
return (
<div>
<div className="swap-header">
<div>
<button
className={`${marketActive}`}
onClick={() => setIsLimit(false)}
>
Market
</button>
<span className="border-r b-silver mx-12" />
<button className={limitActive} onClick={() => setIsLimit(true)}>
Limit
</button>
<span className={'swap-header-active'}>Market</span>
</div>

<div className={'flex items-center space-x-20'}>
Expand Down
77 changes: 8 additions & 69 deletions src/elements/swapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
import { useCallback, useEffect, useState } from 'react';
import { SwapHeader } from 'elements/swapHeader/SwapHeader';
import { SwapLimit } from 'elements/swapLimit/SwapLimit';
import { TokenMinimal } from 'services/observables/tokens';
import { useAppSelector } from 'store';
import { ethToken } from 'services/web3/config';
import { Insight } from 'elements/swapInsights/Insight';
import { IntoTheBlock, intoTheBlockByToken } from 'services/api/intoTheBlock';
import { useAsyncEffect } from 'use-async-effect';
import { useNavigation } from 'hooks/useNavigation';
import { TradeWidget } from 'elements/trade/TradeWidget';
import { getTradeTokensWithExternal } from 'store/bancor/bancor';

interface SwapWidgetProps {
isLimit: boolean;
setIsLimit: Function;
from: string | null;
to: string | null;
limit: string | null;
refreshLimit: Function;
}

export const SwapWidget = ({
isLimit,
setIsLimit,
from,
to,
limit,
refreshLimit,
}: SwapWidgetProps) => {
export const SwapWidget = ({ from, to, limit }: SwapWidgetProps) => {
const tokens = useAppSelector<TokenMinimal[]>(getTradeTokensWithExternal);

const ethOrFirst = useCallback(() => {
Expand All @@ -54,10 +42,8 @@ export const SwapWidget = ({
if (toToken) setToToken(toToken);
else setToToken(undefined);
} else setToToken(undefined);

setIsLimit(limit);
}
}, [from, to, limit, tokens, setIsLimit, ethOrFirst]);
}, [from, to, limit, tokens, ethOrFirst]);

useAsyncEffect(
async (isMounted) => {
Expand All @@ -83,66 +69,19 @@ export const SwapWidget = ({
[toToken]
);

const { goToPage } = useNavigation();

return (
<div className="2xl:space-x-20 flex justify-center mx-auto">
<div className="flex justify-center w-full md:w-auto mx-auto space-x-30">
<div className="w-full md:w-auto">
<div className="widget md:min-w-[485px] rounded-40">
<SwapHeader
isLimit={isLimit}
setIsLimit={(limit: boolean) =>
goToPage.trade({
from: fromToken?.address,
to: toToken?.address,
limit,
})
}
/>
<SwapHeader />
<hr className="widget-separator" />
{isLimit ? (
<SwapLimit
fromToken={fromToken}
setFromToken={(from: TokenMinimal) =>
goToPage.trade({
from: from.address,
to: toToken?.address,
limit: true,
})
}
toToken={toToken}
setToToken={(to: TokenMinimal) =>
goToPage.trade({
from: fromToken?.address,
to: to.address,
limit: true,
})
}
switchTokens={() =>
goToPage.trade({
from: toToken?.address,
to: fromToken?.address,
limit: true,
})
}
refreshLimit={refreshLimit}
/>
) : (
<TradeWidget
tokens={tokens}
from={fromToken?.address}
to={toToken?.address}
/>
)}
<TradeWidget
tokens={tokens}
from={fromToken?.address}
to={toToken?.address}
/>
</div>
{isLimit ? (
<div className="text-center text-10 text-grey mt-18">
Limit orders are powered by Rook
</div>
) : (
''
)}
</div>
<Insight
fromToken={fromToken}
Expand Down
8 changes: 0 additions & 8 deletions src/pages/Swap.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { SwapWidget } from 'elements/swapWidget/SwapWidget';
import { useState } from 'react';
import { useSwapLimitTable } from 'elements/swapLimit/SwapLimitTable';
import { useQuery } from 'hooks/useQuery';

export const Swap = () => {
const [isLimit, setIsLimit] = useState(false);
const [SwapLimitTable, refreshLimit] = useSwapLimitTable();
const query = useQuery();

return (
<div className="pt-[120px] px-10">
<SwapWidget
isLimit={isLimit}
setIsLimit={setIsLimit}
from={query.get('from')}
to={query.get('to')}
limit={query.get('limit')}
refreshLimit={refreshLimit}
/>
{isLimit && SwapLimitTable ? SwapLimitTable : ''}
</div>
);
};

0 comments on commit cd385c1

Please sign in to comment.