Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use chain aware address #1320

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/products/components/product-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ProductList() {
async function fetchProducts() {
const analyticsPromises = Promise.all(
productTokens.map((token) =>
// TODO: https://github.com/IndexCoop/analytics-sdk/issues/30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yea. I was thinking about this recently. 😅 will try to take a look at the task this week.

token.address ? fetchAnalytics(token.address) : null,
),
)
Expand Down
5 changes: 4 additions & 1 deletion src/lib/hooks/use-best-quote/utils/index-quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { displayFromWei, parseUnits, toWei } from '@/lib/utils'
import { IndexApi } from '@/lib/utils/api/index-api'
import { getFullCostsInUsd, getGasCostsInUsd } from '@/lib/utils/costs'
import { GasEstimatooor } from '@/lib/utils/gas-estimatooor'
import { getAddressForToken } from '@/lib/utils/tokens'

import { IndexQuoteRequest, QuoteType, ZeroExQuote } from '../types'

Expand Down Expand Up @@ -59,7 +60,9 @@ export async function getIndexQuote(
} = request
try {
const inputAmount = parseUnits(inputTokenAmount, inputToken.decimals)
const path = `/quote?takerAddress=${address}&inputToken=${inputToken.address}&outputToken=${outputToken.address}&inputAmount=${inputAmount.toString()}&chainId=${chainId}`
const inputTokenAddress = getAddressForToken(inputToken, chainId)
const outputTokenAddress = getAddressForToken(outputToken, chainId)
const path = `/quote?takerAddress=${address}&inputToken=${inputTokenAddress}&outputToken=${outputTokenAddress}&inputAmount=${inputAmount.toString()}&chainId=${chainId}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, making it future proof. 🌟

console.log(path)
const indexApi = new IndexApi()
const res: QuoteResponse = await indexApi.get(path)
Expand Down
18 changes: 0 additions & 18 deletions src/lib/utils/api/coingecko.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { indicesTokenList } from '@/constants/tokenlists'
import { IndexApi } from '@/lib/utils/api/index-api'

import { ARBITRUM, OPTIMISM, POLYGON } from '../../../constants/chains'
Expand Down Expand Up @@ -52,20 +51,3 @@ export const fetchCoingeckoTokenPrice = async (

return data[address.toLowerCase()][baseCurrency]
}

type CoingeckoMarketData = {
current_price: { usd: number }
market_cap: { usd: number }
price_change_percentage_24h_in_currency: { usd: number }
}

export const fetchCoingeckoMarketData = async (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused in the codebase.

address: string,
): Promise<CoingeckoMarketData | null> => {
const token = indicesTokenList.find(
(token) => token.address?.toLowerCase() === address.toLowerCase(),
)
const url = `${baseURL}/coins/${token?.coingeckoId}?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`
const { market_data } = await indexApi.get(url)
return market_data
}