From 65bb434329610f5612ddb2f84803b1e4a0d563c1 Mon Sep 17 00:00:00 2001 From: foxier25 Date: Tue, 12 Nov 2024 10:30:27 -0600 Subject: [PATCH] update token details pages with token price --- src/components/Tokens/TokenDetails/index.tsx | 4 +- src/pages/TokenDetails/index.tsx | 50 ++++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/components/Tokens/TokenDetails/index.tsx b/src/components/Tokens/TokenDetails/index.tsx index aa1343866..dabb126bd 100644 --- a/src/components/Tokens/TokenDetails/index.tsx +++ b/src/components/Tokens/TokenDetails/index.tsx @@ -121,7 +121,7 @@ export default function TokenDetails({ }, {} as { [key: string]: string | undefined }) ?? {}, [tokenQueryData] ) - + const { token, didFetchFromChain } = useRelevantToken(address, pageChainId, tokenQueryData) const tokenWarning = address ? checkWarning(address) : null @@ -196,7 +196,7 @@ export default function TokenDetails({ - {/* */} + [isNative ? getNativeTokenDBAddress(chain) : tokenAddress ?? '', toHistoryDuration(timePeriod)], [chain, isNative, timePeriod, tokenAddress] ) - const { data: tokenQuery } = useTokenQuery({ variables: { address, @@ -101,15 +105,14 @@ export default function TokenDetailsPage() { const priceLow52W = dailyPrices && Math.min(...dailyPrices); - console.log("price High and Low",priceHigh52W, priceLow52W); - console.log("tokenQuery = ",tokenQuery); - console.log("tokenPriceQuery = ", tokenPriceQuery); + // console.log("price High and Low",priceHigh52W, priceLow52W); + // console.log("tokenQuery = ",tokenQuery); + // console.log("tokenPriceQuery = ", tokenPriceQuery); const token = luxData?.token; - console.log("token = ", token); // Now, you can assign the JSON data to a variable of type TokenQuery -const transformedTokenDetail: TokenQuery = { +const transformedTokenDetail: TokenQuery = tokenPriceQuery??{ token: { id: "VG9rZW46RVRIRVJFVU1fMHhhMGI4Njk5MWM2MjE4YjM2YzFkMTlkNGEyZTllYjBjZTM2MDZlYjQ4", decimals: 18, @@ -153,8 +156,34 @@ const transformedTokenDetail: TokenQuery = { } } }; +const ethPriceUSD = luxData?.bundles[0]?.ethPriceUSD; +const ethPrice = luxData?.token?.derivedETH; + +const transformedTokenPriceHistory:TokenPriceQuery = { + token: { + __typename: "Token", + id: "VG9rZW46RVRIRVJFVU1fMHhhMGI4Njk5MWM2MjE4YjM2YzFkMTlkNGEyZTllYjBjZTM2MDZlYjQ4", // Encoded version of the token ID + address: luxData?.token?.id, + chain: Chain.Lux, + market: { + __typename: "TokenMarket", + id: "VG9rZW5NYXJrZXQ6RVRIRVJFVU1fMHhhMGI4Njk5MWM2MjE4YjM2YzFkMTlkNGEyZTllYjBjZTM2MDZlYjQ4X1VTRA==", // Encoded ID for the market + price: { + __typename: "Amount", + id: "QW1vdW50OjFfVVNE", // Encoded amount ID + value: parseFloat(ethPriceUSD) * parseFloat(ethPrice), + }, + priceHistory: luxData?.token?.tokenDayData.map((data: any) => ({ + __typename: "TimestampedAmount", + id: `VGltZXN0YW1wZWRBbW91bnQ6MV8x${data.date}_VVNE`, // Encoded version of the timestamped amount + timestamp: data.date, + value: parseFloat(data.priceUSD), + })), + }, + }, +}; -const renderTokenDetail = (tokenAddress: any, chain: any, tokenQuery: any, tokenPriceQuery: any) => ( +const renderTokenDetail = (tokenAddress: any, chain: any, tokenQuery: any) => ( { if (tokenPriceQuery) setCurrentPriceQuery(tokenPriceQuery) - }, [setCurrentPriceQuery, tokenPriceQuery]) + else if(chain == "LUX") setCurrentPriceQuery(transformedTokenPriceHistory) + }, [luxData, tokenPriceQuery]) if (!tokenQuery && !transformedTokenDetail) return if(chain == "LUX") { - return renderTokenDetail(tokenAddress, chain, transformedTokenDetail, tokenPriceQuery) + return renderTokenDetail(tokenAddress, chain, transformedTokenDetail) } if (!tokenQuery) return - return renderTokenDetail(tokenAddress, chain, tokenQuery, tokenPriceQuery) + return renderTokenDetail(tokenAddress, chain, tokenQuery) }