Commit 7b9a23d9 authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

feat: reduce severity of phishing filter to allow url token names (#6282)

* feat: reduce severity of phishing filter to allow url token names

* tests

* remove unused var from test

* test rendering mini portfolio pools list

* update owner

* update variable names to match cmcewen's suggestions

* checkStringForURL -> hasURL
parent 120ad935
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { render, screen } from 'test-utils' import { SupportedChainId, Token, WETH9 } from '@uniswap/sdk-core'
import { FeeAmount, Pool } from '@uniswap/v3-sdk'
import { USDC_MAINNET } from 'constants/tokens'
import { useToken } from 'hooks/Tokens'
import { usePool } from 'hooks/usePools'
import { PoolState } from 'hooks/usePools'
import { render } from 'test-utils'
import { unwrappedToken } from 'utils/unwrappedToken'
import PositionListItem from '.' import PositionListItem from '.'
jest.mock('hooks/Tokens', () => { jest.mock('utils/unwrappedToken')
const originalModule = jest.requireActual('hooks/Tokens') const mockUnwrappedToken = unwrappedToken as jest.MockedFunction<typeof unwrappedToken>
const uniSDK = jest.requireActual('@uniswap/sdk-core')
jest.mock('hooks/usePools')
const mockUsePool = usePool as jest.MockedFunction<typeof usePool>
jest.mock('hooks/Tokens')
const mockUseToken = useToken as jest.MockedFunction<typeof useToken>
// eslint-disable-next-line react/display-name
jest.mock('components/DoubleLogo', () => () => <div />)
jest.mock('@web3-react/core', () => {
const web3React = jest.requireActual('@web3-react/core')
return { return {
__esModule: true, ...web3React,
...originalModule, useWeb3React: () => ({
useToken: jest.fn( chainId: 1,
() => }),
new uniSDK.Token( }
1, })
'0x39AA39c021dfbaE8faC545936693aC917d5E7563',
8, const susToken0Address = '0x39AA39c021dfbaE8faC545936693aC917d5E7563'
'https://www.example.com',
'example.com coin' beforeEach(() => {
) const susToken0 = new Token(1, susToken0Address, 8, 'https://www.example.com', 'example.com coin')
), mockUseToken.mockImplementation((tokenAddress?: string | null | undefined) => {
if (!tokenAddress) return null
if (tokenAddress === susToken0.address) return susToken0
return new Token(1, tokenAddress, 8, 'symbol', 'name')
})
mockUsePool.mockReturnValue([
PoolState.EXISTS,
new Pool(susToken0, USDC_MAINNET, FeeAmount.HIGH, '2437312313659959819381354528', '10272714736694327408', -69633),
])
mockUnwrappedToken.mockReturnValue(susToken0)
})
test('PositionListItem should not render when token0 symbol contains a url', () => {
const positionDetails = {
token0: susToken0Address,
token1: USDC_MAINNET.address,
tokenId: BigNumber.from(436148),
fee: 100,
liquidity: BigNumber.from('0x5c985aff8059be04'),
tickLower: -800,
tickUpper: 1600,
}
const { container } = render(<PositionListItem {...positionDetails} />)
expect(container).toBeEmptyDOMElement()
})
test('PositionListItem should not render when token1 symbol contains a url', () => {
const positionDetails = {
token0: USDC_MAINNET.address,
token1: susToken0Address,
tokenId: BigNumber.from(436148),
fee: 100,
liquidity: BigNumber.from('0x5c985aff8059be04'),
tickLower: -800,
tickUpper: 1600,
} }
const { container } = render(<PositionListItem {...positionDetails} />)
expect(container).toBeEmptyDOMElement()
}) })
test('PositionListItem should not render when the name contains a url', () => { test('PositionListItem should render a position', () => {
const positionDetails = { const positionDetails = {
token0: '0x39AA39c021dfbaE8faC545936693aC917d5E7563', token0: USDC_MAINNET.address,
token1: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', token1: WETH9[SupportedChainId.MAINNET].address,
tokenId: BigNumber.from(436148), tokenId: BigNumber.from(436148),
fee: 100, fee: 100,
liquidity: BigNumber.from('0x5c985aff8059be04'), liquidity: BigNumber.from('0x5c985aff8059be04'),
tickLower: -800, tickLower: -800,
tickUpper: 1600, tickUpper: 1600,
} }
render(<PositionListItem {...positionDetails} />) const { container } = render(<PositionListItem {...positionDetails} />)
screen.debug() expect(container).not.toBeEmptyDOMElement()
expect(screen.queryByText('.com', { exact: false })).toBe(null)
}) })
...@@ -203,12 +203,9 @@ export default function PositionListItem({ ...@@ -203,12 +203,9 @@ export default function PositionListItem({
const removed = liquidity?.eq(0) const removed = liquidity?.eq(0)
const containsURL = useMemo( const shouldHidePosition = hasURL(token0?.symbol) || hasURL(token1?.symbol)
() => [token0?.name, token0?.symbol, token1?.name, token1?.symbol].some((testString) => hasURL(testString)),
[token0?.name, token0?.symbol, token1?.name, token1?.symbol]
)
if (containsURL) { if (shouldHidePosition) {
return null return null
} }
......
import { BigNumber } from '@ethersproject/bignumber'
import { SupportedChainId, WETH9 } from '@uniswap/sdk-core'
import { FeeAmount, Pool, Position } from '@uniswap/v3-sdk'
import { USDC_MAINNET } from 'constants/tokens'
import { render } from 'test-utils'
import Pools from '.'
import useMultiChainPositions from './useMultiChainPositions'
jest.mock('./useMultiChainPositions')
const mockUseMultiChainPositions = useMultiChainPositions as jest.MockedFunction<typeof useMultiChainPositions>
const owner = '0xf5b6bb25f5beaea03dd014c6ef9fa9f3926bf36c'
const pool = new Pool(
USDC_MAINNET,
WETH9[SupportedChainId.MAINNET],
FeeAmount.MEDIUM,
'1851127709498178402383049949138810',
'7076437181775065414',
201189
)
const position = new Position({
pool,
liquidity: 1341008833950736,
tickLower: 200040,
tickUpper: 202560,
})
const details = {
nonce: BigNumber.from('0'),
tokenId: BigNumber.from('0'),
operator: '0x0',
token0: USDC_MAINNET.address,
token1: WETH9[SupportedChainId.MAINNET].address,
fee: FeeAmount.MEDIUM,
tickLower: -100,
tickUpper: 100,
liquidity: BigNumber.from('9000'),
feeGrowthInside0LastX128: BigNumber.from('0'),
feeGrowthInside1LastX128: BigNumber.from('0'),
tokensOwed0: BigNumber.from('0'),
tokensOwed1: BigNumber.from('0'),
}
const useMultiChainPositionsReturnValue = {
positions: [
{
owner,
chainId: SupportedChainId.MAINNET,
position,
pool,
details,
inRange: true,
closed: false,
},
],
loading: false,
}
beforeEach(() => {
mockUseMultiChainPositions.mockReturnValue(useMultiChainPositionsReturnValue)
})
test('Pools should render LP positions', () => {
const props = { account: owner }
const { container } = render(<Pools {...props} />)
expect(container).not.toBeEmptyDOMElement()
})
...@@ -111,15 +111,9 @@ function PositionListItem({ positionInfo }: { positionInfo: PositionInfo }) { ...@@ -111,15 +111,9 @@ function PositionListItem({ positionInfo }: { positionInfo: PositionInfo }) {
[chainId, pool.token0.address, pool.token0.symbol, pool.token1.address, pool.token1.symbol] [chainId, pool.token0.address, pool.token0.symbol, pool.token1.address, pool.token1.symbol]
) )
const containsURL = useMemo( const shouldHidePosition = hasURL(pool.token0.symbol) || hasURL(pool.token1.symbol)
() =>
[pool.token0.name, pool.token0.symbol, pool.token1.name, pool.token1.symbol].some((testString) =>
hasURL(testString)
),
[pool]
)
if (containsURL) { if (shouldHidePosition) {
return null return null
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment