Skip to content

Commit

Permalink
add function to search token and pair in analytics page.
Browse files Browse the repository at this point in the history
  • Loading branch information
totop716 committed Dec 10, 2021
1 parent 049cc7d commit 108c0ac
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 13 deletions.
125 changes: 125 additions & 0 deletions src/apollo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,94 @@ export const SUBGRAPH_HEALTH = gql`
}
`;

export const TOKEN_SEARCH = gql`
query tokens($value: String, $id: String) {
asSymbol: tokens(
where: { symbol_contains: $value }
orderBy: totalLiquidity
orderDirection: desc
) {
id
symbol
name
decimals
totalLiquidity
}
asName: tokens(
where: { name_contains: $value }
orderBy: totalLiquidity
orderDirection: desc
) {
id
symbol
name
decimals
totalLiquidity
}
asAddress: tokens(
where: { id: $id }
orderBy: totalLiquidity
orderDirection: desc
) {
id
symbol
name
decimals
totalLiquidity
}
}
`;

export const PAIR_SEARCH = gql`
query pairs($tokens: [Bytes]!, $id: String) {
as0: pairs(where: { token0_in: $tokens }) {
id
token0 {
id
symbol
decimals
name
}
token1 {
id
symbol
decimals
name
}
}
as1: pairs(where: { token1_in: $tokens }) {
id
token0 {
id
symbol
decimals
name
}
token1 {
id
symbol
decimals
name
}
}
asAddress: pairs(where: { id: $id }) {
id
token0 {
id
symbol
decimals
name
}
token1 {
id
symbol
decimals
name
}
}
}
`;

export const TOKEN_CHART = gql`
query tokenDayDatas($tokenAddr: String!, $startTime: Int!) {
tokenDayDatas(
Expand Down Expand Up @@ -86,6 +174,43 @@ export const PAIRS_BULK: any = (pairs: any[]) => {
return gql(queryString);
};

export const ALL_TOKENS = gql`
query tokens($skip: Int!) {
tokens(first: 10, skip: $skip) {
id
name
symbol
decimals
totalLiquidity
}
}
`;

export const ALL_PAIRS = gql`
query pairs($skip: Int!) {
pairs(
first: 10
skip: $skip
orderBy: trackedReserveETH
orderDirection: desc
) {
id
token0 {
id
symbol
name
decimals
}
token1 {
id
symbol
name
decimals
}
}
}
`;

export const PAIRS_BULK1 = gql`
${PairFields}
query pairs($allPairs: [Bytes]!) {
Expand Down
13 changes: 13 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ import {
} from '../connectors';
import { getAddress } from '@ethersproject/address';

export const TOKEN_BLACKLIST = [
'0x495c7f3a713870f68f8b418b355c085dfdc412c3',
'0xc3761eb917cd790b30dad99f6cc5b4ff93c4f9ea',
'0xe31debd7abff90b06bca21010dd860d8701fd901',
'0xfc989fbb6b3024de5ca0144dc23c18a063942ac1',
'0xf4eda77f0b455a12f3eb44f8653835f377e36b76',
];

export const PAIR_BLACKLIST = [
'0xb6a741f37d6e455ebcc9f17e2c16d0586c3f57a5',
'0x97cb8cbe91227ba87fc21aaf52c4212d245da3f8',
];

export const SUPPORTED_WALLETS: { [key: string]: WalletInfo } = {
INJECTED: {
connector: injected,
Expand Down
11 changes: 10 additions & 1 deletion src/pages/AnalyticsPage/AnalyticsOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const AnalyticsOverview: React.FC<AnalyticsOverViewProps> = ({
if (topTokensData) {
updateTopTokens(topTokensData);
}
};
const fetchTopPairs = async () => {
const [newPrice] = await getEthPrice();
const pairs = await getTopPairs(8);
const formattedPairs = pairs
? pairs.map((pair: any) => {
Expand All @@ -109,7 +112,13 @@ const AnalyticsOverview: React.FC<AnalyticsOverViewProps> = ({
}
};
fetchChartData();
fetchTopTokens();
if (!topTokens || topTokens.length < 8) {
fetchTopTokens();
}
if (!topPairs || topPairs.length < 8) {
fetchTopPairs();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [startTime, updateGlobalChartData, updateTopTokens, updateTopPairs]);

const liquidityDates = useMemo(() => {
Expand Down
Loading

0 comments on commit 108c0ac

Please sign in to comment.