import React, { useState } from 'react' import BigNumber from 'bignumber.js' import Button from '../Button' import { formatCurrency } from 'utils/formatters' import useCreditManagerStore from 'stores/useCreditManagerStore' import useWalletStore from 'stores/useWalletStore' import useCreditAccountPositions from 'hooks/useCreditAccountPositions' import { getTokenDecimals, getTokenSymbol } from 'utils/tokens' import FundAccount from './FundAccount' import useTokenPrices from 'hooks/useTokenPrices' import useAccountStats from 'hooks/useAccountStats' import useMarkets from 'hooks/useMarkets' import ContainerSecondary from 'components/ContainerSecondary' const CreditManager = () => { const [isFund, setIsFund] = useState(false) const address = useWalletStore((s) => s.address) const selectedAccount = useCreditManagerStore((s) => s.selectedAccount) const { data: positionsData, isLoading: isLoadingPositions } = useCreditAccountPositions( selectedAccount ?? '' ) const { data: tokenPrices } = useTokenPrices() const { data: marketsData } = useMarkets() const accountStats = useAccountStats() const getTokenTotalUSDValue = (amount: string, denom: string) => { // early return if prices are not fetched yet if (!tokenPrices) return 0 return ( BigNumber(amount) .div(10 ** getTokenDecimals(denom)) .toNumber() * tokenPrices[denom] ) } if (!address) { return (