Skip to content

Commit

Permalink
Merge branch 'main' of github.com:KyberNetwork/kyberswap-interface in…
Browse files Browse the repository at this point in the history
…to pool-farm-improvement
  • Loading branch information
viet-nv committed Aug 16, 2023
2 parents 8738a01 + 54d2ed6 commit 490bd27
Show file tree
Hide file tree
Showing 79 changed files with 508 additions and 602 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@kybernetwork/oauth2": "1.0.0",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.0.8",
"@kyberswap/ks-sdk-core": "1.0.9",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"@kyberswap/ks-sdk-solana": "^1.0.2",
"@lingui/loader": "~3.14.0",
Expand Down Expand Up @@ -199,7 +199,7 @@
"vite-tsconfig-paths": "^4.0.8"
},
"resolutions": {
"@kyberswap/ks-sdk-core": "1.0.8",
"@kyberswap/ks-sdk-core": "1.0.9",
"react-error-overlay": "6.0.9",
"@lingui/babel-plugin-extract-messages": "3.14.0",
"@lingui/cli": "3.14.0",
Expand Down
Binary file removed src/assets/networks/avax-network.png
Binary file not shown.
Binary file removed src/assets/networks/bsc-network.png
Binary file not shown.
Binary file removed src/assets/networks/bttc.png
Binary file not shown.
Binary file removed src/assets/networks/ethw.png
Binary file not shown.
Binary file removed src/assets/networks/polygon-network.png
Binary file not shown.
Binary file removed src/assets/networks/zksync-network.png
Binary file not shown.
12 changes: 0 additions & 12 deletions src/assets/svg/eth_pow.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/ClassicElasticTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function ClassicElasticTab() {

const showLegacyExplicit = upToMedium ? false : isFarmpage ? shouldShowFarmTab : shouldShowPositionTab

const dontShowLegacy = [ChainId.LINEA_TESTNET, ChainId.LINEA].includes(chainId)
const dontShowLegacy = [ChainId.ZKEVM, ChainId.LINEA].includes(chainId)

const legacyTag = (small?: boolean) => (
<Text
Expand Down
13 changes: 0 additions & 13 deletions src/components/Header/web3/NetworkModal/Networks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChainId, getChainType } from '@kyberswap/ks-sdk-core'
import { Trans } from '@lingui/macro'
import { darken, rgba } from 'polished'
import { stringify } from 'querystring'
import React from 'react'
Expand All @@ -18,13 +17,6 @@ import useTheme from 'hooks/useTheme'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { useIsDarkMode } from 'state/user/hooks'

const NewLabel = styled.span`
font-size: 12px;
color: ${({ theme }) => theme.red};
margin-left: 2px;
margin-top: -10px;
`

const ListItem = styled.div<{ selected?: boolean }>`
width: 100%;
display: flex;
Expand Down Expand Up @@ -197,11 +189,6 @@ const Networks = ({
{name}
</Text>
</Flex>
{key === ChainId.LINEA && (
<NewLabel>
<Trans>New</Trans>
</NewLabel>
)}
{selected && !walletKey && <CircleGreen />}
{walletKey && (
<WalletWrapper>
Expand Down
10 changes: 4 additions & 6 deletions src/components/SwapForm/AddMEVProtectionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { Trans, t } from '@lingui/macro'
import { Connector } from '@web3-react/types'
import { darken } from 'polished'
import { useCallback, useState } from 'react'
import { X } from 'react-feather'
Expand All @@ -14,12 +13,12 @@ import { NotificationType } from 'components/Announcement/type'
import { ButtonEmpty, ButtonOutlined, ButtonPrimary } from 'components/Button'
import Modal from 'components/Modal'
import Row, { RowBetween } from 'components/Row'
import { didUserReject } from 'constants/connectors/utils'
import { Z_INDEXS } from 'constants/styles'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'
import { useNotify } from 'state/application/hooks'
import { ExternalLink, MEDIA_WIDTHS } from 'theme'
import { friendlyError } from 'utils/errorMessage'

const Wrapper = styled.div`
padding: 20px;
Expand Down Expand Up @@ -113,10 +112,9 @@ export default function AddMEVProtectionModal({ isOpen, onClose }: { isOpen: boo
onClose?.()
mixpanelHandler(MIXPANEL_TYPE.MEV_ADD_RESULT, { type: addingOption.name, result: 'success' })
},
(connector: Connector, error: Error) => {
let reason = error?.message || 'Unknown reason'
if (didUserReject(connector, error)) reason = 'User rejected'
mixpanelHandler(MIXPANEL_TYPE.MEV_ADD_RESULT, { type: addingOption.name, result: 'fail', reason })
(error: Error) => {
const message = friendlyError(error)
mixpanelHandler(MIXPANEL_TYPE.MEV_ADD_RESULT, { type: addingOption.name, result: 'fail', reason: message })
},
)
}, [addNewNetwork, notify, onClose, selectedOption, mixpanelHandler])
Expand Down
6 changes: 1 addition & 5 deletions src/components/SwapForm/PriceImpactNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import styled from 'styled-components'

import Row from 'components/Row'
import WarningNote from 'components/WarningNote'
import { useActiveWeb3React } from 'hooks'
import { checkAllowBypassPriceImpactRestriction } from 'utils/priceImpact'
import { checkPriceImpact } from 'utils/prices'

const TextUnderlineColor = styled(Text)`
Expand All @@ -33,11 +31,9 @@ type Props = {
}

const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact }) => {
const { chainId } = useActiveWeb3React()
const priceImpactResult = checkPriceImpact(priceImpact)
const shouldHide = checkAllowBypassPriceImpactRestriction(chainId)

if (typeof priceImpact !== 'number' || shouldHide) {
if (typeof priceImpact !== 'number') {
return null
}

Expand Down
6 changes: 2 additions & 4 deletions src/components/SwapForm/SlippageSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Trans } from '@lingui/macro'
import React, { ReactNode, useState } from 'react'
import { ReactNode, useState } from 'react'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'

import { ReactComponent as DropdownSVG } from 'assets/svg/down.svg'
import SlippageControl from 'components/SlippageControl'
import { MouseoverTooltip, TextDashed } from 'components/Tooltip'
import { useActiveWeb3React } from 'hooks'
import useTheme from 'hooks/useTheme'
import { useSlippageSettingByPage } from 'state/user/hooks'
import { ExternalLink } from 'theme'
Expand All @@ -28,11 +27,10 @@ type Props = {
}
const SlippageSetting = ({ isStablePairSwap, rightComponent, tooltip, isCrossChain }: Props) => {
const theme = useTheme()
const { chainId } = useActiveWeb3React()
const [expanded, setExpanded] = useState(false)

const { setRawSlippage, rawSlippage, isSlippageControlPinned } = useSlippageSettingByPage(isCrossChain)
const defaultRawSlippage = getDefaultSlippage(chainId, isStablePairSwap)
const defaultRawSlippage = getDefaultSlippage(isStablePairSwap)

const isWarningSlippage = checkWarningSlippage(rawSlippage, isStablePairSwap)
if (!isSlippageControlPinned) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import styled from 'styled-components'
import { ButtonPrimary } from 'components/Button'
import { MouseoverTooltip } from 'components/Tooltip'
import { Dots } from 'components/swapv2/styleds'
import { useActiveWeb3React } from 'hooks'
import useTheme from 'hooks/useTheme'
import { useDegenModeManager } from 'state/user/hooks'
import { checkShouldDisableByPriceImpact } from 'utils/priceImpact'
Expand Down Expand Up @@ -50,7 +49,6 @@ export const SwapButtonWithPriceImpact = ({
showTooltipPriceImpact?: boolean
}) => {
const theme = useTheme()
const { chainId } = useActiveWeb3React()
const [isDegenMode] = useDegenModeManager()
const priceImpactResult = checkPriceImpact(priceImpact)

Expand All @@ -74,7 +72,7 @@ export const SwapButtonWithPriceImpact = ({
)
}

const shouldDisableByPriceImpact = checkShouldDisableByPriceImpact(chainId, isDegenMode, priceImpact)
const shouldDisableByPriceImpact = checkShouldDisableByPriceImpact(isDegenMode, priceImpact)
const shouldDisable = !route || !isApproved || shouldDisableByPriceImpact || disabled

if ((priceImpactResult.isVeryHigh || priceImpactResult.isInvalid) && isDegenMode) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/SwapForm/SwapModal/ConfirmSwapModalContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Currency, CurrencyAmount, Price } from '@kyberswap/ks-sdk-core'
import { Trans } from '@lingui/macro'
import { transparentize } from 'polished'
import React, { useMemo, useState } from 'react'
import { useMemo, useState } from 'react'
import { Check, Info } from 'react-feather'
import { Flex, Text } from 'rebass'
import { calculatePriceImpact } from 'services/route/utils'
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function ConfirmSwapModalContent({
onSwap,
}: Props) {
const theme = useTheme()
const { isSolana, chainId } = useActiveWeb3React()
const { isSolana } = useActiveWeb3React()
const [encodeSolana] = useEncodeSolana()
const { routeSummary, slippage, isStablePairSwap, isAdvancedMode } = useSwapFormContext()
const [hasAcceptedNewAmount, setHasAcceptedNewAmount] = useState(false)
Expand Down Expand Up @@ -218,7 +218,7 @@ export default function ConfirmSwapModalContent({
const warningStyle =
priceImpactResult.isVeryHigh || priceImpactResult.isInvalid ? { background: theme.red } : undefined

const shouldDisableByPriceImpact = checkShouldDisableByPriceImpact(chainId, isAdvancedMode, priceImpactFromBuild)
const shouldDisableByPriceImpact = checkShouldDisableByPriceImpact(isAdvancedMode, priceImpactFromBuild)

const isShowAcceptNewAmount =
outputChangePercent < SHOW_ACCEPT_NEW_AMOUNT_THRESHOLD || (isStablePairSwap && outputChangePercent < 0)
Expand Down
8 changes: 4 additions & 4 deletions src/components/SwapForm/SwapModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Props = {
const SwapModal: React.FC<Props> = props => {
const { isOpen, tokenAddToMetaMask, onDismiss, swapCallback, buildResult, isBuildingRoute } = props
const { chainId, account } = useActiveWeb3React()

const dispatch = useDispatch()
// modal and loading
const [{ error, isAttemptingTx, txHash }, setSwapState] = useState<{
Expand All @@ -48,7 +49,7 @@ const SwapModal: React.FC<Props> = props => {

const amountOut = currencyOut && CurrencyAmount.fromRawAmount(currencyOut, buildResult?.data?.amountOut || '0')
// text to show while loading
const pendingText = `Swapping ${routeSummary?.parsedAmountIn?.toSignificant(6)} ${
const pendingText = t`Swapping ${routeSummary?.parsedAmountIn?.toSignificant(6)} ${
currencyIn?.symbol
} for ${amountOut?.toSignificant(6)} ${currencyOut?.symbol}`

Expand Down Expand Up @@ -107,9 +108,8 @@ const SwapModal: React.FC<Props> = props => {
const hash = await swapCallback()
handleTxSubmitted(hash)
} catch (e) {
if (e?.code !== 4001 && e?.code !== 'ACTION_REJECTED') captureSwapError(e)
const msg = t`Something went wrong. Please try again`
handleError(e.message === '[object Object]' ? msg : e.message || msg)
captureSwapError(e)
handleError(e.message)
}
}

Expand Down
40 changes: 19 additions & 21 deletions src/components/SwapForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId, Currency, CurrencyAmount } from '@kyberswap/ks-sdk-core'
import { Currency, CurrencyAmount } from '@kyberswap/ks-sdk-core'
import { Trans } from '@lingui/macro'
import { rgba } from 'polished'
import { stringify } from 'querystring'
Expand Down Expand Up @@ -216,26 +216,24 @@ const SwapForm: React.FC<SwapFormProps> = props => {
</Flex>

<Flex sx={{ gap: '12px' }}>
{chainId === ChainId.LINEA_TESTNET ? null : (
<PriceAlertButton
onClick={() =>
navigate(
`${APP_PATHS.PROFILE_MANAGE}${PROFILE_MANAGE_ROUTES.CREATE_ALERT}?${stringify({
amount: typedValue || undefined,
inputCurrency: currencyId(currencyIn, chainId),
outputCurrency: currencyId(currencyOut, chainId),
})}`,
)
}
>
<Clock size={14} color={theme.subText} />
{upToExtraSmall ? null : (
<Text color={theme.subText} style={{ whiteSpace: 'nowrap' }}>
<Trans>Price Alert</Trans>
</Text>
)}
</PriceAlertButton>
)}
<PriceAlertButton
onClick={() =>
navigate(
`${APP_PATHS.PROFILE_MANAGE}${PROFILE_MANAGE_ROUTES.CREATE_ALERT}?${stringify({
amount: typedValue || undefined,
inputCurrency: currencyId(currencyIn, chainId),
outputCurrency: currencyId(currencyOut, chainId),
})}`,
)
}
>
<Clock size={14} color={theme.subText} />
{upToExtraSmall ? null : (
<Text color={theme.subText} style={{ whiteSpace: 'nowrap' }}>
<Trans>Price Alert</Trans>
</Text>
)}
</PriceAlertButton>
<ReverseTokenSelectionButton onClick={() => currencyIn && handleChangeCurrencyOut(currencyIn)} />
</Flex>
</AutoRow>
Expand Down
6 changes: 3 additions & 3 deletions src/components/TransactionConfirmationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { VIEW_MODE } from 'state/user/reducer'
import { ExternalLink } from 'theme'
import { CloseIcon } from 'theme/components'
import { getEtherscanLink, getTokenLogoURL } from 'utils'
import { errorFriendly } from 'utils/dmm'
import { friendlyError } from 'utils/errorMessage'

const Wrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -280,9 +280,9 @@ export function TransactionErrorContent({
lineHeight={'24px'}
style={{ textAlign: 'center', width: '85%' }}
>
{errorFriendly(message)}
{friendlyError(message)}
</Text>
{message !== errorFriendly(message) && (
{message !== friendlyError(message) && (
<AutoColumn justify="center" style={{ width: '100%' }}>
<Text
color={theme.primary}
Expand Down
4 changes: 2 additions & 2 deletions src/components/WalletPopup/SendToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { useCurrencyBalance } from 'state/wallet/hooks'
import { useCheckAddressSolana } from 'state/wallet/solanaHooks'
import { TransactionFlowState } from 'types/TransactionFlowState'
import { formattedNum, shortenAddress } from 'utils'
import { errorFriendly } from 'utils/dmm'
import { friendlyError } from 'utils/errorMessage'
import { maxAmountSpend } from 'utils/maxAmountSpend'

const Label = styled.label<{ color?: string }>`
Expand Down Expand Up @@ -142,7 +142,7 @@ export default function SendToken({
setFlowState(state => ({
...state,
attemptingTxn: false,
errorMessage: errorFriendly(error?.message ?? 'Error occur, please try again'),
errorMessage: friendlyError(error),
}))
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/swapv2/LimitOrder/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const calcPercentFilledOrder = (value: string, total: string, decimals: n
}
}

// todo: move to friendlyError
export const getErrorMessage = (error: any) => {
console.error('Limit order error: ', error)
const errorCode: string = error?.response?.data?.code || error.code || ''
Expand Down
6 changes: 3 additions & 3 deletions src/components/swapv2/styleds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AutoColumn } from 'components/Column'
import Modal, { ModalProps } from 'components/Modal'
import { Z_INDEXS } from 'constants/styles'
import useTheme from 'hooks/useTheme'
import { errorFriendly } from 'utils/dmm'
import { friendlyError } from 'utils/errorMessage'

export const PageWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -136,9 +136,9 @@ export function SwapCallbackError({ error, style = {} }: { error: string; style?
<Alert style={{ marginBottom: 'auto' }} />
<AutoColumn style={{ flexBasis: '100%', margin: '10px 0 auto 8px' }}>
<Text fontSize="16px" fontWeight="500" color={theme.red} lineHeight={'24px'}>
{errorFriendly(error)}
{friendlyError(error)}
</Text>
{error !== errorFriendly(error) && (
{error !== friendlyError(error) && (
<Text
color={theme.primary}
fontSize="12px"
Expand Down
9 changes: 2 additions & 7 deletions src/constants/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const WETH_ONLY: ChainTokenList = {
[ChainId.OPTIMISM]: [WETH[ChainId.OPTIMISM]],
[ChainId.ZKSYNC]: [WETH[ChainId.ZKSYNC]],
[ChainId.SOLANA]: [WETH[ChainId.SOLANA]],
[ChainId.LINEA_TESTNET]: [WETH[ChainId.LINEA_TESTNET]],
[ChainId.LINEA]: [WETH[ChainId.LINEA]],
[ChainId.ZKEVM]: [WETH[ChainId.ZKEVM]],
[ChainId.SOLANA_DEVNET]: [WETH[ChainId.SOLANA_DEVNET]],
}

Expand Down Expand Up @@ -178,12 +178,7 @@ export const SUGGESTED_BASES: ChainTokenList = {
new Token(ChainId.ZKSYNC, '0x503234f203fc7eb888eec8513210612a43cf6115', 18, 'LUSD', 'LUSD'),
new Token(ChainId.ZKSYNC, '0xbbeb516fb02a01611cbbe0453fe3c580d7281011', 8, 'wBTC', 'wBTC'),
],
[ChainId.LINEA_TESTNET]: [
...WETH_ONLY[ChainId.LINEA_TESTNET],
USDC[ChainId.LINEA_TESTNET],
USDT[ChainId.LINEA_TESTNET],
DAI[ChainId.LINEA_TESTNET],
],
[ChainId.ZKEVM]: [...WETH_ONLY[ChainId.ZKEVM], USDC[ChainId.ZKEVM], USDT[ChainId.ZKEVM], DAI[ChainId.ZKEVM]],
[ChainId.LINEA]: [
...WETH_ONLY[ChainId.LINEA],
new Token(ChainId.LINEA, '0x7d43aabc515c356145049227cee54b608342c0ad', 18, 'BUSD', 'BUSD'),
Expand Down
Loading

0 comments on commit 490bd27

Please sign in to comment.