fix(currency-dropdown): remove supported currencies and use symbols constant

This commit is contained in:
RadoslavDimchev 2024-04-24 18:18:57 +03:00 committed by Emil Ivanichkov
parent a35a894f8c
commit 1767b8e4db
1 changed files with 7 additions and 39 deletions

View File

@ -14,20 +14,13 @@ type CurrencyDropdownProps = {
const CurrencyDropdown = ({ depositAmount }: CurrencyDropdownProps) => { const CurrencyDropdown = ({ depositAmount }: CurrencyDropdownProps) => {
const [isOpen, setIsOpen] = useState(false) const [isOpen, setIsOpen] = useState(false)
const [supportedCurrencies, setSupportedCurrencies] = useState([])
const [currentCurrencyAmount, setCurrentCurrencyAmount] = useState(0) const [currentCurrencyAmount, setCurrentCurrencyAmount] = useState(0)
const [isCurrencyLoading, setIsCurrencyLoading] = useState(false) const [isCurrencyLoading, setIsCurrencyLoading] = useState(false)
const [isSupportedCurrenciesLoading, setIsSupportedCurrenciesLoading] =
useState(false)
const currency = useSelector((state: RootState) => state.currency) const currency = useSelector((state: RootState) => state.currency)
const dispatch = useDispatch() const dispatch = useDispatch()
const totalPrice = depositAmount * currentCurrencyAmount const totalPrice = depositAmount * currentCurrencyAmount
useEffect(() => {
fetchSupportedCurrencies()
}, [])
useEffect(() => { useEffect(() => {
fetchCurrencyPrice() fetchCurrencyPrice()
}, [currency]) }, [currency])
@ -53,27 +46,6 @@ const CurrencyDropdown = ({ depositAmount }: CurrencyDropdownProps) => {
} }
} }
const fetchSupportedCurrencies = async () => {
try {
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/supported_vs_currencies',
{
headers: {
accept: 'application/json',
'x-cg-demo-api-key': COIN_GECKO_API_KEY,
},
},
)
const newSupportedCurrencies = await response.json()
setSupportedCurrencies(newSupportedCurrencies)
} catch (error) {
console.error(error)
} finally {
setIsSupportedCurrenciesLoading(false)
}
}
const changeIsOpenHandler = (isOpen: boolean) => { const changeIsOpenHandler = (isOpen: boolean) => {
setIsOpen(isOpen) setIsOpen(isOpen)
} }
@ -102,17 +74,13 @@ const CurrencyDropdown = ({ depositAmount }: CurrencyDropdownProps) => {
height={190} height={190}
className={'transparent-scrollbar'} className={'transparent-scrollbar'}
> >
{isSupportedCurrenciesLoading ? ( {Object.keys(currencySymbols).map(currency => (
<DropdownMenu.Item label={LOADING} onSelect={() => {}} />
) : (
supportedCurrencies.map(currency => (
<DropdownMenu.Item <DropdownMenu.Item
key={currency} key={currency}
label={getCurrencyLabel(currency)} label={getCurrencyLabel(currency)}
onSelect={() => changeCurrencyHandler(currency)} onSelect={() => changeCurrencyHandler(currency)}
/> />
)) ))}
)}
</DropdownMenu.Content> </DropdownMenu.Content>
</DropdownMenu> </DropdownMenu>
</XStack> </XStack>