fix(currency-dropdown): remove supported currencies and use symbols constant
This commit is contained in:
parent
a35a894f8c
commit
1767b8e4db
|
@ -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={() => {}} />
|
<DropdownMenu.Item
|
||||||
) : (
|
key={currency}
|
||||||
supportedCurrencies.map(currency => (
|
label={getCurrencyLabel(currency)}
|
||||||
<DropdownMenu.Item
|
onSelect={() => changeCurrencyHandler(currency)}
|
||||||
key={currency}
|
/>
|
||||||
label={getCurrencyLabel(currency)}
|
))}
|
||||||
onSelect={() => changeCurrencyHandler(currency)}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</DropdownMenu.Content>
|
</DropdownMenu.Content>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</XStack>
|
</XStack>
|
||||||
|
|
Loading…
Reference in New Issue