forked from sifiorg/sifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): show all-time volume
fix: pnpm fixup! feat(frontend): show all-time volume fix: make requests concurrently fixup! feat(frontend): show all-time volume fix: font size and layout shift fixup! feat(frontend): show all-time volume fix: reduce request frequency
- Loading branch information
1 parent
e0754bb
commit 26026a0
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useAllTimeStats } from 'src/hooks/useAllTimeStats'; | ||
import { numberWithCommas } from 'src/utils/numberWithCommas'; | ||
|
||
const Stats = () => { | ||
const { error, data } = useAllTimeStats(); | ||
|
||
if (error) { | ||
console.error('Failed to fetch all-time stats:', error); | ||
} | ||
|
||
return ( | ||
<div className="font-display m-auto text-center text-sm p-2 flex place-items-center justify-center relative"> | ||
{data ? ( | ||
`All-time volume: $${numberWithCommas(data)}` | ||
) : ( | ||
// To avoid layout shifts | ||
<span className="invisible">Placehodler</span> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export { Stats }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { request, gql } from 'graphql-request'; | ||
import GRAPH_URLS from 'src/subgraph.json'; | ||
|
||
const ALL_TIME_STATS_QUERY = gql` | ||
query { | ||
allTimeStats(id: "current") { | ||
volumeUsd | ||
} | ||
} | ||
`; | ||
|
||
type AllTimeStatsResponse = { | ||
allTimeStats: { | ||
volumeUsd: string; | ||
}; | ||
}; | ||
|
||
const useAllTimeStats = () => { | ||
return useQuery( | ||
['allTimeStats'], | ||
async () => { | ||
const responses = (await Promise.all( | ||
Object.values(GRAPH_URLS).map(url => | ||
request(url, ALL_TIME_STATS_QUERY).catch((error: any) => { | ||
console.error(`Failed to fetch data from ${url}:`, error); | ||
|
||
return { allTimeStats: { volumeUsd: '0' } }; | ||
}) | ||
) | ||
)) as AllTimeStatsResponse[]; | ||
|
||
const totalVolumeUsd = responses.reduce( | ||
(sum: number, response: AllTimeStatsResponse) => | ||
sum + Number(response.allTimeStats?.volumeUsd ?? '0'), | ||
0 | ||
); | ||
|
||
return Math.round(totalVolumeUsd); | ||
}, | ||
{ | ||
staleTime: 1000 * 60 * 5, // 5 minutes | ||
refetchOnWindowFocus: false, | ||
} | ||
); | ||
}; | ||
|
||
export { useAllTimeStats }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"1": "https://gateway-arbitrum.network.thegraph.com/api/3e9d2f58d24bcd5d854ba4c4c8df5c3b/subgraphs/id/G316MkVLSw1ksstmonpSQ1UEBUWmRSZf4QkoRA5CN4TA", | ||
"10": "https://api.thegraph.com/subgraphs/name/sifiorg/sifi-optimism", | ||
"56": "https://api.thegraph.com/subgraphs/name/sifiorg/sifi-bsc", | ||
"137": "https://gateway-arbitrum.network.thegraph.com/api/3e9d2f58d24bcd5d854ba4c4c8df5c3b/subgraphs/id/VJesTAc98ochTTwDQViVgnM4jWhyRC4pyWHBpDQkCjj", | ||
"8453": "https://api.thegraph.com/subgraphs/name/sifiorg/sifi-base", | ||
"42161": "https://gateway-arbitrum.network.thegraph.com/api/3e9d2f58d24bcd5d854ba4c4c8df5c3b/subgraphs/id/BVexPGe3pnB7Mw7ajFkEDQJ8XY8XdVKbAL37ydmorhSQ", | ||
"43114": "https://gateway-arbitrum.network.thegraph.com/api/3e9d2f58d24bcd5d854ba4c4c8df5c3b/subgraphs/id/4cn8JGVKUJBWRJNt4n5KQNMKyMLjRATUBLQ9oSCbL9QA" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.