fixed refetchgin of account data (#747)

Co-authored-by: Linkie Link <linkielink.dev@gmail.com>
This commit is contained in:
Bob van der Helm 2024-01-24 17:06:12 +01:00 committed by GitHub
parent 957b44a153
commit 74c9a41a8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 84 additions and 92 deletions

View File

@ -9,15 +9,15 @@ import DisplayCurrency from 'components/common/DisplayCurrency'
import Divider from 'components/common/Divider' import Divider from 'components/common/Divider'
import { FormattedNumber } from 'components/common/FormattedNumber' import { FormattedNumber } from 'components/common/FormattedNumber'
import { ArrowRight, InfoCircle } from 'components/common/Icons' import { ArrowRight, InfoCircle } from 'components/common/Icons'
import Modal from 'components/Modals/Modal'
import Switch from 'components/common/Switch' import Switch from 'components/common/Switch'
import Text from 'components/common/Text' import Text from 'components/common/Text'
import TitleAndSubCell from 'components/common/TitleAndSubCell' import TitleAndSubCell from 'components/common/TitleAndSubCell'
import TokenInputWithSlider from 'components/common/TokenInput/TokenInputWithSlider' import TokenInputWithSlider from 'components/common/TokenInput/TokenInputWithSlider'
import Modal from 'components/Modals/Modal'
import { BN_ZERO } from 'constants/math' import { BN_ZERO } from 'constants/math'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useMarketAssets from 'hooks/markets/useMarketAssets' import useMarketAssets from 'hooks/markets/useMarketAssets'
import useAutoLend from 'hooks/useAutoLend' import useAutoLend from 'hooks/useAutoLend'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useHealthComputer from 'hooks/useHealthComputer' import useHealthComputer from 'hooks/useHealthComputer'
import useToggle from 'hooks/useToggle' import useToggle from 'hooks/useToggle'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount' import { useUpdatedAccount } from 'hooks/useUpdatedAccount'

View File

@ -2,7 +2,7 @@ import { useCallback } from 'react'
import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal' import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal'
import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader' import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader'
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal' import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal'
import { useUpdatedAccount } from 'hooks/useUpdatedAccount' import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
import useStore from 'store' import useStore from 'store'

View File

@ -3,13 +3,13 @@ import { useCallback, useMemo } from 'react'
import DoubleLogo from 'components/common/DoubleLogo' import DoubleLogo from 'components/common/DoubleLogo'
import { InfoCircle } from 'components/common/Icons' import { InfoCircle } from 'components/common/Icons'
import Text from 'components/common/Text'
import { Tooltip } from 'components/common/Tooltip'
import Modal from 'components/Modals/Modal' import Modal from 'components/Modals/Modal'
import VaultModalContent from 'components/Modals/Vault/VaultModalContent' import VaultModalContent from 'components/Modals/Vault/VaultModalContent'
import VaultModalContentHeader from 'components/Modals/Vault/VaultModalContentHeader' import VaultModalContentHeader from 'components/Modals/Vault/VaultModalContentHeader'
import Text from 'components/common/Text' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import { Tooltip } from 'components/common/Tooltip'
import useAsset from 'hooks/assets/useAsset' import useAsset from 'hooks/assets/useAsset'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useStore from 'store' import useStore from 'store'
export default function VaultModalController() { export default function VaultModalController() {

View File

@ -8,7 +8,7 @@ import ActionButton from 'components/common/Button/ActionButton'
import Card from 'components/common/Card' import Card from 'components/common/Card'
import Table from 'components/common/Table' import Table from 'components/common/Table'
import ConditionalWrapper from 'hocs/ConditionalWrapper' import ConditionalWrapper from 'hocs/ConditionalWrapper'
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useStore from 'store' import useStore from 'store'
import { getPage, getRoute } from 'utils/route' import { getPage, getRoute } from 'utils/route'

View File

@ -42,7 +42,7 @@ export default function AccountComposition(props: Props) {
const { data: prices } = usePrices() const { data: prices } = usePrices()
const { data: hlsStrategies } = useHLSStakingAssets() const { data: hlsStrategies } = useHLSStakingAssets()
const assets = useAllAssets() const assets = useAllAssets()
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
const { availableAssets: lendingAvailableAssets, accountLentAssets } = const { availableAssets: lendingAvailableAssets, accountLentAssets } =
useLendingMarketAssetsTableData() useLendingMarketAssetsTableData()

View File

@ -20,6 +20,7 @@ import { LocalStorageKeys } from 'constants/localStorageKeys'
import { ORACLE_DENOM } from 'constants/oracle' import { ORACLE_DENOM } from 'constants/oracle'
import useAccountIds from 'hooks/accounts/useAccountIds' import useAccountIds from 'hooks/accounts/useAccountIds'
import useAccounts from 'hooks/accounts/useAccounts' import useAccounts from 'hooks/accounts/useAccounts'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAllAssets from 'hooks/assets/useAllAssets' import useAllAssets from 'hooks/assets/useAllAssets'
import useLocalStorage from 'hooks/localStorage/useLocalStorage' import useLocalStorage from 'hooks/localStorage/useLocalStorage'
import useAccountId from 'hooks/useAccountId' import useAccountId from 'hooks/useAccountId'
@ -92,7 +93,7 @@ function AccountDetails(props: Props) {
return updatedLeverage return updatedLeverage
}, [updatedAccount, prices, leverage, assets]) }, [updatedAccount, prices, leverage, assets])
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
const { availableAssets: lendingAvailableAssets, accountLentAssets } = const { availableAssets: lendingAvailableAssets, accountLentAssets } =

View File

@ -5,8 +5,8 @@ import Card from 'components/common/Card'
import { CircularProgress } from 'components/common/CircularProgress' import { CircularProgress } from 'components/common/CircularProgress'
import FullOverlayContent from 'components/common/FullOverlayContent' import FullOverlayContent from 'components/common/FullOverlayContent'
import useAccounts from 'hooks/accounts/useAccounts' import useAccounts from 'hooks/accounts/useAccounts'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAccountId from 'hooks/useAccountId' import useAccountId from 'hooks/useAccountId'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useStore from 'store' import useStore from 'store'
export default function AccountFundFullPage() { export default function AccountFundFullPage() {

View File

@ -33,7 +33,7 @@ export default function AccountStats(props: Props) {
[account, assets, prices], [account, assets, prices],
) )
const { health, healthFactor } = useHealthComputer(account) const { health, healthFactor } = useHealthComputer(account)
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
const { availableAssets: lendingAvailableAssets, accountLentAssets } = const { availableAssets: lendingAvailableAssets, accountLentAssets } =
useLendingMarketAssetsTableData() useLendingMarketAssetsTableData()

View File

@ -45,7 +45,7 @@ export default function AccountSummary(props: Props) {
: BN_ZERO, : BN_ZERO,
[props.account, updatedAccount, prices, assets], [props.account, updatedAccount, prices, assets],
) )
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
const { availableAssets: lendingAvailableAssets, accountLentAssets } = const { availableAssets: lendingAvailableAssets, accountLentAssets } =
useLendingMarketAssetsTableData() useLendingMarketAssetsTableData()

View File

@ -1,5 +1,5 @@
import AccountSummary from 'components/account/AccountSummary' import AccountSummary from 'components/account/AccountSummary'
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
function CurrentAccountSummary() { function CurrentAccountSummary() {
const account = useCurrentAccount() const account = useCurrentAccount()

View File

@ -5,7 +5,7 @@ import useBorrowEnabledAssets from 'hooks/assets/useBorrowEnabledAssets'
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData' import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
export default function Borrowings() { export default function Borrowings() {
const { data } = useBorrowMarketAssetsTableData() const data = useBorrowMarketAssetsTableData()
if (!data?.allAssets?.length) { if (!data?.allAssets?.length) {
return <Fallback /> return <Fallback />

View File

@ -3,7 +3,8 @@ import { useSearchParams } from 'react-router-dom'
import DropDownButton from 'components/common/Button/DropDownButton' import DropDownButton from 'components/common/Button/DropDownButton'
import { Cross, Edit } from 'components/common/Icons' import { Cross, Edit } from 'components/common/Icons'
import useCurrentAccount from 'hooks/useCurrentAccount' import { PerpPositionRow } from 'components/perps/BalancesTable/usePerpsBalancesData'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useStore from 'store' import useStore from 'store'
import { SearchParams } from 'types/enums/searchParams' import { SearchParams } from 'types/enums/searchParams'
import { getSearchParamsObject } from 'utils/route' import { getSearchParamsObject } from 'utils/route'

View File

@ -1,9 +1,9 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import { BN_ZERO } from 'constants/math' import { BN_ZERO } from 'constants/math'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAllAssets from 'hooks/assets/useAllAssets' import useAllAssets from 'hooks/assets/useAllAssets'
import usePerpsEnabledAssets from 'hooks/assets/usePerpsEnabledAssets' import usePerpsEnabledAssets from 'hooks/assets/usePerpsEnabledAssets'
import useCurrentAccount from 'hooks/useCurrentAccount'
import usePrices from 'hooks/usePrices' import usePrices from 'hooks/usePrices'
import { getAccountNetValue } from 'utils/accounts' import { getAccountNetValue } from 'utils/accounts'
import { byDenom } from 'utils/array' import { byDenom } from 'utils/array'

View File

@ -2,10 +2,10 @@ import { useCallback, useMemo } from 'react'
import { useSearchParams } from 'react-router-dom' import { useSearchParams } from 'react-router-dom'
import { BN_ZERO } from 'constants/math' import { BN_ZERO } from 'constants/math'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAllAssets from 'hooks/assets/useAllAssets' import useAllAssets from 'hooks/assets/useAllAssets'
import usePerpPosition from 'hooks/perps/usePerpPosition' import usePerpPosition from 'hooks/perps/usePerpPosition'
import usePerpsAsset from 'hooks/perps/usePerpsAsset' import usePerpsAsset from 'hooks/perps/usePerpsAsset'
import useCurrentAccount from 'hooks/useCurrentAccount'
import usePrice from 'hooks/usePrice' import usePrice from 'hooks/usePrice'
import usePrices from 'hooks/usePrices' import usePrices from 'hooks/usePrices'
import { SearchParams } from 'types/enums/searchParams' import { SearchParams } from 'types/enums/searchParams'

View File

@ -4,11 +4,11 @@ import { useCallback, useMemo } from 'react'
import AssetAmount from 'components/common/assets/AssetAmount' import AssetAmount from 'components/common/assets/AssetAmount'
import ActionButton from 'components/common/Button/ActionButton' import ActionButton from 'components/common/Button/ActionButton'
import { ArrowRight } from 'components/common/Icons' import { ArrowRight } from 'components/common/Icons'
import TradeDirection from 'components/perps/BalancesTable/Columns/TradeDirection'
import OpeningFee from 'components/perps/Module/OpeningFee'
import SummaryLine from 'components/common/SummaryLine' import SummaryLine from 'components/common/SummaryLine'
import Text from 'components/common/Text' import Text from 'components/common/Text'
import useCurrentAccount from 'hooks/useCurrentAccount' import TradeDirection from 'components/perps/BalancesTable/Columns/TradeDirection'
import OpeningFee from 'components/perps/Module/OpeningFee'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useStore from 'store' import useStore from 'store'
import { BNCoin } from 'types/classes/BNCoin' import { BNCoin } from 'types/classes/BNCoin'
import { formatLeverage } from 'utils/formatters' import { formatLeverage } from 'utils/formatters'

View File

@ -15,7 +15,7 @@ interface Props {
function Content(props: Props) { function Content(props: Props) {
const { data: account } = useAccount(props.accountId, true) const { data: account } = useAccount(props.accountId, true)
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssets = useMemo(() => data?.allAssets || [], [data]) const borrowAssets = useMemo(() => data?.allAssets || [], [data])
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData() const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()

View File

@ -22,7 +22,7 @@ function Content(props: Props) {
const { data: account } = useAccount(props.accountId, true) const { data: account } = useAccount(props.accountId, true)
const { data: prices } = usePrices() const { data: prices } = usePrices()
const { health, healthFactor } = useHealthComputer(account) const { health, healthFactor } = useHealthComputer(account)
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssets = useMemo(() => data?.allAssets || [], [data]) const borrowAssets = useMemo(() => data?.allAssets || [], [data])
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData() const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
const { data: hlsStrategies } = useHLSStakingAssets() const { data: hlsStrategies } = useHLSStakingAssets()

View File

@ -35,7 +35,7 @@ export default function PortfolioCard(props: Props) {
const { data: prices } = usePrices() const { data: prices } = usePrices()
const currentAccountId = useAccountId() const currentAccountId = useAccountId()
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData() const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const { data: hlsStrategies } = useHLSStakingAssets() const { data: hlsStrategies } = useHLSStakingAssets()
const [searchParams] = useSearchParams() const [searchParams] = useSearchParams()
const assets = useAllAssets() const assets = useAllAssets()

View File

@ -19,7 +19,7 @@ export default function PortfolioSummary() {
const { address: urlAddress } = useParams() const { address: urlAddress } = useParams()
const walletAddress = useStore((s) => s.address) const walletAddress = useStore((s) => s.address)
const { data: prices } = usePrices() const { data: prices } = usePrices()
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssets = useMemo(() => data?.allAssets || [], [data]) const borrowAssets = useMemo(() => data?.allAssets || [], [data])
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData() const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
const { data: accounts } = useAccounts('default', urlAddress || walletAddress) const { data: accounts } = useAccounts('default', urlAddress || walletAddress)

View File

@ -1,13 +1,13 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import AccountBalancesTable from 'components/account/AccountBalancesTable' import AccountBalancesTable from 'components/account/AccountBalancesTable'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData' import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData' import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
export default function AccountDetailsCard() { export default function AccountDetailsCard() {
const account = useCurrentAccount() const account = useCurrentAccount()
const { data } = useBorrowMarketAssetsTableData(false) const data = useBorrowMarketAssetsTableData()
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data]) const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
const { availableAssets: lendingAvailableAssets, accountLentAssets } = const { availableAssets: lendingAvailableAssets, accountLentAssets } =
useLendingMarketAssetsTableData() useLendingMarketAssetsTableData()

View File

@ -4,10 +4,10 @@ import { useMemo } from 'react'
import { ChevronDown } from 'components/common/Icons' import { ChevronDown } from 'components/common/Icons'
import Text from 'components/common/Text' import Text from 'components/common/Text'
import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem' import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets' import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
import useMarketAssets from 'hooks/markets/useMarketAssets' import useMarketAssets from 'hooks/markets/useMarketAssets'
import useMarketDeposits from 'hooks/markets/useMarketDeposits' import useMarketDeposits from 'hooks/markets/useMarketDeposits'
import useCurrentAccount from 'hooks/useCurrentAccount'
import usePrices from 'hooks/usePrices' import usePrices from 'hooks/usePrices'
import useStore from 'store' import useStore from 'store'
import { getMergedBalancesForAsset } from 'utils/accounts' import { getMergedBalancesForAsset } from 'utils/accounts'

View File

@ -2,11 +2,11 @@ import { useMemo } from 'react'
import Text from 'components/common/Text' import Text from 'components/common/Text'
import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem' import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useBaseAsset from 'hooks/assets/useBasetAsset' import useBaseAsset from 'hooks/assets/useBasetAsset'
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets' import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
import useMarketAssets from 'hooks/markets/useMarketAssets' import useMarketAssets from 'hooks/markets/useMarketAssets'
import useMarketDeposits from 'hooks/markets/useMarketDeposits' import useMarketDeposits from 'hooks/markets/useMarketDeposits'
import useCurrentAccount from 'hooks/useCurrentAccount'
import usePrices from 'hooks/usePrices' import usePrices from 'hooks/usePrices'
import { getMergedBalancesForAsset } from 'utils/accounts' import { getMergedBalancesForAsset } from 'utils/accounts'
import { byDenom } from 'utils/array' import { byDenom } from 'utils/array'

View File

@ -19,13 +19,13 @@ import TradeSummary from 'components/trade/TradeModule/SwapForm/TradeSummary'
import { DEFAULT_SETTINGS } from 'constants/defaultSettings' import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
import { LocalStorageKeys } from 'constants/localStorageKeys' import { LocalStorageKeys } from 'constants/localStorageKeys'
import { BN_ZERO } from 'constants/math' import { BN_ZERO } from 'constants/math'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets' import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
import useLocalStorage from 'hooks/localStorage/useLocalStorage' import useLocalStorage from 'hooks/localStorage/useLocalStorage'
import useMarketAssets from 'hooks/markets/useMarketAssets' import useMarketAssets from 'hooks/markets/useMarketAssets'
import useMarketBorrowings from 'hooks/markets/useMarketBorrowings' import useMarketBorrowings from 'hooks/markets/useMarketBorrowings'
import useAutoLend from 'hooks/useAutoLend' import useAutoLend from 'hooks/useAutoLend'
import useChainConfig from 'hooks/useChainConfig' import useChainConfig from 'hooks/useChainConfig'
import useCurrentAccount from 'hooks/useCurrentAccount'
import useHealthComputer from 'hooks/useHealthComputer' import useHealthComputer from 'hooks/useHealthComputer'
import useSwapRoute from 'hooks/useSwapRoute' import useSwapRoute from 'hooks/useSwapRoute'
import useToggle from 'hooks/useToggle' import useToggle from 'hooks/useToggle'

View File

@ -0,0 +1,11 @@
import { useMemo } from 'react'
import useAccount from 'hooks/accounts/useAccount'
import useAccountId from 'hooks/useAccountId'
export default function useCurrentAccount(): Account | undefined {
const accountId = useAccountId()
const { data: account } = useAccount(accountId || undefined)
return useMemo(() => account, [account])
}

View File

@ -1,6 +1,6 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import { byDenom } from 'utils/array' import { byDenom } from 'utils/array'
export default function usePerpPosition(denom: string): PerpsPosition | undefined { export default function usePerpPosition(denom: string): PerpsPosition | undefined {

View File

@ -1,6 +1,6 @@
import useAccounts from 'hooks/accounts/useAccounts' import useAccounts from 'hooks/accounts/useAccounts'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAutoLendEnabledAccountIds from 'hooks/localStorage/useAutoLendEnabledAccountIds' import useAutoLendEnabledAccountIds from 'hooks/localStorage/useAutoLendEnabledAccountIds'
import useCurrentAccount from 'hooks/useCurrentAccount'
export default function useAutoLend(): { export default function useAutoLend(): {
autoLendEnabledAccountIds: string[] autoLendEnabledAccountIds: string[]

View File

@ -1,6 +1,8 @@
import { useMemo } from 'react'
import useMarketAssets from 'hooks/markets/useMarketAssets' import useMarketAssets from 'hooks/markets/useMarketAssets'
export default function useBorrowEnabledMarkets() { export default function useBorrowEnabledMarkets() {
const { data: markets } = useMarketAssets() const { data: markets } = useMarketAssets()
return markets.filter((market) => market.borrowEnabled) return useMemo(() => markets.filter((market) => market.borrowEnabled), [markets])
} }

View File

@ -1,29 +1,27 @@
import useSWR from 'swr' import { useMemo } from 'react'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAllAssets from 'hooks/assets/useAllAssets' import useAllAssets from 'hooks/assets/useAllAssets'
import useMarketBorrowings from 'hooks/markets/useMarketBorrowings' import useMarketBorrowings from 'hooks/markets/useMarketBorrowings'
import useMarketDeposits from 'hooks/markets/useMarketDeposits' import useMarketDeposits from 'hooks/markets/useMarketDeposits'
import useMarketLiquidities from 'hooks/markets/useMarketLiquidities' import useMarketLiquidities from 'hooks/markets/useMarketLiquidities'
import useBorrowEnabledMarkets from 'hooks/useBorrowEnabledMarkets' import useBorrowEnabledMarkets from 'hooks/useBorrowEnabledMarkets'
import useCurrentAccountDebts from 'hooks/useCurrentAccountDebts'
import { byDenom } from 'utils/array' import { byDenom } from 'utils/array'
import { BN } from 'utils/helpers' import { BN } from 'utils/helpers'
export default function useBorrowMarketAssetsTableData(suspense = true) { export default function useBorrowMarketAssetsTableData() {
const markets = useBorrowEnabledMarkets() const markets = useBorrowEnabledMarkets()
const accountDebts = useCurrentAccountDebts() const account = useCurrentAccount()
const { data: borrowData } = useMarketBorrowings() const { data: borrowData } = useMarketBorrowings()
const { data: marketDeposits } = useMarketDeposits() const { data: marketDeposits } = useMarketDeposits()
const { data: marketLiquidities } = useMarketLiquidities() const { data: marketLiquidities } = useMarketLiquidities()
const assets = useAllAssets() const assets = useAllAssets()
return useSWR( return useMemo((): {
'borrowMarketAssetsTableData',
async (): Promise<{
accountBorrowedAssets: BorrowMarketTableData[] accountBorrowedAssets: BorrowMarketTableData[]
availableAssets: BorrowMarketTableData[] availableAssets: BorrowMarketTableData[]
allAssets: BorrowMarketTableData[] allAssets: BorrowMarketTableData[]
}> => { } => {
const accountBorrowedAssets: BorrowMarketTableData[] = [], const accountBorrowedAssets: BorrowMarketTableData[] = [],
availableAssets: BorrowMarketTableData[] = [] availableAssets: BorrowMarketTableData[] = []
@ -33,7 +31,7 @@ export default function useBorrowMarketAssetsTableData(suspense = true) {
const marketDepositAmount = BN(marketDeposits.find(byDenom(denom))?.amount ?? 0) const marketDepositAmount = BN(marketDeposits.find(byDenom(denom))?.amount ?? 0)
const marketLiquidityAmount = BN(marketLiquidities.find(byDenom(denom))?.amount ?? 0) const marketLiquidityAmount = BN(marketLiquidities.find(byDenom(denom))?.amount ?? 0)
const debt = accountDebts?.find((debt) => debt.denom === denom) const debt = account?.debts?.find((debt) => debt.denom === denom)
if (!borrow) return if (!borrow) return
const borrowMarketAsset: BorrowMarketTableData = { const borrowMarketAsset: BorrowMarketTableData = {
@ -53,9 +51,5 @@ export default function useBorrowMarketAssetsTableData(suspense = true) {
availableAssets, availableAssets,
allAssets: [...accountBorrowedAssets, ...availableAssets], allAssets: [...accountBorrowedAssets, ...availableAssets],
} }
}, }, [account?.debts, assets, borrowData, marketDeposits, marketLiquidities, markets])
{
suspense,
},
)
} }

View File

@ -1,11 +0,0 @@
import { useMemo } from 'react'
import useAccounts from 'hooks/accounts/useAccounts'
import useAccountId from 'hooks/useAccountId'
export default function useCurrentAccount(): Account | undefined {
const accountId = useAccountId()
const { data: accounts } = useAccounts('default', undefined, false)
return useMemo(() => accounts?.find((account) => account.id === accountId), [accountId, accounts])
}

View File

@ -1,6 +0,0 @@
import useCurrentAccount from 'hooks/useCurrentAccount'
export default function useCurrentAccountDebts() {
const account = useCurrentAccount()
return account?.debts ?? []
}

View File

@ -1,4 +1,4 @@
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
export default function useCurrentAccountDeposits() { export default function useCurrentAccountDeposits() {
const account = useCurrentAccount() const account = useCurrentAccount()

View File

@ -1,4 +1,4 @@
import useCurrentAccount from 'hooks/useCurrentAccount' import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
export default function useCurrentAccountLends() { export default function useCurrentAccountLends() {
const account = useCurrentAccount() const account = useCurrentAccount()