Skip to content

Commit

Permalink
update analytics pair details and token details pages
Browse files Browse the repository at this point in the history
  • Loading branch information
totop716 committed Dec 29, 2021
1 parent c25bb70 commit 4eacc81
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 66 deletions.
15 changes: 15 additions & 0 deletions src/apollo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ export const PAIR_CHART = gql`
}
`;

export const HOURLY_PAIR_RATES = (pairAddress: string, blocks: any[]) => {
let queryString = 'query blocks {';
queryString += blocks.map(
(block) => `
t${block.timestamp}: pair(id:"${pairAddress}", block: { number: ${block.number} }) {
token0Price
token1Price
}
`,
);

queryString += '}';
return gql(queryString);
};

const PairFields = `
fragment PairFields on Pair {
id
Expand Down
18 changes: 12 additions & 6 deletions src/components/PairsTable/PairsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,18 @@ const PairTable: React.FC<TokensTableProps> = ({ data }) => {
const liquidity = pair.trackedReserveUSD
? pair.trackedReserveUSD
: pair.reserveUSD;
const oneDayVolume = pair.oneDayVolumeUSD
? pair.oneDayVolumeUSD
: pair.oneDayVolumeUntracked;
const oneWeekVolume = pair.oneWeekVolumeUSD
? pair.oneWeekVolumeUSD
: pair.oneWeekVolumeUntracked;
const oneDayVolume =
pair.oneDayVolumeUSD && !isNaN(pair.oneDayVolumeUSD)
? pair.oneDayVolumeUSD
: pair.oneDayVolumeUntracked && !isNaN(pair.oneDayVolumeUntracked)
? pair.oneDayVolumeUntracked
: 0;
const oneWeekVolume =
pair.oneWeekVolumeUSD && !isNaN(pair.oneWeekVolumeUSD)
? pair.oneWeekVolumeUSD
: pair.oneWeekVolumeUntracked && !isNaN(pair.oneWeekVolumeUntracked)
? pair.oneWeekVolumeUntracked
: 0;
const oneDayFee = (Number(oneDayVolume) * 0.003).toLocaleString();
return [
{
Expand Down
6 changes: 3 additions & 3 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ export const KOM = new Token(
);
export const UST = new Token(
ChainId.MATIC,
'0x692597b009d13C4049a947CAB2239b7d6517875F',
18,
'0xE6469Ba6D2fD6130788E0eA9C0a0515900563b59',
6,
'UST',
'Wrapped UST Token',
);
Expand Down Expand Up @@ -1890,4 +1890,4 @@ export const BETTER_TRADE_LINK_THRESHOLD = new Percent(

// the Uniswap Default token list lives here
export const DEFAULT_TOKEN_LIST_URL =
'https://unpkg.com/[email protected].17/build/quickswap-default.tokenlist.json';
'https://unpkg.com/[email protected].18/build/quickswap-default.tokenlist.json';
2 changes: 1 addition & 1 deletion src/constants/lists.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// the Quickswap Default token list lives here
export const DEFAULT_TOKEN_LIST_URL =
'https://unpkg.com/[email protected].17/build/quickswap-default.tokenlist.json';
'https://unpkg.com/[email protected].18/build/quickswap-default.tokenlist.json';

export const DEFAULT_LIST_OF_LISTS: string[] = [DEFAULT_TOKEN_LIST_URL];
9 changes: 8 additions & 1 deletion src/pages/AnalyticsPage/AnalyticsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,14 @@ const AnalyticsPage: React.FC = () => {
val.token1.decimals,
);
return (
<Box mt={1} key={ind} display='flex' alignItems='center'>
<Box
mt={1}
key={ind}
display='flex'
alignItems='center'
style={{ cursor: 'pointer' }}
onClick={() => history.push(`/analytics/pair/${val.id}`)}
>
<DoubleCurrencyLogo
currency0={currency0}
currency1={currency1}
Expand Down
10 changes: 4 additions & 6 deletions src/pages/AnalyticsPairDetails/AnalyticsPairDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
formatCompact,
getPairTransactions,
getPairChartData,
getHourlyRateData,
} from 'utils';
import { useActiveWeb3React } from 'hooks';
import {
Expand Down Expand Up @@ -194,15 +195,13 @@ const AnalyticsPairDetails: React.FC = () => {
? Number(item.dailyVolumeUSD)
: chartIndex === 1
? Number(item.reserveUSD)
: Number(item.dailyVolumeToken0),
: Number(item.dailyVolumeUSD) * 0.003,
);
} else {
return null;
}
}, [pairChartData, chartIndex]);

console.log('ccc', pairChartData);

const yAxisValues = useMemo(() => {
if (chartData) {
const minValue = Math.min(...chartData) * 0.99;
Expand Down Expand Up @@ -266,7 +265,6 @@ const AnalyticsPairDetails: React.FC = () => {
}
}
fetchPairChartData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pairAddress]);

return (
Expand Down Expand Up @@ -377,7 +375,7 @@ const AnalyticsPairDetails: React.FC = () => {
className={cx(classes.button, classes.filledButton)}
onClick={() => {
history.push(
`/swap?currency0=${pairData.token1.id}&currency1=${pairData.token1.id}`,
`/swap?currency0=${pairData.token0.id}&currency1=${pairData.token1.id}`,
);
}}
>
Expand Down Expand Up @@ -484,7 +482,7 @@ const AnalyticsPairDetails: React.FC = () => {
className={classes.chartType}
onClick={() => setChartIndex(2)}
>
<Typography variant='caption'>Price</Typography>
<Typography variant='caption'>Fees</Typography>
</Box>
</Box>
</Box>
Expand Down
25 changes: 13 additions & 12 deletions src/pages/AnalyticsTokenDetails/AnalyticsTokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import cx from 'classnames';
import { shortenAddress, getEtherscanLink, formatCompact } from 'utils';
import { useActiveWeb3React } from 'hooks';
import { CurrencyLogo, PairTable, AreaChart } from 'components';
import {
useTokenPairs,
useBookmarkTokens,
useTokenChartData,
} from 'state/application/hooks';
import { useBookmarkTokens } from 'state/application/hooks';
import {
getTokenInfo,
getEthPrice,
Expand Down Expand Up @@ -113,10 +109,14 @@ const AnalyticsTokenDetails: React.FC = () => {
const currency = token
? new Token(ChainId.MATIC, getAddress(token.id), token.decimals)
: undefined;
const { tokenChartData, updateTokenChartData } = useTokenChartData();
const [tokenChartData, updateTokenChartData] = useState<any>(null);
const [chartIndex, setChartIndex] = useState(0);
const { tokenPairs, updateTokenPairs } = useTokenPairs();
const { bookmarkTokens } = useBookmarkTokens();
const [tokenPairs, updateTokenPairs] = useState<any>(null);
const {
bookmarkTokens,
addBookmarkToken,
removeBookmarkToken,
} = useBookmarkTokens();

useEffect(() => {
async function checkEthPrice() {
Expand Down Expand Up @@ -211,7 +211,6 @@ const AnalyticsTokenDetails: React.FC = () => {
}
async function fetchTokenPairs() {
const [newPrice] = await getEthPrice();
updateTokenPairs({ data: null });
const tokenPairs = await getTokenPairs2(tokenAddress);
const formattedPairs = tokenPairs
? tokenPairs.map((pair: any) => {
Expand All @@ -220,7 +219,7 @@ const AnalyticsTokenDetails: React.FC = () => {
: [];
const pairData = await getBulkPairData(formattedPairs, newPrice);
if (pairData) {
updateTokenPairs({ data: pairData });
updateTokenPairs(pairData);
}
}
fetchTokenPairs();
Expand Down Expand Up @@ -277,9 +276,11 @@ const AnalyticsTokenDetails: React.FC = () => {
</Typography>
</Box>
{bookmarkTokens.includes(token.id) ? (
<StarChecked />
<StarChecked
onClick={() => removeBookmarkToken(token.id)}
/>
) : (
<StarUnchecked />
<StarUnchecked onClick={() => addBookmarkToken(token.id)} />
)}
</Box>
<Box mt={1.25} display='flex' alignItems='center'>
Expand Down
4 changes: 0 additions & 4 deletions src/state/application/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,3 @@ export const updateBookmarkPairs = createAction<string[]>(
);

export const updateTopPairs = createAction<any>('application/updateTopPairs');

export const updateTokenChartData = createAction<any>(
'application/updateTokenChartData',
);
18 changes: 0 additions & 18 deletions src/state/application/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
updateTopPairs,
addBookMarkPair,
removeBookmarkPair,
updateTokenChartData,
} from './actions';

export function useBlockNumber(): number | undefined {
Expand Down Expand Up @@ -315,20 +314,3 @@ export function useTopPairs(): {
);
return { topPairs, updateTopPairs: _updateTopPairs };
}

export function useTokenChartData(): {
tokenChartData: any;
updateTokenChartData: (data: any) => void;
} {
const tokenChartData = useSelector(
(state: AppState) => state.application.tokenChartData,
);
const dispatch = useDispatch();
const _updateTokenChartData = useCallback(
(data) => {
dispatch(updateTokenChartData(data));
},
[dispatch],
);
return { tokenChartData, updateTokenChartData: _updateTokenChartData };
}
4 changes: 0 additions & 4 deletions src/state/application/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
addBookMarkPair,
removeBookmarkPair,
updateBookmarkPairs,
updateTokenChartData,
} from './actions';

type PopupList = Array<{
Expand Down Expand Up @@ -179,8 +178,5 @@ export default createReducer(initialState, (builder) =>
})
.addCase(updateBookmarkPairs, (state, { payload }) => {
state.bookmarkedPairs = payload;
})
.addCase(updateTokenChartData, (state, { payload }) => {
state.tokenChartData = payload;
}),
);
2 changes: 1 addition & 1 deletion src/state/lists/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe('list reducer', () => {
expect(store.getState()).toEqual({
byUrl: {},
selectedListUrl:
'https://unpkg.com/[email protected].17/build/quickswap-default.tokenlist.json',
'https://unpkg.com/[email protected].18/build/quickswap-default.tokenlist.json',
});
});
});
Expand Down
30 changes: 20 additions & 10 deletions src/state/stake/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ export const SYRUP_REWARDS_INFO: {
}[];
} = {
[ChainId.MATIC]: [
{
token: SNE,
stakingRewardAddress: '0xf6Fe46F0001FDeFAde6b5E08635ED303f2E0a3aA',
ended: false,
lp: '',
name: '',
baseToken: USDC,
rate: 160000,
ending: 1643302635,
},
{
token: POLYPUG,
stakingRewardAddress: '0xA206A97b30343a0802553dB48d71af349AbF563A',
Expand Down Expand Up @@ -347,16 +357,6 @@ export const SYRUP_REWARDS_INFO: {
rate: 40610.66,
ending: 1644090690,
},
{
token: UFI,
stakingRewardAddress: '0xE707bB8513873c2360811F01BfBd0e9EBFd96b0D',
ended: false,
lp: '',
name: '',
baseToken: MATIC,
rate: 18315,
ending: 1640485140,
},
{
token: WSG,
stakingRewardAddress: '0x2b91d985AEb645cc580E35BdF52DF2694e742ADF',
Expand Down Expand Up @@ -483,6 +483,16 @@ export const OLD_SYRUP_REWARDS_INFO: {
}[];
} = {
[ChainId.MATIC]: [
{
token: UFI,
stakingRewardAddress: '0xE707bB8513873c2360811F01BfBd0e9EBFd96b0D',
ended: true,
lp: '',
name: '',
baseToken: MATIC,
rate: 18315,
ending: 1640485140,
},
{
token: UCO,
stakingRewardAddress: '0xC328d6eC46d11a6ABdA3C02434861beA14739E1f',
Expand Down
Loading

0 comments on commit 4eacc81

Please sign in to comment.