-
Notifications
You must be signed in to change notification settings - Fork 427
feat: added dynamic assets categories using Coingecko API #2593
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
Open
AGMASO
wants to merge
15
commits into
main
Choose a base branch
from
feat/add-filters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8cfc1c4
feat: added filters for categories in market section v0
AGMASO a67bf56
feat: version 1.0.0 filter for markets finished
AGMASO bd4769c
feat: version 1.0.0 filter for markets finished
AGMASO 737c9f7
fix: fix hover effect
AGMASO 09067bb
feat: added dynamic filters using Coingecko api
AGMASO 8d3f15a
feat: add dynamic assets categories using coingecko api & fix mobile …
AGMASO 1a217d2
fix: standardize mobile layout padding for consistent spacing
AGMASO 35216e8
fix: include env variable
AGMASO 35cef78
feat: implement Figma design for asset category filter buttons
AGMASO 5891f19
chore(i18n): regenerate catalogs after merge
AGMASO 2bd45f4
refactor: unify CoinGecko category hooks and connect to proxy backend
AGMASO a03613f
fix: resolve locale message merge conflicts
AGMASO c842f01
refactor: create useAssetCategoryFilters hook to reduce code duplication
AGMASO 4728fb0
chore: fetch of categories in parallel & stale for a week
AGMASO ed6062a
Merge remote-tracking branch 'origin/main' into feat/add-filters
AGMASO 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const CG_ENDPOINT = 'https://pro-api.coingecko.com/api/v3/coins/markets'; | ||
const HEADERS: HeadersInit = { | ||
accept: 'application/json', | ||
'x-cg-pro-api-key': process.env.COINGECKO_API_KEY ?? '', | ||
}; | ||
interface CoinGeckoCoin { | ||
id: string; | ||
symbol: string; | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const allowedOrigins = ['https://app.aave.com', 'https://aave.com']; | ||
const origin = req.headers.origin; | ||
|
||
const isOriginAllowed = (origin: string | undefined): boolean => { | ||
if (!origin) return false; | ||
|
||
if (allowedOrigins.includes(origin)) return true; | ||
|
||
// Match any subdomain ending with avaraxyz.vercel.app for deployment urls | ||
const allowedPatterns = [/^https:\/\/.*avaraxyz\.vercel\.app$/]; | ||
|
||
return allowedPatterns.some((pattern) => pattern.test(origin)); | ||
}; | ||
|
||
if (process.env.CORS_DOMAINS_ALLOWED === 'true') { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
} else if (origin && isOriginAllowed(origin)) { | ||
res.setHeader('Access-Control-Allow-Origin', origin); | ||
} | ||
|
||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); | ||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); | ||
|
||
if (req.method === 'OPTIONS') { | ||
return res.status(200).end(); | ||
} | ||
|
||
if (req.method !== 'GET') { | ||
return res.status(405).json({ error: 'Method not allowed' }); | ||
} | ||
|
||
try { | ||
const coingeckoApiKey = process.env.COINGECKO_API_KEY; | ||
if (!coingeckoApiKey) { | ||
return res.status(500).json({ error: 'CoinGecko API key is not configured' }); | ||
} | ||
|
||
// Fetch for Stablecoins Category and Eth Correlated Categories | ||
const [resStable1, resStable2, resEth1, resEth2, resEth3] = await Promise.all([ | ||
fetch(`${CG_ENDPOINT}?vs_currency=usd&category=stablecoins&per_page=250&page=1`, { | ||
method: 'GET', | ||
headers: HEADERS, | ||
}), | ||
fetch(`${CG_ENDPOINT}?vs_currency=usd&category=stablecoins&per_page=250&page=2`, { | ||
method: 'GET', | ||
headers: HEADERS, | ||
}), | ||
fetch(`${CG_ENDPOINT}?vs_currency=usd&category=liquid-staked-eth&per_page=250&page=1`, { | ||
method: 'GET', | ||
headers: HEADERS, | ||
}), | ||
fetch(`${CG_ENDPOINT}?vs_currency=usd&category=ether-fi-ecosystem&per_page=250&page=1`, { | ||
method: 'GET', | ||
headers: HEADERS, | ||
}), | ||
fetch(`${CG_ENDPOINT}?vs_currency=usd&category=liquid-staking-tokens&per_page=250&page=1`, { | ||
method: 'GET', | ||
headers: HEADERS, | ||
}), | ||
]); | ||
|
||
if (!resStable1.ok) { | ||
return res.status(resStable1.status).json({ | ||
error: `Error fetching stablecoins page 1`, | ||
details: resStable1.statusText, | ||
}); | ||
} | ||
if (!resStable2.ok) { | ||
return res.status(resStable2.status).json({ | ||
error: `Error fetching stablecoins page 2`, | ||
details: resStable2.statusText, | ||
}); | ||
} | ||
if (!resEth1.ok) { | ||
return res.status(resEth1.status).json({ | ||
error: `Error fetching liquid-staked-eth`, | ||
details: resEth1.statusText, | ||
}); | ||
} | ||
if (!resEth2.ok) { | ||
return res.status(resEth2.status).json({ | ||
error: `Error fetching ether-fi-ecosystem`, | ||
details: resEth2.statusText, | ||
}); | ||
} | ||
if (!resEth3.ok) { | ||
return res.status(resEth3.status).json({ | ||
error: `Error fetching liquid-staking-tokens`, | ||
details: resEth3.statusText, | ||
}); | ||
} | ||
|
||
const [dataStable1, dataStable2, dataEth1, dataEth2, dataEth3] = await Promise.all([ | ||
resStable1.json(), | ||
resStable2.json(), | ||
resEth1.json(), | ||
resEth2.json(), | ||
resEth3.json(), | ||
]); | ||
const combinedData = [...dataStable1, ...dataStable2]; | ||
|
||
const processedSymbols = combinedData | ||
.map((coin: CoinGeckoCoin) => coin.symbol?.toUpperCase()) | ||
.filter((symbol: string) => symbol); | ||
|
||
const uniqueSymbolsStablecoins = [...new Set([...processedSymbols])]; | ||
|
||
// Filter category 'liquid-staking-tokens' to only include coins correlated to ETH | ||
const filteredData3 = dataEth3.filter((coin: CoinGeckoCoin) => { | ||
const symbol = coin.symbol?.toUpperCase(); | ||
return symbol?.includes('ETH'); | ||
}); | ||
|
||
const combinedDataEth = [...dataEth1, ...dataEth2, ...filteredData3]; | ||
|
||
const symbols = combinedDataEth | ||
.map((coin: CoinGeckoCoin) => coin.symbol?.toUpperCase()) | ||
.filter((symbol: string) => symbol); | ||
|
||
const uniqueSymbolsEth = [...new Set([...symbols, 'WETH'])]; | ||
|
||
return res.status(200).json({ uniqueSymbolsStablecoins, uniqueSymbolsEth }); | ||
} catch (error) { | ||
console.error('Coingecko categories proxy error:', error); | ||
return res.status(500).json({ error: 'Internal server error', details: String(error) }); | ||
} | ||
} |
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,87 @@ | ||
import { Trans } from '@lingui/macro'; | ||
import { SxProps, Theme, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material'; | ||
import { AssetCategory } from 'src/modules/markets/utils/assetCategories'; | ||
|
||
interface MarketAssetCategoryFiltersProps { | ||
selectedCategory: AssetCategory; | ||
onCategoryChange: (category: AssetCategory) => void; | ||
sx?: { | ||
buttonGroup?: SxProps<Theme>; | ||
button?: SxProps<Theme>; | ||
}; | ||
} | ||
const categoryLabels = { | ||
[AssetCategory.ALL]: <Trans>All</Trans>, | ||
[AssetCategory.STABLECOINS]: <Trans>Stablecoins</Trans>, | ||
[AssetCategory.ETH_CORRELATED]: <Trans>ETH Correlated</Trans>, | ||
} as const; | ||
const categories = [ | ||
AssetCategory.ALL, | ||
AssetCategory.STABLECOINS, | ||
AssetCategory.ETH_CORRELATED, | ||
] as const; | ||
|
||
export const MarketAssetCategoryFilter = ({ | ||
selectedCategory, | ||
onCategoryChange, | ||
...props | ||
}: MarketAssetCategoryFiltersProps) => { | ||
const handleChange = (_event: React.MouseEvent<HTMLElement>, newCategory: AssetCategory) => { | ||
if (newCategory !== null) { | ||
onCategoryChange(newCategory); | ||
} | ||
}; | ||
|
||
return ( | ||
<ToggleButtonGroup | ||
value={selectedCategory} | ||
exclusive | ||
onChange={handleChange} | ||
aria-label="Asset category" | ||
sx={{ | ||
width: '100%', | ||
height: '36px', | ||
'&.MuiToggleButtonGroup-grouped': { | ||
borderRadius: 'unset', | ||
}, | ||
...props.sx?.buttonGroup, | ||
}} | ||
> | ||
{categories.map((category) => ( | ||
<ToggleButton | ||
key={category} | ||
value={category} | ||
disableRipple | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
sx={(theme): SxProps<Theme> | undefined => ({ | ||
flex: { xs: 1, xsm: 1, sm: 'auto' }, | ||
'&.MuiToggleButtonGroup-grouped:not(.Mui-selected), &.MuiToggleButtonGroup-grouped&.Mui-disabled': | ||
{ | ||
border: '1px solid transparent', | ||
backgroundColor: 'background.surface', | ||
color: 'action.disabled', | ||
}, | ||
'&.MuiToggleButtonGroup-grouped&.Mui-selected': { | ||
borderRadius: '4px', | ||
border: `1px solid ${theme.palette.divider}`, | ||
boxShadow: '0px 2px 1px rgba(0, 0, 0, 0.05), 0px 0px 1px rgba(0, 0, 0, 0.25)', | ||
backgroundColor: 'background.paper', | ||
}, | ||
...props.sx?.button, | ||
})} | ||
> | ||
<Typography | ||
variant="buttonM" | ||
sx={{ | ||
fontSize: '0.875rem', | ||
whiteSpace: 'nowrap', | ||
}} | ||
> | ||
{categoryLabels[category]} | ||
</Typography> | ||
</ToggleButton> | ||
))} | ||
</ToggleButtonGroup> | ||
); | ||
}; |
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,110 @@ | ||
import { SearchIcon } from '@heroicons/react/solid'; | ||
import { Trans } from '@lingui/macro'; | ||
import { | ||
Box, | ||
Button, | ||
IconButton, | ||
SvgIcon, | ||
Typography, | ||
TypographyProps, | ||
useMediaQuery, | ||
useTheme, | ||
} from '@mui/material'; | ||
import { ReactNode, useState } from 'react'; | ||
import { AssetCategory } from 'src/modules/markets/utils/assetCategories'; | ||
|
||
import { MarketAssetCategoryFilter } from './MarketAssetCategoryFilter'; | ||
import { SearchInput } from './SearchInput'; | ||
|
||
interface TitleWithFiltersAndSearchBarProps<C extends React.ElementType> { | ||
onSearchTermChange: (value: string) => void; | ||
searchPlaceholder: string; | ||
titleProps?: TypographyProps<C, { component?: C }>; | ||
title: ReactNode; | ||
selectedCategory: AssetCategory; | ||
onCategoryChange: (category: AssetCategory) => void; | ||
} | ||
|
||
export const TitleWithFiltersAndSearchBar = <T extends React.ElementType>({ | ||
onSearchTermChange, | ||
searchPlaceholder, | ||
titleProps, | ||
title, | ||
selectedCategory, | ||
onCategoryChange, | ||
}: TitleWithFiltersAndSearchBarProps<T>) => { | ||
const [showSearchBar, setShowSearchBar] = useState(false); | ||
|
||
const { breakpoints } = useTheme(); | ||
const sm = useMediaQuery(breakpoints.down('sm')); | ||
|
||
const showSearchIcon = sm && !showSearchBar; | ||
const showMarketTitle = !sm || !showSearchBar; | ||
|
||
const handleCancelClick = () => { | ||
setShowSearchBar(false); | ||
onSearchTermChange(''); | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
{showMarketTitle && ( | ||
<Typography component="div" variant="h2" sx={{ mr: 4 }} {...titleProps}> | ||
{title} | ||
</Typography> | ||
)} | ||
|
||
<Box | ||
sx={{ | ||
height: '40px', | ||
width: showSearchBar && sm ? '100%' : 'unset', | ||
position: 'relative', | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: 4, | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<MarketAssetCategoryFilter | ||
selectedCategory={selectedCategory} | ||
onCategoryChange={onCategoryChange} | ||
/> | ||
{showSearchIcon && ( | ||
<IconButton onClick={() => setShowSearchBar(true)}> | ||
<SvgIcon> | ||
<SearchIcon /> | ||
</SvgIcon> | ||
</IconButton> | ||
)} | ||
{(showSearchBar || !sm) && ( | ||
<Box sx={{ width: '100%', display: 'flex', justifyContent: 'space-between' }}> | ||
<SearchInput | ||
wrapperSx={{ | ||
width: { | ||
xs: '100%', | ||
sm: '340px', | ||
}, | ||
}} | ||
placeholder={searchPlaceholder} | ||
onSearchTermChange={onSearchTermChange} | ||
/> | ||
{sm && ( | ||
<Button sx={{ ml: 2 }} onClick={() => handleCancelClick()}> | ||
<Typography variant="buttonM"> | ||
<Trans>Cancel</Trans> | ||
</Typography> | ||
</Button> | ||
)} | ||
</Box> | ||
)} | ||
</Box> | ||
</Box> | ||
); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice!