Skip to content

Commit

Permalink
enable best trade in zkevm and fix some UI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
totop716 committed Jul 31, 2023
1 parent 68d6f0b commit 7115a8a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/components/ConfirmSwapModal/SwapModalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { AlertTriangle } from 'react-feather';
import { Box, Button } from '@material-ui/core';
import { Field } from 'state/swap/actions';
import { DoubleCurrencyLogo } from 'components';
import useUSDCPrice from 'utils/useUSDCPrice';
import { useUSDCPriceFromAddress } from 'utils/useUSDCPrice';
import { computeSlippageAdjustedAmounts } from 'utils/prices';
import { ReactComponent as ArrowDownIcon } from 'assets/images/ArrowDownIcon.svg';
import { basisPointsToPercent, formatTokenAmount } from 'utils';
import { useTranslation } from 'react-i18next';
import { OptimalRate, SwapSide } from '@paraswap/sdk';
import { ONE } from 'v3lib/utils';
import { wrappedCurrency } from 'utils/wrappedCurrency';
import { useActiveWeb3React } from 'hooks';

interface SwapModalHeaderProps {
trade?: Trade;
Expand All @@ -34,13 +36,16 @@ const SwapModalHeader: React.FC<SwapModalHeaderProps> = ({
onConfirm,
}) => {
const { t } = useTranslation();
const { chainId } = useActiveWeb3React();
const slippageAdjustedAmounts = useMemo(
() => computeSlippageAdjustedAmounts(trade, allowedSlippage),
[trade, allowedSlippage],
);
const usdPrice = useUSDCPrice(
const wrappedToken = wrappedCurrency(
trade ? trade.inputAmount.currency : inputCurrency,
chainId,
);
const usdPrice = useUSDCPriceFromAddress(wrappedToken?.address ?? '');

const pct = basisPointsToPercent(allowedSlippage);

Expand Down Expand Up @@ -75,7 +80,7 @@ const SwapModalHeader: React.FC<SwapModalHeaderProps> = ({
: ''}{' '}
{trade ? trade.inputAmount.currency.symbol : inputCurrency?.symbol} ($
{(
Number(usdPrice?.toSignificant()) *
(usdPrice ?? 0) *
(optimalRate
? Number(optimalRate.srcAmount) / 10 ** optimalRate.srcDecimals
: trade
Expand Down
5 changes: 1 addition & 4 deletions src/components/v3/CurrencyInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ export default function CurrencyInputPanel({
currency?.isNative ? nativeCurrency : currency ?? undefined,
);

const currentPrice = useUSDCPriceFromAddress(
currency?.wrapped.address ?? '',
true,
);
const currentPrice = useUSDCPriceFromAddress(currency?.wrapped.address ?? '');

const valueAsUsd = useMemo(() => {
if (!currentPrice || !value) {
Expand Down
2 changes: 1 addition & 1 deletion src/config/zkmainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"swap": {
"available": true,
"bestTrade": false,
"bestTrade": true,
"proMode": false,
"limitOrder": false,
"crossChain": false
Expand Down
2 changes: 0 additions & 2 deletions src/utils/useUSDCPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import { PairState, usePairs, usePair } from 'data/Reserves';
import { useActiveWeb3React } from 'hooks';
import { unwrappedToken, wrappedCurrency } from './wrappedCurrency';
import { useDQUICKtoQUICK } from 'state/stake/hooks';
import { GlobalValue } from 'constants/index';
import { useAllCommonPairs } from 'hooks/Trades';
import { tryParseAmount } from 'state/swap/hooks';
import { useEthPrice, useMaticPrice } from 'state/application/hooks';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import weekOfYear from 'dayjs/plugin/weekOfYear';
Expand Down

0 comments on commit 7115a8a

Please sign in to comment.