-
Notifications
You must be signed in to change notification settings - Fork 199
feat: markets page coingecko lists and savers recommended assets #7782
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ff03143
[skip ci] wip: markets page coingecko recommended categories
gomesalexandre cdd1a8d
[skip ci] feat: cleanup some
gomesalexandre 2d11a95
Merge remote-tracking branch 'origin/develop' into feat_coingecko_rec…
gomesalexandre b5b6f0f
[skip ci] feat: make it better
gomesalexandre bbdf131
[skip ci] feat: handle native assets
gomesalexandre 12f485c
feat: trending
gomesalexandre 1311940
feat: cleanup
gomesalexandre 64296f7
feat: more cleanup
gomesalexandre 41e5870
feat: more more cleanup
gomesalexandre 2d84a1a
[skip ci] feat: progression
gomesalexandre e4c9059
feat: cleanup
gomesalexandre c79b2fc
feat: thorchain progression
gomesalexandre 3acfe70
[skip ci] thor too
gomesalexandre 68b6338
fix: times 100 thor apy
gomesalexandre dce484a
fix: thor narrowing
gomesalexandre 50e085e
Merge remote-tracking branch 'origin/develop' into feat_coingecko_rec…
gomesalexandre f5a24a5
fix: don't display chaindropdown for coingecko bits
gomesalexandre adaf5b2
feat: savers supported ChainIds
gomesalexandre 5334f58
[skip ci] fix: uniq
gomesalexandre 38ae34e
feat: add volume and market cap categories, revert chain selection
gomesalexandre 90ebc5e
fix: queryKey
gomesalexandre eb4c3d5
chore: update src/assets/translations/en/main.json
gomesalexandre c9962ef
Merge remote-tracking branch 'origin/develop' into feat_coingecko_rec…
gomesalexandre c9f20b9
feat: attempt using caip/src/adapters to keep things DRY
gomesalexandre a0c597b
feat: dry
gomesalexandre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { AssetId } from '@shapeshiftoss/caip' | ||
import { | ||
adapters, | ||
baseAssetId, | ||
bchAssetId, | ||
bscAssetId, | ||
btcAssetId, | ||
cosmosAssetId, | ||
dogeAssetId, | ||
ethAssetId, | ||
gnosisAssetId, | ||
ltcAssetId, | ||
polygonAssetId, | ||
thorchainAssetId, | ||
} from '@shapeshiftoss/caip' | ||
|
||
export const COINGECKO_NATIVE_ASSET_ID_TO_ASSET_ID: Partial<Record<string, AssetId>> = { | ||
bitcoin: btcAssetId, | ||
'bitcoin-cash': bchAssetId, | ||
dogecoin: dogeAssetId, | ||
litecoin: ltcAssetId, | ||
[adapters.CoingeckoAssetPlatform.Ethereum]: ethAssetId, | ||
[adapters.CoingeckoAssetPlatform.Thorchain]: thorchainAssetId, | ||
[adapters.CoingeckoAssetPlatform.Gnosis]: gnosisAssetId, | ||
[adapters.CoingeckoAssetPlatform.Cosmos]: cosmosAssetId, | ||
// This isn't a mistake - the network and id are different in the case of MATIC/POS | ||
'polygon-ecosystem-token': polygonAssetId, | ||
[adapters.CoingeckoAssetPlatform.Base]: baseAssetId, | ||
// This isn't a mistake - the network and id are different in the case of BSC | ||
binanceCoin: bscAssetId, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { AssetId, ChainId } from '@shapeshiftoss/caip' | ||
import type { | ||
CoinGeckoMarketCap, | ||
CoinGeckoMarketData, | ||
} from 'lib/market-service/coingecko/coingecko-types' | ||
|
||
// Non-exhaustive types, refer to https://docs.coingecko.com/reference/coins-id and other endpoints for full response schema | ||
export type CoingeckoAssetDetails = { | ||
market_data: CoinGeckoMarketData | ||
asset_platform_id: string | ||
id: string | ||
image: Record<string, string> | ||
name: string | ||
symbol: string | ||
detail_platforms: Record<string, { decimal_place: number; contract_address: string }> | ||
platforms: Record<string, string> | ||
} | ||
|
||
export type MoverAsset = Pick< | ||
CoinGeckoMarketCap, | ||
'id' | 'symbol' | 'name' | 'image' | 'market_cap_rank' | ||
> & { | ||
usd: string | ||
usd_24h_vol: string | ||
usd_1y_change: string | ||
} | ||
|
||
export type MoversResponse = { | ||
top_gainers: MoverAsset[] | ||
top_losers: MoverAsset[] | ||
} | ||
|
||
// Non-exhaustive | ||
export type TrendingCoin = { | ||
id: string | ||
coin_id: number | ||
name: string | ||
symbol: string | ||
market_cap_rank: number | ||
thumb: string | ||
small: string | ||
large: string | ||
slug: string | ||
price_btc: number | ||
score: number | ||
data: { | ||
price: number | ||
price_btc: string | ||
price_change_percentage_24h: Record<string, number> | ||
market_cap: string | ||
market_cap_btc: string | ||
total_volume: string | ||
} | ||
} | ||
|
||
export type TrendingResponse = { | ||
coins: { | ||
item: TrendingCoin | ||
}[] | ||
} | ||
|
||
export type RecentlyAddedCoin = { | ||
id: string | ||
symbol: string | ||
name: string | ||
activated_at: number | ||
} | ||
|
||
export type RecentlyAddedResponse = RecentlyAddedCoin[] | ||
|
||
export type CoingeckoAsset = { | ||
assetId: AssetId | ||
details: CoingeckoAssetDetails | ||
} | ||
|
||
export type CoingeckoList = { | ||
byId: Record<AssetId, CoingeckoAsset> | ||
ids: AssetId[] | ||
chainIds: ChainId[] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { adapters, ASSET_NAMESPACE, bscChainId, toAssetId } from '@shapeshiftoss/caip' | ||
import type { CoingeckoAssetPlatform } from '@shapeshiftoss/caip/src/adapters' | ||
import axios from 'axios' | ||
import { queryClient } from 'context/QueryClientProvider/queryClient' | ||
import type { CoinGeckoMarketCap } from 'lib/market-service/coingecko/coingecko-types' | ||
|
||
import { COINGECKO_NATIVE_ASSET_ID_TO_ASSET_ID } from './constants' | ||
import type { | ||
CoingeckoAsset, | ||
CoingeckoAssetDetails, | ||
MoverAsset, | ||
MoversResponse, | ||
RecentlyAddedCoin, | ||
RecentlyAddedResponse, | ||
TrendingCoin, | ||
TrendingResponse, | ||
} from './types' | ||
|
||
const coingeckoBaseUrl = 'https://api.proxy.shapeshift.com/api/v1/markets' | ||
|
||
const getCoinDetails = async ( | ||
marketCap: CoinGeckoMarketCap | RecentlyAddedCoin | TrendingCoin | MoverAsset, | ||
i: number, | ||
all: CoingeckoAsset[], | ||
) => { | ||
try { | ||
const { data } = await queryClient.fetchQuery({ | ||
queryKey: ['coingecko', 'coin', marketCap.id], | ||
// Shared query across consumers, so make it infinite as there will be a lot of overlap | ||
queryFn: () => axios.get<CoingeckoAssetDetails>(`${coingeckoBaseUrl}/coins/${marketCap.id}`), | ||
gcTime: Infinity, | ||
staleTime: Infinity, | ||
}) | ||
const { asset_platform_id, id } = data | ||
|
||
const address = data.platforms?.[asset_platform_id] | ||
|
||
if (!address) return | ||
|
||
const assetId = (() => { | ||
// Handles native assets, which *may* not contain a platform_id | ||
if (COINGECKO_NATIVE_ASSET_ID_TO_ASSET_ID[id]) | ||
return COINGECKO_NATIVE_ASSET_ID_TO_ASSET_ID[id] | ||
|
||
const chainId = adapters.coingeckoAssetPlatformToChainId( | ||
asset_platform_id as CoingeckoAssetPlatform, | ||
) | ||
if (!chainId) return | ||
|
||
const assetId = toAssetId({ | ||
chainId, | ||
assetNamespace: chainId === bscChainId ? ASSET_NAMESPACE.bep20 : ASSET_NAMESPACE.erc20, | ||
assetReference: address, | ||
}) | ||
return assetId | ||
})() | ||
|
||
if (!assetId) return marketCap | ||
|
||
all[i] = { | ||
assetId, | ||
details: data, | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching asset details for ${marketCap.id}:`, error) | ||
return null | ||
} | ||
} | ||
|
||
export const getCoingeckoTopMovers = async (): Promise<CoingeckoAsset[]> => { | ||
const { data } = await axios.get<MoversResponse>( | ||
`${coingeckoBaseUrl}/coins/top_gainers_losers?vs_currency=usd`, | ||
) | ||
|
||
const all: CoingeckoAsset[] = [] | ||
|
||
await Promise.allSettled( | ||
data.top_gainers | ||
.concat(data.top_losers) | ||
.map((marketData, i) => getCoinDetails(marketData, i, all)), | ||
) | ||
|
||
return all.filter(mover => Boolean(mover.assetId)) | ||
} | ||
|
||
export const getCoingeckoTrending = async (): Promise<CoingeckoAsset[]> => { | ||
const { data } = await axios.get<TrendingResponse>(`${coingeckoBaseUrl}/search/trending`) | ||
|
||
const all: CoingeckoAsset[] = [] | ||
|
||
await Promise.allSettled( | ||
data.coins.map(({ item }) => item).map((marketData, i) => getCoinDetails(marketData, i, all)), | ||
) | ||
|
||
return all.filter(mover => Boolean(mover.assetId)) | ||
} | ||
|
||
export const getCoingeckoRecentlyAdded = async (): Promise<CoingeckoAsset[]> => { | ||
const { data } = await axios.get<RecentlyAddedResponse>(`${coingeckoBaseUrl}/coins/list/new`) | ||
|
||
const all: CoingeckoAsset[] = [] | ||
|
||
await Promise.allSettled(data.map((marketData, i) => getCoinDetails(marketData, i, all))) | ||
|
||
return all.filter(mover => Boolean(mover.assetId)) | ||
} | ||
|
||
export const getCoingeckoMarkets = async ( | ||
order: 'market_cap_desc' | 'volume_desc', | ||
): Promise<CoingeckoAsset[]> => { | ||
const { data } = await axios.get<CoinGeckoMarketCap[]>( | ||
`${coingeckoBaseUrl}/coins/markets?vs_currency=usd&order=${order}`, | ||
) | ||
|
||
const all: CoingeckoAsset[] = [] | ||
|
||
await Promise.allSettled(data.map((marketData, i) => getCoinDetails(marketData, i, all))) | ||
|
||
return all.filter(mover => Boolean(mover.assetId)) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.