Skip to content

Commit

Permalink
fix: add historical data query for token prices
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeonus committed Oct 1, 2024
1 parent 86d75a8 commit 77039ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/data/balancer-api-v3/useGetHistoricalTokenPrice.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { GqlChain } from "../../apollo/generated/graphql-codegen-generated";
import { balancerV3APIClient } from "../../apollo/client";
import { useGetTokenPriceQuery } from "../../apollo/generated/graphql-balancer-v3-codegen-generated";
import { useGetTokenSetHistoricalPricesQuery } from "../../apollo/generated/graphql-balancer-v3-codegen-generated";
import { BalancerChartDataItem } from "../balancer/balancerTypes";
import { unixToDate } from "../../utils/date";

export default function useGetHistoricalTokenPrice(address: string, chainId: GqlChain) {
const { data, loading, error } = useGetTokenPriceQuery({
const { data, loading, error } = useGetTokenSetHistoricalPricesQuery({
client: balancerV3APIClient,
variables: {
address: address,
addresses: [address],
chain: chainId,
},
});

let mappedData: BalancerChartDataItem[] | undefined = undefined;

if (data && data.tokenGetPriceChartData) {
if (data && data.tokenGetHistoricalPrices && data.tokenGetHistoricalPrices.length > 0) {
const tokenData = data.tokenGetHistoricalPrices[0]; // We only expect one token's data

// Group data by date string
const groupedByDate: { [date: string]: BalancerChartDataItem[] } = {};
data.tokenGetPriceChartData.forEach((item) => {
const dateString = unixToDate(item.timestamp); // Get date string
tokenData.prices.forEach((item) => {
const dateString = unixToDate(Number(item.timestamp));
if (!groupedByDate[dateString]) {
groupedByDate[dateString] = [];
}
groupedByDate[dateString].push({
value: parseFloat(item.price),
value: item.price,
time: dateString,
});
});
Expand Down
2 changes: 0 additions & 2 deletions src/pages/VotingIncentives/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export default function VotingIncentives() {
const {address} = useAccount();
const addressRewards = useGetHiddenHandRewards(address ? address : '')
const gaugeData = useGetBalancerV3StakingGauges();
//APR chart data
//const {priceData} = useBalancerTokenPageData(AURA_TOKEN_MAINNET);
const timeStampNow = Math.floor(Date.now() / 1000);
const priceData = HISTORICAL_AURA_PRICE
const { data: auraHistoricalPrice} = useGetHistoricalTokenPrice(AURA_TOKEN_MAINNET, GqlChain.Mainnet)
Expand Down

0 comments on commit 77039ea

Please sign in to comment.