Skip to content

Commit

Permalink
Merge pull request #7 from helix-bridge/jay/fix-cors
Browse files Browse the repository at this point in the history
Fix CORS
  • Loading branch information
xiaoch05 authored Jul 17, 2024
2 parents a2a248d + 2cf2ab3 commit 998f84a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy staging
name: Deploy production

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion apps/web/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1"
REACT_APP_MOONPAY_API="https://api.moonpay.com"
REACT_APP_MOONPAY_LINK="https://us-central1-uniswap-mobile.cloudfunctions.net/signMoonpayLinkV2?platform=web&env=production"
REACT_APP_MOONPAY_PUBLISHABLE_KEY="pk_live_uQG4BJC4w3cxnqpcSqAfohdBFDTsY6E"
REACT_APP_SENTRY_ENABLED=true
REACT_APP_SENTRY_ENABLED=false
REACT_APP_SENTRY_TRACES_SAMPLE_RATE=0.003
REACT_APP_STATSIG_PROXY_URL="https://interface.gateway.uniswap.org/v1/statsig-proxy"
REACT_APP_QUICKNODE_MAINNET_RPC_URL="https://ultra-blue-flower.quiknode.pro/770b22d5f362c537bc8fe19b034c45b22958f880"
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/FiatOnrampModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function FiatOnrampModal() {
])

useEffect(() => {
fetchSignedIframeUrl()
// fetchSignedIframeUrl()
}, [fetchSignedIframeUrl])

return (
Expand Down
50 changes: 25 additions & 25 deletions apps/web/src/hooks/useAccountRiskCheck.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { useEffect } from 'react'
import { ApplicationModal, setOpenModal } from 'state/application/reducer'
import { useAppDispatch } from 'state/hooks'
// import { useEffect } from 'react'
// import { ApplicationModal, setOpenModal } from 'state/application/reducer'
// import { useAppDispatch } from 'state/hooks'

export default function useAccountRiskCheck(account: string | null | undefined) {
const dispatch = useAppDispatch()
// const dispatch = useAppDispatch()

useEffect(() => {
if (!account) {
return
}
// useEffect(() => {
// if (!account) {
// return
// }

// TODO: add back local browser cacheing (revisit 11/13/2023)
const headers = new Headers({ 'Content-Type': 'application/json' })
fetch('https://interface.gateway.uniswap.org/v1/screen', {
method: 'POST',
headers,
body: JSON.stringify({ address: account }),
})
.then((res) => res.json())
.then((data) => {
if (data.block) {
dispatch(setOpenModal(ApplicationModal.BLOCKED_ACCOUNT))
}
})
.catch(() => {
dispatch(setOpenModal(null))
})
}, [account, dispatch])
// // TODO: add back local browser cacheing (revisit 11/13/2023)
// const headers = new Headers({ 'Content-Type': 'application/json' })
// fetch('https://interface.gateway.uniswap.org/v1/screen', {
// method: 'POST',
// headers,
// body: JSON.stringify({ address: account }),
// })
// .then((res) => res.json())
// .then((data) => {
// if (data.block) {
// dispatch(setOpenModal(ApplicationModal.BLOCKED_ACCOUNT))
// }
// })
// .catch(() => {
// dispatch(setOpenModal(null))
// })
// }, [account, dispatch])
}
214 changes: 108 additions & 106 deletions apps/web/src/hooks/useFilterPossiblyMaliciousPositions.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
import { useQueries } from '@tanstack/react-query'
import { SupportedInterfaceChainId, chainIdToBackendChain } from 'constants/chains'
import { apolloClient } from 'graphql/data/apollo/client'
import { gqlTokenToCurrencyInfo } from 'graphql/data/types'
import { apolloQueryOptions } from 'graphql/data/util'
import { useMemo } from 'react'
// import { useQueries } from '@tanstack/react-query'
// import { SupportedInterfaceChainId, chainIdToBackendChain } from 'constants/chains'
// import { apolloClient } from 'graphql/data/apollo/client'
// import { gqlTokenToCurrencyInfo } from 'graphql/data/types'
// import { apolloQueryOptions } from 'graphql/data/util'
// import { useMemo } from 'react'
import { PositionDetails } from 'types/position'
import {
SafetyLevel,
SimpleTokenDocument,
SimpleTokenQuery,
Token,
} from 'uniswap/src/data/graphql/uniswap-data-api/__generated__/types-and-hooks'
import { hasURL } from 'utils/urlChecks'
// import {
// SafetyLevel,
// SimpleTokenDocument,
// SimpleTokenQuery,
// Token,
// } from 'uniswap/src/data/graphql/uniswap-data-api/__generated__/types-and-hooks'
// import { hasURL } from 'utils/urlChecks'

import { useAccount } from 'hooks/useAccount'
import { useTokenContractsConstant } from './useTokenContractsConstant'
// import { useAccount } from 'hooks/useAccount'
// import { useTokenContractsConstant } from './useTokenContractsConstant'

function getUniqueAddressesFromPositions(positions: PositionDetails[]): string[] {
return Array.from(
new Set(positions.reduce<string[]>((acc, position) => acc.concat(position.token0, position.token1), []))
)
}
// function getUniqueAddressesFromPositions(positions: PositionDetails[]): string[] {
// return Array.from(
// new Set(positions.reduce<string[]>((acc, position) => acc.concat(position.token0, position.token1), []))
// )
// }

function getPositionCurrencyInfosQueryOptions(position: PositionDetails, chainId?: SupportedInterfaceChainId) {
return apolloQueryOptions({
queryKey: ['positionCurrencyInfo', position],
queryFn: async () => {
const queries = [
apolloClient.query<SimpleTokenQuery>({
query: SimpleTokenDocument,
variables: {
address: position.token0,
chain: chainIdToBackendChain({ chainId }),
},
fetchPolicy: 'cache-first',
}),
apolloClient.query<SimpleTokenQuery>({
query: SimpleTokenDocument,
variables: {
address: position.token1,
chain: chainIdToBackendChain({ chainId }),
},
fetchPolicy: 'cache-first',
}),
]
const [currency0, currency1] = await Promise.all(queries)
return {
position,
currency0Info: gqlTokenToCurrencyInfo(currency0.data.token as Token),
currency1Info: gqlTokenToCurrencyInfo(currency1.data.token as Token),
}
},
})
}
// function getPositionCurrencyInfosQueryOptions(position: PositionDetails, chainId?: SupportedInterfaceChainId) {
// return apolloQueryOptions({
// queryKey: ['positionCurrencyInfo', position],
// queryFn: async () => {
// const queries = [
// apolloClient.query<SimpleTokenQuery>({
// query: SimpleTokenDocument,
// variables: {
// address: position.token0,
// chain: chainIdToBackendChain({ chainId }),
// },
// fetchPolicy: 'cache-first',
// }),
// apolloClient.query<SimpleTokenQuery>({
// query: SimpleTokenDocument,
// variables: {
// address: position.token1,
// chain: chainIdToBackendChain({ chainId }),
// },
// fetchPolicy: 'cache-first',
// }),
// ]
// const [currency0, currency1] = await Promise.all(queries)
// return {
// position,
// currency0Info: gqlTokenToCurrencyInfo(currency0.data.token as Token),
// currency1Info: gqlTokenToCurrencyInfo(currency1.data.token as Token),
// }
// },
// })
// }

/**
* This function is an attempt to filter out an observed phishing attack from LP list UIs.
Expand All @@ -66,65 +66,67 @@ function getPositionCurrencyInfosQueryOptions(position: PositionDetails, chainId
* The hope is that this approach removes the cheapest version of the attack without punishing non-malicious url symbols
*/
export function useFilterPossiblyMaliciousPositions(positions: PositionDetails[]): PositionDetails[] {
const { chainId } = useAccount()
const nonListPositionTokenAddresses = useMemo(() => getUniqueAddressesFromPositions(positions), [positions])
// const { chainId } = useAccount()
// const nonListPositionTokenAddresses = useMemo(() => getUniqueAddressesFromPositions(positions), [positions])

// const positionCurrencyInfos = useQueries({
// queries: positions.map((position) => getPositionCurrencyInfosQueryOptions(position, chainId)),
// })
// const symbolCallStates = useTokenContractsConstant(nonListPositionTokenAddresses, 'symbol')

const positionCurrencyInfos = useQueries({
queries: positions.map((position) => getPositionCurrencyInfosQueryOptions(position, chainId)),
})
const symbolCallStates = useTokenContractsConstant(nonListPositionTokenAddresses, 'symbol')
// const addressesToSymbol: Record<string, string> = useMemo(() => {
// const result: Record<string, string> = {}
// for (let i = 0; i < nonListPositionTokenAddresses.length; i++) {
// const callResult = symbolCallStates[i]?.result
// if (!callResult) {
// continue
// }
// const address = nonListPositionTokenAddresses[i]
// result[address] = callResult as unknown as string
// }
// return result
// }, [nonListPositionTokenAddresses, symbolCallStates])

const addressesToSymbol: Record<string, string> = useMemo(() => {
const result: Record<string, string> = {}
for (let i = 0; i < nonListPositionTokenAddresses.length; i++) {
const callResult = symbolCallStates[i]?.result
if (!callResult) {
continue
}
const address = nonListPositionTokenAddresses[i]
result[address] = callResult as unknown as string
}
return result
}, [nonListPositionTokenAddresses, symbolCallStates])
// return useMemo(() => {
// return positionCurrencyInfos
// .map((result) => {
// if (!result.data) {
// return undefined
// }

return useMemo(() => {
return positionCurrencyInfos
.map((result) => {
if (!result.data) {
return undefined
}
// const { currency0Info, currency1Info, position } = result.data
// let tokensInListCount = 0
// if (!currency0Info?.isSpam && currency0Info?.safetyLevel === SafetyLevel.Verified) {
// tokensInListCount++
// }
// if (!currency1Info?.isSpam && currency1Info?.safetyLevel === SafetyLevel.Verified) {
// tokensInListCount++
// }
// // if both tokens are in the list, then we let both have url symbols (so we don't check)
// if (tokensInListCount === 2) {
// return position
// }

const { currency0Info, currency1Info, position } = result.data
let tokensInListCount = 0
if (!currency0Info?.isSpam && currency0Info?.safetyLevel === SafetyLevel.Verified) {
tokensInListCount++
}
if (!currency1Info?.isSpam && currency1Info?.safetyLevel === SafetyLevel.Verified) {
tokensInListCount++
}
// if both tokens are in the list, then we let both have url symbols (so we don't check)
if (tokensInListCount === 2) {
return position
}
// // check the token symbols to see if they contain a url
// // prioritize the token entity from the list if it exists
// // if the token isn't in the list, then use the data returned from chain calls
// let urlSymbolCount = 0
// if (hasURL(currency0Info?.currency?.symbol ?? addressesToSymbol[position.token0])) {
// urlSymbolCount++
// }
// if (hasURL(currency1Info?.currency?.symbol ?? addressesToSymbol[position.token1])) {
// urlSymbolCount++
// }
// // if one token is in the list, then one token can have a url symbol
// if (tokensInListCount === 1 && urlSymbolCount < 2) {
// return position
// }

// check the token symbols to see if they contain a url
// prioritize the token entity from the list if it exists
// if the token isn't in the list, then use the data returned from chain calls
let urlSymbolCount = 0
if (hasURL(currency0Info?.currency?.symbol ?? addressesToSymbol[position.token0])) {
urlSymbolCount++
}
if (hasURL(currency1Info?.currency?.symbol ?? addressesToSymbol[position.token1])) {
urlSymbolCount++
}
// if one token is in the list, then one token can have a url symbol
if (tokensInListCount === 1 && urlSymbolCount < 2) {
return position
}
// // if neither token is in the list, then neither can have a url symbol
// return urlSymbolCount === 0 ? position : undefined
// })
// .filter((position): position is PositionDetails => !!position)
// }, [addressesToSymbol, positionCurrencyInfos])

// if neither token is in the list, then neither can have a url symbol
return urlSymbolCount === 0 ? position : undefined
})
.filter((position): position is PositionDetails => !!position)
}, [addressesToSymbol, positionCurrencyInfos])
return positions
}
2 changes: 1 addition & 1 deletion apps/web/src/hooks/useUSDPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function useUSDPrice(
const isTokenEthPriced = Boolean(tokenEthPrice || isTokenEthPriceLoading)
const { data, networkStatus } = useTokenSpotPriceQuery({
variables: { chain: chain ?? Chain.Ethereum, address: getNativeTokenDBAddress(chain ?? Chain.Ethereum) },
skip: !isTokenEthPriced || !isWindowVisible,
skip: !isTokenEthPriced || !isWindowVisible || true,
pollInterval: PollingInterval.Normal,
notifyOnNetworkStatusChange: true,
fetchPolicy: 'cache-first',
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import '@reach/dialog/styles.css'
import 'inter-ui'
import 'polyfills'
import 'tracing'
// import 'tracing'
import './i18n' // ensure translations load before things
/* eslint-enable prettier/prettier */

Expand Down

0 comments on commit 998f84a

Please sign in to comment.