Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for tracked data only with globals #374

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AccountLookup from './pages/AccountLookup'
import LocalLoader from './components/LocalLoader'
import { useLatestBlocks } from './contexts/Application'
import GoogleAnalyticsReporter from './components/analytics/GoogleAnalyticsReporter'
import { PAIR_BLACKLIST, TOKEN_BLACKLIST } from './constants'

const AppWrapper = styled.div`
position: relative;
Expand Down Expand Up @@ -126,7 +127,10 @@ function App() {
strict
path="/token/:tokenAddress"
render={({ match }) => {
if (isAddress(match.params.tokenAddress.toLowerCase())) {
if (
isAddress(match.params.tokenAddress.toLowerCase()) &&
!Object.keys(TOKEN_BLACKLIST).includes(match.params.tokenAddress.toLowerCase())
) {
return (
<LayoutWrapper savedOpen={savedOpen} setSavedOpen={setSavedOpen}>
<TokenPage address={match.params.tokenAddress.toLowerCase()} />
Expand All @@ -142,7 +146,10 @@ function App() {
strict
path="/pair/:pairAddress"
render={({ match }) => {
if (isAddress(match.params.pairAddress.toLowerCase())) {
if (
isAddress(match.params.pairAddress.toLowerCase()) &&
!Object.keys(PAIR_BLACKLIST).includes(match.params.pairAddress.toLowerCase())
) {
return (
<LayoutWrapper savedOpen={savedOpen} setSavedOpen={setSavedOpen}>
<PairPage pairAddress={match.params.pairAddress.toLowerCase()} />
Expand Down
11 changes: 0 additions & 11 deletions src/apollo/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,17 +734,6 @@ export const TOKEN_CHART = gql`
dailyVolumeETH
dailyVolumeToken
dailyVolumeUSD
mostLiquidPairs {
id
token0 {
id
derivedETH
}
token1 {
id
derivedETH
}
}
}
}
`
Expand Down
3 changes: 3 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ export const TOKEN_BLACKLIST = [
'0xfc989fbb6b3024de5ca0144dc23c18a063942ac1',
'0xf4eda77f0b455a12f3eb44f8653835f377e36b76',
'0x93b2fff814fcaeffb01406e80b4ecd89ca6a021b',
'0x9ea3b5b4ec044b70375236a281986106457b20ef',
'0x05934eba98486693aaec2d00b0e9ce918e37dc3f',
]

// pair blacklist
export const PAIR_BLACKLIST = [
'0xb6a741f37d6e455ebcc9f17e2c16d0586c3f57a5',
'0x97cb8cbe91227ba87fc21aaf52c4212d245da3f8',
'0x1acba73121d5f63d8ea40bdc64edb594bd88ed09',
'0x7d7e813082ef6c143277c71786e5be626ec77b20',
]

// warnings to display if page contains info about blocked token
Expand Down
52 changes: 37 additions & 15 deletions src/contexts/GlobalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default function Provider({ children }) {
* @param {*} oldEthPrice
*/

async function getGlobalData(ethPrice, oldEthPrice, offsetData) {
async function getGlobalData(ethPrice, oldEthPrice, offsetData, offsetData2) {
// data for each day , historic data used for % changes
let data = {}
let oneDayData = {}
Expand Down Expand Up @@ -292,10 +292,8 @@ async function getGlobalData(ethPrice, oldEthPrice, offsetData) {
oneDayData.totalLiquidityETH * oldEthPrice
)

console.log(offsetData)

// add relevant fields with the calculated amounts
data.oneDayVolumeUSD = oneDayVolumeUSD - offsetData.oneDayVolumeUSD
data.oneDayVolumeUSD = oneDayVolumeUSD - offsetData.oneDayVolumeUSD - offsetData2.oneDayVolumeUSD
data.oneWeekVolume = oneWeekVolume
data.weeklyVolumeChange = weeklyVolumeChange
data.volumeChangeUSD = volumeChangeUSD
Expand All @@ -317,7 +315,7 @@ async function getGlobalData(ethPrice, oldEthPrice, offsetData) {
*/

let checked = false
const getChartData = async (oldestDateToFetch, formattedDelataVol) => {
const getChartData = async (oldestDateToFetch, formattedOffsetData, formattedOffsetData2) => {
let data = []
let weeklyData = []
const utcEndTime = dayjs.utc()
Expand Down Expand Up @@ -385,8 +383,11 @@ const getChartData = async (oldestDateToFetch, formattedDelataVol) => {
let currentWeek = -1
data.forEach((entry, i) => {
// hardcoded fix for offset volume
if (formattedDelataVol[data[i].date] && !checked) {
data[i].dailyVolumeUSD = data[i].dailyVolumeUSD - formattedDelataVol[data[i].date].dailyVolumeUSD
if (formattedOffsetData[data[i].date] && !checked) {
data[i].dailyVolumeUSD = data[i].dailyVolumeUSD - formattedOffsetData[data[i].date].dailyVolumeUSD
}
if (formattedOffsetData2[data[i].date] && !checked) {
data[i].dailyVolumeUSD = data[i].dailyVolumeUSD - formattedOffsetData2[data[i].date].dailyVolumeUSD
}
const week = dayjs.utc(dayjs.unix(data[i].date)).week()
if (week !== currentWeek) {
Expand Down Expand Up @@ -549,11 +550,12 @@ export function useGlobalData() {

const data = state?.globalData

const offsetData = useTokenData('0x9ea3b5b4ec044b70375236a281986106457b20ef')
const offsetData = useTokenData('0x05934eba98486693aaec2d00b0e9ce918e37dc3f')
const otherOffsetData = useTokenData('0x9ea3b5b4ec044b70375236a281986106457b20ef')

useEffect(() => {
async function fetchData() {
let globalData = await getGlobalData(ethPrice, oldEthPrice, offsetData)
let globalData = await getGlobalData(ethPrice, oldEthPrice, offsetData, otherOffsetData)
globalData && update(globalData)

let allPairs = await getAllPairsOnUniswap()
Expand All @@ -565,7 +567,16 @@ export function useGlobalData() {
if (!data && ethPrice && oldEthPrice && offsetData && offsetData.oneDayVolumeUSD) {
fetchData()
}
}, [ethPrice, oldEthPrice, update, data, updateAllPairsInUniswap, updateAllTokensInUniswap, offsetData])
}, [
ethPrice,
oldEthPrice,
update,
data,
updateAllPairsInUniswap,
updateAllTokensInUniswap,
offsetData,
otherOffsetData,
])

return data || {}
}
Expand All @@ -592,8 +603,9 @@ export function useGlobalChartData() {
}
}, [activeWindow, oldestDateFetch])

// fix for rebassing tokens
const offsetVol = useTokenChartData('0x9ea3b5b4ec044b70375236a281986106457b20ef')
// fix for rebass tokens
const offsetVol = useTokenChartData('0x05934eba98486693aaec2d00b0e9ce918e37dc3f')
const offsetVol2 = useTokenChartData('0x9ea3b5b4ec044b70375236a281986106457b20ef')

const formattedOffsetVol = useMemo(() => {
return (
Expand All @@ -605,19 +617,29 @@ export function useGlobalChartData() {
)
}, [offsetVol])

const formattedOffsetVol2 = useMemo(() => {
return (
offsetVol2 &&
offsetVol2.reduce(function (acc, day) {
acc[day.date] = day
return acc
}, {})
)
}, [offsetVol2])

/**
* Fetch data if none fetched or older data is needed
*/
useEffect(() => {
async function fetchData() {
// historical stuff for chart
let [newChartData, newWeeklyData] = await getChartData(oldestDateFetch, formattedOffsetVol)
let [newChartData, newWeeklyData] = await getChartData(oldestDateFetch, formattedOffsetVol, formattedOffsetVol2)
updateChart(newChartData, newWeeklyData)
}
if (oldestDateFetch && !(chartDataDaily && chartDataWeekly) && formattedOffsetVol) {
if (oldestDateFetch && !(chartDataDaily && chartDataWeekly) && formattedOffsetVol && formattedOffsetVol2) {
fetchData()
}
}, [chartDataDaily, chartDataWeekly, formattedOffsetVol, oldestDateFetch, updateChart])
}, [chartDataDaily, chartDataWeekly, formattedOffsetVol, oldestDateFetch, updateChart, formattedOffsetVol2])

return [chartDataDaily, chartDataWeekly]
}
Expand Down