Skip to content

Commit

Permalink
Minor improvement and bugfix (#2276)
Browse files Browse the repository at this point in the history
* feat: add x-client-id to aggregator

* fix: classic zap crash

* feat: hide disclaimer token for erc20 standard

* switch to addresses query

* fix: classic not working

* Update pr.yaml
  • Loading branch information
viet-nv authored Oct 4, 2023
1 parent 69384a0 commit 5f08d10
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ export function useContract(
): Contract | null {
const { account, isEVM } = useActiveWeb3React()
const { library } = useWeb3React()
const { readProvider } = useKyberSwapConfig()

const lib = useMemo(() => (account ? library : readProvider), [account, library, readProvider])

return useMemo(() => {
if (!isEVM || !address || !ABI || !library) return null
if (!isEVM || !address || !ABI || !lib) return null
try {
return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined)
return getContract(address, ABI, lib as any, withSignerIfPossible && account ? account : undefined)
} catch (error) {
console.error('Failed to get contract', error)
return null
}
}, [address, ABI, library, withSignerIfPossible, account, isEVM])
}, [address, ABI, lib, withSignerIfPossible, account, isEVM])
}

export function useContractForReading(
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useZap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ export const useZapInAmounts = (
if (tokenIn && tokenOut && pool && userIn?.gt(0)) {
const amounts = await calculateZapInAmounts(tokenIn, tokenOut, pool, userIn)

setResult({
amounts,
error: undefined,
})
if (amounts)
setResult({
amounts,
error: undefined,
})
}
} catch (err) {
setResult({
Expand Down
6 changes: 5 additions & 1 deletion src/pages/AddLiquidity/TokenPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ const TokenPair = ({
</Warning>
)}

<DisclaimerERC20 href="https://docs.kyberswap.com/liquidity-solutions/kyberswap-elastic/user-guides/add-liquidity-to-an-existing-elastic-pool#non-standard-tokens" />
<DisclaimerERC20
href="https://docs.kyberswap.com/liquidity-solutions/kyberswap-elastic/user-guides/add-liquidity-to-an-existing-elastic-pool#non-standard-tokens"
token0={currencyA?.wrapped.address || ''}
token1={currencyB?.wrapped.address || ''}
/>

<div style={{ marginBottom: '1.5rem' }} />

Expand Down
18 changes: 17 additions & 1 deletion src/pages/AddLiquidityV2/components/DisclaimerERC20.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { Trans } from '@lingui/macro'
import { AlertTriangle } from 'react-feather'
import { Flex, Text } from 'rebass'
import { useGetTokenListQuery } from 'services/ksSetting'

import { WarningCard } from 'components/Card'
import { useActiveWeb3React } from 'hooks'
import useTheme from 'hooks/useTheme'
import { ExternalLink } from 'theme'

export default function DisclaimerERC20({ href }: { href?: string }) {
export default function DisclaimerERC20({ href, token0, token1 }: { href?: string; token0: string; token1: string }) {
const theme = useTheme()
const { chainId } = useActiveWeb3React()
const { data } = useGetTokenListQuery(
{
chainId,
addresses: `${token0},${token1}`,
},
{
skip: !token0 || !token1,
},
)

const hide = data?.data?.tokens?.[0]?.isStandardERC20 && data?.data?.tokens?.[1]?.isStandardERC20
if (hide) return null

return (
<WarningCard padding="10px 16px">
<Flex alignItems="center" sx={{ gap: '12px' }} lineHeight={1.5}>
Expand Down
8 changes: 5 additions & 3 deletions src/pages/AddLiquidityV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1629,9 +1629,11 @@ export default function AddLiquidity() {
<Flex>{warnings}</Flex>
</Row>
)}
<Flex maxWidth={chartRef?.current?.clientWidth} alignSelf="flex-end">
<DisclaimerERC20 />
</Flex>
{tokenA && tokenB && (
<Flex maxWidth={chartRef?.current?.clientWidth} alignSelf="flex-end">
<DisclaimerERC20 token0={tokenA.address} token1={tokenB.address} />
</Flex>
)}

<Row justify="flex-end">
<Buttons />
Expand Down
6 changes: 5 additions & 1 deletion src/pages/CreatePool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,11 @@ export default function CreatePool() {
</Warning>
)}

<DisclaimerERC20 href="https://docs.kyberswap.com/liquidity-solutions/kyberswap-classic/user-guides/classic-pool-creation#non-standard-tokens" />
<DisclaimerERC20
href="https://docs.kyberswap.com/liquidity-solutions/kyberswap-classic/user-guides/classic-pool-creation#non-standard-tokens"
token0={currencyA?.wrapped.address || ''}
token1={currencyB?.wrapped.address || ''}
/>

{!account ? (
<ButtonLight onClick={toggleWalletModal}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Farm/ElasticFarmCombination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export const ElasticFarmCombination: FC = () => {
<Trans>
Note: Farms will run in{' '}
<Text as="span" color={theme.warning}>
multiple phases
</Text>
multiple phases.
</Text>{' '}
If you haven’t harvested your rewards for ended farms, you still can access them via the{' '}
<StyledInternalLink to={`${APP_PATHS.FARMS}/${networkInfo.route}?type=${FARM_TAB.ENDED}`}>
Ended
Expand Down
5 changes: 3 additions & 2 deletions src/services/baseQueryOauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { KyberOauth2Api } from '@kybernetwork/oauth2'
import { FetchBaseQueryArgs } from '@reduxjs/toolkit/dist/query/fetchBaseQuery'
import { BaseQueryFn, fetchBaseQuery } from '@reduxjs/toolkit/query'
import axios from 'axios'

Expand Down Expand Up @@ -33,11 +34,11 @@ const baseQueryOauth =

// same as baseQueryOauth, but has flag to revert if meet incident
export const baseQueryOauthDynamic =
({ baseUrl = '' }: { baseUrl?: string }): BaseQueryFn =>
({ baseUrl = '', ...baseFetchOption }: FetchBaseQueryArgs): BaseQueryFn =>
async (args, WebApi, extraOptions) => {
if (!args.authentication) {
// to quickly revert if meet incident
const rawBaseQuery = fetchBaseQuery({ baseUrl })
const rawBaseQuery = fetchBaseQuery({ baseUrl, ...baseFetchOption })
return rawBaseQuery(args, WebApi, extraOptions)
}
return queryWithTokenAndTracking(args, baseUrl)
Expand Down
10 changes: 9 additions & 1 deletion src/services/ksSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ const ksSettingApi = createApi({

getTokenList: builder.query<
TokenListResponse,
{ chainId: number; page?: number; pageSize?: number; isWhitelisted?: boolean; isStable?: boolean }
{
chainId: number
page?: number
pageSize?: number
isWhitelisted?: boolean
isStable?: boolean
query?: string
addresses?: string
}
>({
query: ({ chainId, ...params }) => ({
url: `/tokens`,
Expand Down
10 changes: 9 additions & 1 deletion src/services/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { GetRouteParams, GetRouteResponse } from './types/getRoute'

const routeApi = createApi({
reducerPath: 'routeApi',
baseQuery: baseQueryOauthDynamic({ baseUrl: '' }),
baseQuery: baseQueryOauthDynamic({
baseUrl: '',
}),
endpoints: builder => ({
getRoute: builder.query<
GetRouteResponse,
Expand All @@ -20,6 +22,9 @@ const routeApi = createApi({
url,
params,
authentication,
headers: {
'x-client-id': 'kyberswap',
},
}),
}),
buildRoute: builder.mutation<
Expand All @@ -32,6 +37,9 @@ const routeApi = createApi({
body: payload,
signal,
authentication,
headers: {
'x-client-id': 'kyberswap',
},
}),
}),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/state/farms/elasticv2/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const useFilteredFarmsV2 = (farmAddress?: string) => {
const updatedFarms = useMemo(() => {
const newFarms = farms
?.filter(farm => {
if (farm?.endTime < Date.now() / 1000) return false
if (farm?.endTime < Date.now() / 1000 || farm?.isSettled) return false
const isUserJoinThisFarm = userInfo?.find(item => item.fId === farm.fId)
if (!isUserJoinThisFarm) return false

Expand Down
1 change: 1 addition & 0 deletions src/state/lists/wrappedTokenInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface TokenInfo {
readonly isWhitelisted?: boolean // from backend
readonly multichainInfo?: MultiChainTokenInfo // from multichain api
readonly domainSeparator?: string
readonly isStandardERC20?: boolean
}

export class WrappedTokenInfo extends Token {
Expand Down

0 comments on commit 5f08d10

Please sign in to comment.