Skip to content

Commit

Permalink
Merge branch 'fix-crash' into test-prod
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Nov 28, 2023
2 parents 81fbbcb + 998ced3 commit 5e7c5eb
Show file tree
Hide file tree
Showing 45 changed files with 652 additions and 697 deletions.
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ export default defineConfig({
})
},
specPattern: 'cypress/e2e/specs/*.e2e.cy.ts',
excludeSpecPattern: '*/*/**/zap.e2e.cy.ts',
},
})
10 changes: 5 additions & 5 deletions cypress/e2e/selectors/constants.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export enum TAG {
}

export const TOKEN_SYMBOLS = {
Ethereum: ['BAND', 'wstETH', 'USDT', 'USDC', '1INCH'],
Arbitrum: ['ANGLE', 'ARB', 'USDT', 'USDC.e', 'BOB'],
Optimism: ['BOND', 'wstETH', 'USDT', 'USDC', 'BOB'],
Avalanche: ['AAVE.e', 'sAVAX', 'USDT.e', 'USDC.e', 'BUSD.e'],
BNB: ['RICE', 'BUSD', 'USDT', 'USDC', 'BOB'],
Ethereum: ['BAND', 'wstETH', 'USDT', 'AAVE', '1INCH'],
Arbitrum: ['ANGLE', 'ARB', 'USDT', 'ANGLE', 'BOB'],
Optimism: ['BOND', 'WETH', 'USDT', 'AAVE', 'BOB'],
Avalanche: ['AAVE.e', 'sAVAX', 'USDT.e', 'ANGLE', 'BUSD.e'],
BNB: ['RICE', 'BUSD', 'USDT', 'AAVE', 'BOB'],
}

export const NETWORK_LIST = [
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/specs/intercept.e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { FarmPage } from "../pages/farm-page.po.cy";
import { SwapPage, TokenCatalog } from "../pages/swap-page.po.cy"
import { DEFAULT_URL, TAG, } from "../selectors/constants.cy"
import { HeaderLocators } from "../selectors/selectors.cy"
const tokenCatalog = new TokenCatalog()
const farm = new FarmPage()

describe('Intercept', { tags: TAG.regression }, () => {
before(() => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
})

afterEach(() => {
cy.reload()
cy.clearCookies();
cy.clearLocalStorage();
})

describe('Swap', () => {
it('Should get route successfully', () => {
cy.intercept('GET', '**/routes?**').as('get-route')
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Intercept', { tags: TAG.regression }, () => {
cy.intercept('GET', '**/pools?**').as('get-pool-list')
SwapPage.goToFarmPage()
cy.get('[data-testid=farm-block]')
.should(_ => {})
.should(_ => { })
.then($list => {
if ($list.length) {
cy.wait('@get-pool-list', { timeout: 5000 }).its('response.statusCode').should('equal', 200)
Expand Down
15 changes: 7 additions & 8 deletions cypress/e2e/specs/swap-page.e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {

it('Should be selected tokenOut in favorite tokens list successfully', () => {
SwapPage.selectTokenOut().getFavoriteTokens(arr => {
tokenCatalog.selectFavoriteToken(arr[2])
tokenCatalog.selectFavoriteToken(arr[0])
SwapPage.getCurrentTokenOut(text => {
expect(text).to.equal(arr[2])
expect(text).to.equal(arr[0])
})
})
})
})

describe('Remove/add token with favorite tokens list', () => {
afterEach(() => {
tokenCatalog.closePopup()
})
it('Should be removed tokenIn from favorite tokens list', () => {
SwapPage.selectTokenIn().getFavoriteTokens(arr => {
tokenCatalog.removeFavoriteToken(arr[1])
Expand All @@ -54,15 +57,13 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
expect(list).not.to.include.members([arr[1]])
})
})
tokenCatalog.closePopup()
})

it('Should be added tokenIn to favorite tokens list', () => {
SwapPage.selectTokenIn().addFavoriteToken([tokenSymbols[0]])
tokenCatalog.getFavoriteTokens(list => {
expect(list).to.include.members([tokenSymbols[0]])
})
tokenCatalog.closePopup()
})

it('Should be removed tokenOut from favorite tokens list', () => {
Expand All @@ -73,15 +74,13 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
expect(list).not.to.include.members([arr[2]])
})
})
tokenCatalog.closePopup()
})

it('Should be added tokenOut to favorite tokens list', () => {
SwapPage.selectTokenOut().addFavoriteToken([tokenSymbols[0]])
SwapPage.selectTokenOut().addFavoriteToken([tokenSymbols[4]])
tokenCatalog.getFavoriteTokens(list => {
expect(list).to.include.members([tokenSymbols[0]])
expect(list).to.include.members([tokenSymbols[4]])
})
tokenCatalog.closePopup()
})
})

Expand Down
5 changes: 4 additions & 1 deletion src/components/Announcement/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export const ackAnnouncementPopup = (id: string | number) => {

export const formatNumberOfUnread = (num: number | undefined) => (num ? (num > 10 ? '10+' : num + '') : null)

const NO_NOTI_PAGES = [APP_PATHS.IAM_CONSENT, APP_PATHS.IAM_LOGIN, APP_PATHS.IAM_LOGOUT, APP_PATHS.PARTNER_SWAP]

export const isPopupCanShow = (
popupInfo: PopupItemType<PopupContentAnnouncement>,
chainId: ChainId,
account: string | undefined,
) => {
if ([APP_PATHS.IAM_CONSENT, APP_PATHS.IAM_LOGIN, APP_PATHS.IAM_LOGOUT].includes(window.location.pathname))
if (NO_NOTI_PAGES.some(path => window.location.pathname.startsWith(path))) {
return false
}

const { templateBody = {}, metaMessageId } = popupInfo.content
const { endAt, startAt, chainIds = [] } = templateBody as AnnouncementTemplatePopup
Expand Down
3 changes: 2 additions & 1 deletion src/components/ElasticZap/QuickZap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export const QuickZapButton = ({
const isZapAvailable = !!(networkInfo as EVMNetworkInfo).elastic.zap
const theme = useTheme()

return (
const tmp = true
return tmp ? null : (
<MouseoverTooltip
text={
isZapAvailable ? (
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchModal/CurrencyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function CurrencyList({
const canShowBalance = customChainId && customChainId !== chainId ? isEVM(customChainId) === isEVM(chainId) : true
const { favoriteTokens } = useUserFavoriteTokens(customChainId)

const Row: any = useCallback(
const Row = useCallback(
function TokenRow({ style, currency, currencyBalance }: TokenRowProps) {
const isSelected = Boolean(currency && selectedCurrency?.equals(currency))
const otherSelected = Boolean(currency && otherCurrency?.equals(currency))
Expand Down
26 changes: 3 additions & 23 deletions src/components/SearchModal/CurrencySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ChangeEvent, KeyboardEvent, ReactNode, useCallback, useEffect, useMemo,
import { Trash } from 'react-feather'
import { usePrevious } from 'react-use'
import { Flex, Text } from 'rebass'
import { useImportTokenMutation } from 'services/ksSetting'
import styled from 'styled-components'

import Column from 'components/Column'
Expand Down Expand Up @@ -102,7 +101,7 @@ const fetchTokens = async (
): Promise<WrappedTokenInfo[]> => {
try {
if (search && chainId && isAddress(chainId, search)) {
const token = await fetchTokenByAddress(search, chainId, signal)
const token = await fetchTokenByAddress(search, chainId)
return token ? [token as WrappedTokenInfo] : []
}
const params: { query: string; isWhitelisted?: boolean; pageSize: number; page: number; chainIds: string } = {
Expand Down Expand Up @@ -174,7 +173,7 @@ export function CurrencySearch({
return (debouncedQuery ? filterTokens(chainId, tokenImports, debouncedQuery) : tokenImports).sort(tokenComparator)
}, [debouncedQuery, chainId, tokenImports, tokenComparator])

const fetchERC20TokenFromRPC = useFetchERC20TokenFromRPC()
const fetchERC20TokenFromRPC = useFetchERC20TokenFromRPC(chainId)

// input eth => output filter weth, input weth => output filter eth
const filterWrapFunc = useCallback(
Expand Down Expand Up @@ -312,7 +311,6 @@ export function CurrencySearch({
}, [fetchFavoriteTokenFromAddress])

const abortControllerRef = useRef(new AbortController())
const [importTokensToKsSettings] = useImportTokenMutation()
const fetchListTokens = useCallback(
async (page?: number) => {
const nextPage = (page ?? pageCount) + 1
Expand All @@ -335,15 +333,6 @@ export function CurrencySearch({
symbol: rawToken.symbol || 'UNKNOWN',
}),
)

importTokensToKsSettings([
{
chainId: String(rawToken.chainId),
address: rawToken.address,
},
]).catch(err => {
console.error('import token err', err)
})
}
}
} else {
Expand All @@ -354,16 +343,7 @@ export function CurrencySearch({
setFetchedTokens(current => (nextPage === 1 ? [] : current).concat(tokens))
setHasMoreToken(tokens.length === PAGE_SIZE && !!debouncedQuery)
},
[
isImportedTab,
chainId,
debouncedQuery,
defaultTokens,
fetchERC20TokenFromRPC,
isQueryValidEVMAddress,
pageCount,
importTokensToKsSettings,
],
[isImportedTab, chainId, debouncedQuery, defaultTokens, fetchERC20TokenFromRPC, isQueryValidEVMAddress, pageCount],
)

const [hasMoreToken, setHasMoreToken] = useState(false)
Expand Down
5 changes: 2 additions & 3 deletions src/components/SwapForm/SlippageSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ type Props = {
isStablePairSwap: boolean
rightComponent?: ReactNode
tooltip?: ReactNode
isCrossChain?: boolean
}
const SlippageSetting = ({ isStablePairSwap, rightComponent, tooltip, isCrossChain }: Props) => {
const SlippageSetting = ({ isStablePairSwap, rightComponent, tooltip }: Props) => {
const theme = useTheme()
const [expanded, setExpanded] = useState(false)

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

const isWarningSlippage = checkWarningSlippage(rawSlippage, isStablePairSwap)
Expand Down
7 changes: 6 additions & 1 deletion src/components/SwapForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ const SwapForm: React.FC<SwapFormProps> = props => {
)}
</PriceAlertButton>
)}
<ReverseTokenSelectionButton onClick={() => currencyIn && onChangeCurrencyOut(currencyIn)} />
<ReverseTokenSelectionButton
onClick={() => {
currencyIn && onChangeCurrencyOut(currencyIn)
routeSummary && onUserInput(routeSummary.parsedAmountOut.toExact())
}}
/>
</Flex>
</AutoRow>

Expand Down
2 changes: 1 addition & 1 deletion src/components/TradeRouting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const RouteRow = ({ route, chainId, backgroundColor }: RouteRowProps) => {
const contentRef = useRef<HTMLDivElement>(null)
const shadowRef = useRef<HTMLDivElement>(null)

const allDexes = useAllDexes()
const allDexes = useAllDexes(chainId)
const handleShadow = useShadow(scrollRef, shadowRef, contentRef)

useEffect(() => {
Expand Down
8 changes: 6 additions & 2 deletions src/components/swapv2/LimitOrder/EditOrderModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { Trans } from '@lingui/macro'
import { ethers } from 'ethers'
import { useEffect, useMemo, useRef, useState } from 'react'
Expand Down Expand Up @@ -42,6 +43,7 @@ enum Steps {
export default function EditOrderModal({
onSubmit,
onDismiss,
customChainId,
order,
note,
isOpen,
Expand All @@ -50,6 +52,7 @@ export default function EditOrderModal({
}: {
onSubmit: CancelOrderFunction
onDismiss: () => void
customChainId?: ChainId
order: LimitOrder
note: string
isOpen: boolean
Expand All @@ -60,8 +63,8 @@ export default function EditOrderModal({
const [step, setStep] = useState(Steps.EDIT_ORDER)

const { status, makingAmount, takingAmount, makerAsset, takerAsset, filledTakingAmount, expiredAt } = order
const currencyIn = useCurrencyV2(makerAsset) ?? undefined
const currencyOut = useCurrencyV2(takerAsset) ?? undefined
const currencyIn = useCurrencyV2(makerAsset, customChainId) ?? undefined
const currencyOut = useCurrencyV2(takerAsset, customChainId) ?? undefined
const inputAmount = currencyIn ? ethers.utils.formatUnits(makingAmount, currencyIn.decimals) : ''
const outputAmount = currencyOut ? ethers.utils.formatUnits(takingAmount, currencyOut.decimals) : ''

Expand Down Expand Up @@ -193,6 +196,7 @@ export default function EditOrderModal({
note={note}
orderInfo={order}
defaultExpire={defaultExpire}
useUrlParams
/>
)}
</Wrapper>
Expand Down
8 changes: 6 additions & 2 deletions src/components/swapv2/LimitOrder/ListOrder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ export default function ListLimitOrder({ customChainId }: { customChainId?: Chai
setCurPage(1)
}

const isPartnerSwap = window.location.pathname.includes(APP_PATHS.PARTNER_SWAP)
const navigate = useNavigate()
const onSelectTab = (type: LimitOrderStatus) => {
setOrderType(type)
onReset()
if (!window.location.pathname.includes(APP_PATHS.PARTNER_SWAP))
if (!isPartnerSwap) {
navigate({ search: stringify(qs) }, { replace: true })
}
}

const onChangeKeyword = (val: string) => {
Expand Down Expand Up @@ -296,7 +298,7 @@ export default function ListLimitOrder({ customChainId }: { customChainId?: Chai
}, [totalOrderNotCancelling, orders, ordersUpdating])

const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`)
const subscribeBtn = !window.location.pathname.includes(APP_PATHS.PARTNER_SWAP) && (
const subscribeBtn = !isPartnerSwap && (
<SubscribeNotificationButton
iconOnly={false}
style={{ margin: upToSmall ? 0 : '12px 12px 0px 12px' }}
Expand Down Expand Up @@ -397,6 +399,7 @@ export default function ListLimitOrder({ customChainId }: { customChainId?: Chai
flowState={flowState}
onDismiss={hideConfirmCancel}
onSubmit={onCancelOrder}
customChainId={customChainId}
order={currentOrder}
isCancelAll={isCancelAll}
/>
Expand All @@ -405,6 +408,7 @@ export default function ListLimitOrder({ customChainId }: { customChainId?: Chai
<EditOrderModal
flowState={flowState}
setFlowState={setFlowState}
customChainId={customChainId}
isOpen={isOpenEdit}
onDismiss={hideEditModal}
onSubmit={onCancelOrder}
Expand Down
13 changes: 10 additions & 3 deletions src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { Trans, t } from '@lingui/macro'
import { useEffect, useMemo, useState } from 'react'
import { Text } from 'rebass'
Expand Down Expand Up @@ -26,21 +27,23 @@ export enum CancelStatus {
const styleLogo = { width: 20, height: 20 }
function CancelOrderModal({
isCancelAll,
customChainId,
order,
onSubmit,
onDismiss,
flowState,
isOpen,
}: {
isCancelAll: boolean
customChainId?: ChainId
order: LimitOrder | undefined
onSubmit: CancelOrderFunction
onDismiss: () => void
flowState: TransactionFlowState
isOpen: boolean
}) {
const currencyIn = useCurrencyV2(order?.makerAsset) || undefined
const currencyOut = useCurrencyV2(order?.takerAsset) || undefined
const currencyIn = useCurrencyV2(order?.makerAsset, customChainId) || undefined
const currencyOut = useCurrencyV2(order?.takerAsset, customChainId) || undefined
const { tradeInfo: marketPrice } = useBaseTradeInfoLimitOrder(currencyIn, currencyOut)

const {
Expand All @@ -56,7 +59,11 @@ function CancelOrderModal({
takerAssetDecimals,
} = order ?? ({} as LimitOrder)

const { orders = [], ordersSoftCancel = [], supportCancelGaslessAllOrders } = useAllActiveOrders(!isCancelAll)
const {
orders = [],
ordersSoftCancel = [],
supportCancelGaslessAllOrders,
} = useAllActiveOrders(!isCancelAll, customChainId)

const isOrderSupportGaslessCancel = useIsSupportSoftCancelOrder()
const { orderSupportGasless, chainSupportGasless } = isOrderSupportGaslessCancel(order)
Expand Down
5 changes: 3 additions & 2 deletions src/components/swapv2/LimitOrder/useFetchActiveAllOrders.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import { useCallback, useMemo } from 'react'
import { useGetLOConfigQuery, useGetListOrdersQuery } from 'services/limitOrder'

Expand All @@ -18,10 +19,10 @@ export const useIsSupportSoftCancelOrder = () => {
)
}

export default function useAllActiveOrders(disabled = false) {
export default function useAllActiveOrders(disabled = false, customChainId?: ChainId) {
const { account, chainId } = useActiveWeb3React()
const { data } = useGetListOrdersQuery(
{ chainId, maker: account, status: LimitOrderStatus.ACTIVE, pageSize: 100 },
{ chainId: customChainId ?? chainId, maker: account, status: LimitOrderStatus.ACTIVE, pageSize: 100 },
{ skip: !account || disabled },
)

Expand Down
Loading

0 comments on commit 5e7c5eb

Please sign in to comment.