From 642699f622a5749aeccda117a5dbadfafec8a4b5 Mon Sep 17 00:00:00 2001 From: Nguyen Van Viet Date: Wed, 2 Aug 2023 15:49:55 +0700 Subject: [PATCH] fix: lp collect fee (#2132) * fix: lp collect fee * feat: add disclaimer erc 20 * fix: add liqudity native symbol --- src/components/ProAmm/ListPositions.tsx | 26 +++++---- src/pages/AddLiquidity/TokenPair.tsx | 5 ++ .../components/DisclaimerERC20.tsx | 33 +++++++++++ src/pages/AddLiquidityV2/index.tsx | 13 +++-- src/pages/CreatePool/index.tsx | 3 + .../ElasticPools/SinglePool/index.tsx | 21 +++++-- .../SinglePosition/PositionView.tsx | 2 +- src/pages/Pool/DeprecationBanner.tsx | 57 ------------------- src/pages/Pool/index.tsx | 6 +- src/services/earning/index.ts | 2 + src/services/earning/types.ts | 3 + 11 files changed, 88 insertions(+), 83 deletions(-) create mode 100644 src/pages/AddLiquidityV2/components/DisclaimerERC20.tsx delete mode 100644 src/pages/Pool/DeprecationBanner.tsx diff --git a/src/components/ProAmm/ListPositions.tsx b/src/components/ProAmm/ListPositions.tsx index 77f4f2a583..11d89b89cc 100644 --- a/src/components/ProAmm/ListPositions.tsx +++ b/src/components/ProAmm/ListPositions.tsx @@ -15,6 +15,7 @@ import { MEDIA_WIDTHS } from 'theme' import { formattedNum } from 'utils' import { formatTickPrice } from 'utils/formatTickPrice' import { getTickToPrice } from 'utils/getTickToPrice' +import { unwrappedToken } from 'utils/wrappedCurrency' import PriceVisualizeAlignCurrent from './PriceVisualizeAlignCurrent' @@ -106,6 +107,9 @@ const PositionListItem = ({ const priceUpper = getTickToPrice(tokenA, tokenB, position.tickUpper) const formattedLowerPrice = formatTickPrice(priceLower, ticksAtLimit, Bound.LOWER) const formattedUpperPrice = formatTickPrice(priceUpper, ticksAtLimit, Bound.UPPER) + + const currency0 = unwrappedToken(position.amount0.currency) + const currency1 = unwrappedToken(position.amount1.currency) if (!priceLower || !priceUpper) return null return ( @@ -120,17 +124,17 @@ const PositionListItem = ({ <> - + - {position.amount0.toSignificant(4)} {position.amount0.currency.symbol} + {position.amount0.toSignificant(4)} {currency0.symbol} - + - {position.amount1.toSignificant(4)} {position.amount1.currency.symbol} + {position.amount1.toSignificant(4)} {currency1.symbol} @@ -159,18 +163,18 @@ const PositionListItem = ({ {/* {position.amount0.currency.symbol} */} - + - {position.amount0.toSignificant(4)} {position.amount0.currency.symbol} + {position.amount0.toSignificant(4)} {currency0.symbol} {/* {position.amount1.currency.symbol} */} - + - {position.amount1.toSignificant(4)} {position.amount1.currency.symbol} + {position.amount1.toSignificant(4)} {currency1.symbol} @@ -225,11 +229,11 @@ const ChartPositions = ({ {upToSmall ? null : ( <> - {positions[0].amount0.currency.symbol} + {unwrappedToken(positions[0].amount0.currency).symbol} - {positions[0].amount1.currency.symbol} + {unwrappedToken(positions[0].amount1.currency).symbol} )} @@ -239,7 +243,7 @@ const ChartPositions = ({ PRICE RANGE{' '} - ({tokenB.symbol} per {tokenA.symbol}) + ({unwrappedToken(tokenB).symbol} per {unwrappedToken(tokenA).symbol}) diff --git a/src/pages/AddLiquidity/TokenPair.tsx b/src/pages/AddLiquidity/TokenPair.tsx index c65034dc16..0862bdafd8 100644 --- a/src/pages/AddLiquidity/TokenPair.tsx +++ b/src/pages/AddLiquidity/TokenPair.tsx @@ -32,6 +32,7 @@ import { useCurrency } from 'hooks/Tokens' import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' import useTheme from 'hooks/useTheme' import useTransactionDeadline from 'hooks/useTransactionDeadline' +import DisclaimerERC20 from 'pages/AddLiquidityV2/components/DisclaimerERC20' import { Dots, Wrapper } from 'pages/Pool/styleds' import { useWalletModalToggle } from 'state/application/hooks' import { Field } from 'state/mint/actions' @@ -670,6 +671,10 @@ const TokenPair = ({ )} + + +
+ {!account ? ( Connect Wallet diff --git a/src/pages/AddLiquidityV2/components/DisclaimerERC20.tsx b/src/pages/AddLiquidityV2/components/DisclaimerERC20.tsx new file mode 100644 index 0000000000..6b9d8e80cf --- /dev/null +++ b/src/pages/AddLiquidityV2/components/DisclaimerERC20.tsx @@ -0,0 +1,33 @@ +import { Trans } from '@lingui/macro' +import { AlertTriangle } from 'react-feather' +import { Flex, Text } from 'rebass' + +import { WarningCard } from 'components/Card' +import useTheme from 'hooks/useTheme' +import { ExternalLink } from 'theme' + +export default function DisclaimerERC20({ href }: { href?: string }) { + const theme = useTheme() + return ( + + + + + + Disclaimer: KyberSwap is a permissionless protocol optimized for the standard ERC20 implementation only. + Please do your own research before you provide liquidity using tokens with unique mechanics (e.g. FOT, + Rebase, LP tokens, contract deposits, etc.). More info{' '} + + here + + + + + + ) +} diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index c477211a40..4c50d73999 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -91,6 +91,7 @@ import { formatNotDollarAmount } from 'utils/numbers' import { SLIPPAGE_STATUS, checkRangeSlippage } from 'utils/slippage' import { unwrappedToken } from 'utils/wrappedCurrency' +import DisclaimerERC20 from './components/DisclaimerERC20' import NewPoolNote from './components/NewPoolNote' import { RANGE_LIST, rangeData } from './constants' import { @@ -784,7 +785,7 @@ export default function AddLiquidity() { const [allowedSlippage] = useUserSlippageTolerance() const slippageStatus = checkRangeSlippage(allowedSlippage, false) - const warning = ( + const warnings = ( {noLiquidity && ( @@ -1327,7 +1328,7 @@ export default function AddLiquidity() { showGridListOption={false} bottomContent={() => ( - {warning} + {warnings} {chart}} - {warning && ( + {warnings && ( - {warning} + {warnings} )} + + + + diff --git a/src/pages/CreatePool/index.tsx b/src/pages/CreatePool/index.tsx index 330aa9d778..4e0dba71d7 100644 --- a/src/pages/CreatePool/index.tsx +++ b/src/pages/CreatePool/index.tsx @@ -32,6 +32,7 @@ import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel' import useTheme from 'hooks/useTheme' import useTransactionDeadline from 'hooks/useTransactionDeadline' +import DisclaimerERC20 from 'pages/AddLiquidityV2/components/DisclaimerERC20' import { Dots, Wrapper } from 'pages/Pool/styleds' import { useWalletModalToggle } from 'state/application/hooks' import { Field } from 'state/mint/actions' @@ -734,6 +735,8 @@ export default function CreatePool() { )} + + {!account ? ( Connect Wallet diff --git a/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx b/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx index 3b7d3d19a9..469e318d70 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePool/index.tsx @@ -1,4 +1,4 @@ -import { ChainId } from '@kyberswap/ks-sdk-core' +import { ChainId, Token } from '@kyberswap/ks-sdk-core' import { FeeAmount, Pool, Position } from '@kyberswap/ks-sdk-elastic' import { Trans, t } from '@lingui/macro' import { rgba } from 'polished' @@ -130,7 +130,6 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p const theme = useTheme() const { mixpanelHandler } = useMixpanel() const [isExpanded, setExpanded] = useState(false) - const tokensByChainId = useAppSelector(state => state.lists.mapWhitelistTokens) const tabletView = useMedia(`(max-width: ${WIDTHS[3]}px)`) const mobileView = useMedia(`(max-width: ${WIDTHS[2]}px)`) @@ -146,11 +145,23 @@ const SinglePool: React.FC = ({ poolEarning, chainId, positionEarnings, p return [] } - const currency0 = tokensByChainId[chainId][tokenAddress0] - const currency1 = tokensByChainId[chainId][tokenAddress1] + const currency0 = new Token( + chainId, + poolEarning.token0.id, + +poolEarning.token0.decimals, + poolEarning.token0.symbol, + poolEarning.token0.name, + ) + const currency1 = new Token( + chainId, + poolEarning.token1.id, + +poolEarning.token1.decimals, + poolEarning.token1.symbol, + poolEarning.token0.name, + ) return [currency0, currency1] - }, [chainId, poolEarning.token0.id, poolEarning.token1.id, tokensByChainId]) + }, [chainId, poolEarning]) const pool = useMemo(() => { if (currency0 && currency1) diff --git a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx index 183b8754d4..87d0b21586 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx @@ -256,7 +256,7 @@ const PositionView: React.FC = props => { feeValue0={feeReward0} feeValue1={feeReward1} hasUserDepositedInFarm={positionEarning.owner !== positionEarning.ownerOriginal} - farmAddress={positionEarning.joinedPositions?.[0]?.farmId} + farmAddress={positionEarning.depositedPosition?.farm || positionEarning.joinedPositions?.[0]?.farmId} poolAddress={positionEarning.pool.id} position={position} isLegacy={isLegacyPosition} diff --git a/src/pages/Pool/DeprecationBanner.tsx b/src/pages/Pool/DeprecationBanner.tsx deleted file mode 100644 index c72ca19c40..0000000000 --- a/src/pages/Pool/DeprecationBanner.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Link } from 'react-router-dom' -import { Flex, Text } from 'rebass' - -import { APP_PATHS } from 'constants/index' -import useTheme from 'hooks/useTheme' - -if (Date.now() > new Date('2023-08-12T00:00:00Z').getTime()) { - console.warn('Remove DeprecationBanner') -} - -const DeprecationBanner = () => { - const theme = useTheme() - return ( - - - View your earnings & manage your liquidity positions through your new earnings dashboard! Access this dashboard - anytime from My Earnings under the 'Earn' section. - - - Note: We will deprecate{' '} - - My Pools - {' '} - by Aug 25. - - - ) -} - -export default DeprecationBanner diff --git a/src/pages/Pool/index.tsx b/src/pages/Pool/index.tsx index 89a5475edc..0217f79f5c 100644 --- a/src/pages/Pool/index.tsx +++ b/src/pages/Pool/index.tsx @@ -33,7 +33,6 @@ import useParsedQueryString from 'hooks/useParsedQueryString' import useTheme from 'hooks/useTheme' import { useSyncNetworkParamWithStore } from 'hooks/web3/useSyncNetworkParamWithStore' import ElasticLegacy from 'pages/ElasticLegacy' -import DeprecationBanner from 'pages/Pool/DeprecationBanner' import ProAmmPool from 'pages/ProAmmPool' import { useFarmsData, useTotalApr } from 'state/farms/classic/hooks' import { Farm } from 'state/farms/classic/types' @@ -174,10 +173,7 @@ export default function PoolCombination() { return ( <> - - - - + {tab === VERSION.ELASTIC ? ( ) : tab === VERSION.ELASTIC_LEGACY ? ( diff --git a/src/services/earning/index.ts b/src/services/earning/index.ts index 01466ec56a..d8e77c9d4b 100644 --- a/src/services/earning/index.ts +++ b/src/services/earning/index.ts @@ -34,6 +34,7 @@ const earningApi = createApi({ includeMyFarmApr: true, perPage: 1000, page: 1, + includeHistorical: true, } const [positionsRes, earningRes] = await Promise.all([ @@ -88,6 +89,7 @@ const earningApi = createApi({ includeMyFarmApr: true, perPage: 1000, page: 1, + includeHistorical: true, } const [positionsRes, earningRes] = await Promise.all([ diff --git a/src/services/earning/types.ts b/src/services/earning/types.ts index 4e70be1899..1d3f25eec4 100644 --- a/src/services/earning/types.ts +++ b/src/services/earning/types.ts @@ -70,6 +70,9 @@ export type ElasticPositionEarningWithDetails = { pendingRewardUSD: string myPoolApr?: string myFarmApr?: string + depositedPosition?: { + farm: string + } joinedPositions?: { farmId: string farmingPool: {