fixed refetchgin of account data (#747)
Co-authored-by: Linkie Link <linkielink.dev@gmail.com>
This commit is contained in:
parent
957b44a153
commit
74c9a41a8b
@ -9,15 +9,15 @@ import DisplayCurrency from 'components/common/DisplayCurrency'
|
||||
import Divider from 'components/common/Divider'
|
||||
import { FormattedNumber } from 'components/common/FormattedNumber'
|
||||
import { ArrowRight, InfoCircle } from 'components/common/Icons'
|
||||
import Modal from 'components/Modals/Modal'
|
||||
import Switch from 'components/common/Switch'
|
||||
import Text from 'components/common/Text'
|
||||
import TitleAndSubCell from 'components/common/TitleAndSubCell'
|
||||
import TokenInputWithSlider from 'components/common/TokenInput/TokenInputWithSlider'
|
||||
import Modal from 'components/Modals/Modal'
|
||||
import { BN_ZERO } from 'constants/math'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useMarketAssets from 'hooks/markets/useMarketAssets'
|
||||
import useAutoLend from 'hooks/useAutoLend'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useHealthComputer from 'hooks/useHealthComputer'
|
||||
import useToggle from 'hooks/useToggle'
|
||||
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
||||
|
@ -2,7 +2,7 @@ import { useCallback } from 'react'
|
||||
|
||||
import AssetAmountSelectActionModal from 'components/Modals/AssetAmountSelectActionModal'
|
||||
import DetailsHeader from 'components/Modals/LendAndReclaim/DetailsHeader'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal'
|
||||
import { useUpdatedAccount } from 'hooks/useUpdatedAccount'
|
||||
import useStore from 'store'
|
||||
|
@ -3,13 +3,13 @@ import { useCallback, useMemo } from 'react'
|
||||
|
||||
import DoubleLogo from 'components/common/DoubleLogo'
|
||||
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 VaultModalContent from 'components/Modals/Vault/VaultModalContent'
|
||||
import VaultModalContentHeader from 'components/Modals/Vault/VaultModalContentHeader'
|
||||
import Text from 'components/common/Text'
|
||||
import { Tooltip } from 'components/common/Tooltip'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAsset from 'hooks/assets/useAsset'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useStore from 'store'
|
||||
|
||||
export default function VaultModalController() {
|
||||
|
@ -8,7 +8,7 @@ import ActionButton from 'components/common/Button/ActionButton'
|
||||
import Card from 'components/common/Card'
|
||||
import Table from 'components/common/Table'
|
||||
import ConditionalWrapper from 'hocs/ConditionalWrapper'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useStore from 'store'
|
||||
import { getPage, getRoute } from 'utils/route'
|
||||
|
||||
|
@ -42,7 +42,7 @@ export default function AccountComposition(props: Props) {
|
||||
const { data: prices } = usePrices()
|
||||
const { data: hlsStrategies } = useHLSStakingAssets()
|
||||
const assets = useAllAssets()
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
|
||||
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
|
||||
useLendingMarketAssetsTableData()
|
||||
|
@ -20,6 +20,7 @@ import { LocalStorageKeys } from 'constants/localStorageKeys'
|
||||
import { ORACLE_DENOM } from 'constants/oracle'
|
||||
import useAccountIds from 'hooks/accounts/useAccountIds'
|
||||
import useAccounts from 'hooks/accounts/useAccounts'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAllAssets from 'hooks/assets/useAllAssets'
|
||||
import useLocalStorage from 'hooks/localStorage/useLocalStorage'
|
||||
import useAccountId from 'hooks/useAccountId'
|
||||
@ -92,7 +93,7 @@ function AccountDetails(props: Props) {
|
||||
return updatedLeverage
|
||||
}, [updatedAccount, prices, leverage, assets])
|
||||
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
|
||||
|
||||
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
|
||||
|
@ -5,8 +5,8 @@ import Card from 'components/common/Card'
|
||||
import { CircularProgress } from 'components/common/CircularProgress'
|
||||
import FullOverlayContent from 'components/common/FullOverlayContent'
|
||||
import useAccounts from 'hooks/accounts/useAccounts'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAccountId from 'hooks/useAccountId'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useStore from 'store'
|
||||
|
||||
export default function AccountFundFullPage() {
|
||||
|
@ -33,7 +33,7 @@ export default function AccountStats(props: Props) {
|
||||
[account, assets, prices],
|
||||
)
|
||||
const { health, healthFactor } = useHealthComputer(account)
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
|
||||
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
|
||||
useLendingMarketAssetsTableData()
|
||||
|
@ -45,7 +45,7 @@ export default function AccountSummary(props: Props) {
|
||||
: BN_ZERO,
|
||||
[props.account, updatedAccount, prices, assets],
|
||||
)
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
|
||||
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
|
||||
useLendingMarketAssetsTableData()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import AccountSummary from 'components/account/AccountSummary'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
|
||||
function CurrentAccountSummary() {
|
||||
const account = useCurrentAccount()
|
||||
|
@ -5,7 +5,7 @@ import useBorrowEnabledAssets from 'hooks/assets/useBorrowEnabledAssets'
|
||||
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
|
||||
|
||||
export default function Borrowings() {
|
||||
const { data } = useBorrowMarketAssetsTableData()
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
|
||||
if (!data?.allAssets?.length) {
|
||||
return <Fallback />
|
||||
|
@ -3,7 +3,8 @@ import { useSearchParams } from 'react-router-dom'
|
||||
|
||||
import DropDownButton from 'components/common/Button/DropDownButton'
|
||||
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 { SearchParams } from 'types/enums/searchParams'
|
||||
import { getSearchParamsObject } from 'utils/route'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import { BN_ZERO } from 'constants/math'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAllAssets from 'hooks/assets/useAllAssets'
|
||||
import usePerpsEnabledAssets from 'hooks/assets/usePerpsEnabledAssets'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import usePrices from 'hooks/usePrices'
|
||||
import { getAccountNetValue } from 'utils/accounts'
|
||||
import { byDenom } from 'utils/array'
|
||||
|
@ -2,10 +2,10 @@ import { useCallback, useMemo } from 'react'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
|
||||
import { BN_ZERO } from 'constants/math'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAllAssets from 'hooks/assets/useAllAssets'
|
||||
import usePerpPosition from 'hooks/perps/usePerpPosition'
|
||||
import usePerpsAsset from 'hooks/perps/usePerpsAsset'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import usePrice from 'hooks/usePrice'
|
||||
import usePrices from 'hooks/usePrices'
|
||||
import { SearchParams } from 'types/enums/searchParams'
|
||||
|
@ -4,11 +4,11 @@ import { useCallback, useMemo } from 'react'
|
||||
import AssetAmount from 'components/common/assets/AssetAmount'
|
||||
import ActionButton from 'components/common/Button/ActionButton'
|
||||
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 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 { BNCoin } from 'types/classes/BNCoin'
|
||||
import { formatLeverage } from 'utils/formatters'
|
||||
|
@ -15,7 +15,7 @@ interface Props {
|
||||
function Content(props: Props) {
|
||||
const { data: account } = useAccount(props.accountId, true)
|
||||
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssets = useMemo(() => data?.allAssets || [], [data])
|
||||
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
|
||||
|
||||
|
@ -22,7 +22,7 @@ function Content(props: Props) {
|
||||
const { data: account } = useAccount(props.accountId, true)
|
||||
const { data: prices } = usePrices()
|
||||
const { health, healthFactor } = useHealthComputer(account)
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssets = useMemo(() => data?.allAssets || [], [data])
|
||||
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
|
||||
const { data: hlsStrategies } = useHLSStakingAssets()
|
||||
|
@ -35,7 +35,7 @@ export default function PortfolioCard(props: Props) {
|
||||
const { data: prices } = usePrices()
|
||||
const currentAccountId = useAccountId()
|
||||
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const { data: hlsStrategies } = useHLSStakingAssets()
|
||||
const [searchParams] = useSearchParams()
|
||||
const assets = useAllAssets()
|
||||
|
@ -19,7 +19,7 @@ export default function PortfolioSummary() {
|
||||
const { address: urlAddress } = useParams()
|
||||
const walletAddress = useStore((s) => s.address)
|
||||
const { data: prices } = usePrices()
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssets = useMemo(() => data?.allAssets || [], [data])
|
||||
const { allAssets: lendingAssets } = useLendingMarketAssetsTableData()
|
||||
const { data: accounts } = useAccounts('default', urlAddress || walletAddress)
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import AccountBalancesTable from 'components/account/AccountBalancesTable'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useBorrowMarketAssetsTableData from 'hooks/useBorrowMarketAssetsTableData'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
|
||||
|
||||
export default function AccountDetailsCard() {
|
||||
const account = useCurrentAccount()
|
||||
const { data } = useBorrowMarketAssetsTableData(false)
|
||||
const data = useBorrowMarketAssetsTableData()
|
||||
const borrowAssetsData = useMemo(() => data?.allAssets || [], [data])
|
||||
const { availableAssets: lendingAvailableAssets, accountLentAssets } =
|
||||
useLendingMarketAssetsTableData()
|
||||
|
@ -4,10 +4,10 @@ import { useMemo } from 'react'
|
||||
import { ChevronDown } from 'components/common/Icons'
|
||||
import Text from 'components/common/Text'
|
||||
import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
|
||||
import useMarketAssets from 'hooks/markets/useMarketAssets'
|
||||
import useMarketDeposits from 'hooks/markets/useMarketDeposits'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import usePrices from 'hooks/usePrices'
|
||||
import useStore from 'store'
|
||||
import { getMergedBalancesForAsset } from 'utils/accounts'
|
||||
|
@ -2,11 +2,11 @@ import { useMemo } from 'react'
|
||||
|
||||
import Text from 'components/common/Text'
|
||||
import AssetSelectorItem from 'components/trade/TradeModule/AssetSelector/AssetSelectorItem'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useBaseAsset from 'hooks/assets/useBasetAsset'
|
||||
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
|
||||
import useMarketAssets from 'hooks/markets/useMarketAssets'
|
||||
import useMarketDeposits from 'hooks/markets/useMarketDeposits'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import usePrices from 'hooks/usePrices'
|
||||
import { getMergedBalancesForAsset } from 'utils/accounts'
|
||||
import { byDenom } from 'utils/array'
|
||||
|
@ -19,13 +19,13 @@ import TradeSummary from 'components/trade/TradeModule/SwapForm/TradeSummary'
|
||||
import { DEFAULT_SETTINGS } from 'constants/defaultSettings'
|
||||
import { LocalStorageKeys } from 'constants/localStorageKeys'
|
||||
import { BN_ZERO } from 'constants/math'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useMarketEnabledAssets from 'hooks/assets/useMarketEnabledAssets'
|
||||
import useLocalStorage from 'hooks/localStorage/useLocalStorage'
|
||||
import useMarketAssets from 'hooks/markets/useMarketAssets'
|
||||
import useMarketBorrowings from 'hooks/markets/useMarketBorrowings'
|
||||
import useAutoLend from 'hooks/useAutoLend'
|
||||
import useChainConfig from 'hooks/useChainConfig'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useHealthComputer from 'hooks/useHealthComputer'
|
||||
import useSwapRoute from 'hooks/useSwapRoute'
|
||||
import useToggle from 'hooks/useToggle'
|
||||
|
11
src/hooks/accounts/useCurrentAccount.tsx
Normal file
11
src/hooks/accounts/useCurrentAccount.tsx
Normal 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])
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import { byDenom } from 'utils/array'
|
||||
|
||||
export default function usePerpPosition(denom: string): PerpsPosition | undefined {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import useAccounts from 'hooks/accounts/useAccounts'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
import useAutoLendEnabledAccountIds from 'hooks/localStorage/useAutoLendEnabledAccountIds'
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
|
||||
export default function useAutoLend(): {
|
||||
autoLendEnabledAccountIds: string[]
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import useMarketAssets from 'hooks/markets/useMarketAssets'
|
||||
|
||||
export default function useBorrowEnabledMarkets() {
|
||||
const { data: markets } = useMarketAssets()
|
||||
return markets.filter((market) => market.borrowEnabled)
|
||||
return useMemo(() => markets.filter((market) => market.borrowEnabled), [markets])
|
||||
}
|
||||
|
@ -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 useMarketBorrowings from 'hooks/markets/useMarketBorrowings'
|
||||
import useMarketDeposits from 'hooks/markets/useMarketDeposits'
|
||||
import useMarketLiquidities from 'hooks/markets/useMarketLiquidities'
|
||||
import useBorrowEnabledMarkets from 'hooks/useBorrowEnabledMarkets'
|
||||
import useCurrentAccountDebts from 'hooks/useCurrentAccountDebts'
|
||||
import { byDenom } from 'utils/array'
|
||||
import { BN } from 'utils/helpers'
|
||||
|
||||
export default function useBorrowMarketAssetsTableData(suspense = true) {
|
||||
export default function useBorrowMarketAssetsTableData() {
|
||||
const markets = useBorrowEnabledMarkets()
|
||||
const accountDebts = useCurrentAccountDebts()
|
||||
const account = useCurrentAccount()
|
||||
const { data: borrowData } = useMarketBorrowings()
|
||||
const { data: marketDeposits } = useMarketDeposits()
|
||||
const { data: marketLiquidities } = useMarketLiquidities()
|
||||
const assets = useAllAssets()
|
||||
|
||||
return useSWR(
|
||||
'borrowMarketAssetsTableData',
|
||||
async (): Promise<{
|
||||
return useMemo((): {
|
||||
accountBorrowedAssets: BorrowMarketTableData[]
|
||||
availableAssets: BorrowMarketTableData[]
|
||||
allAssets: BorrowMarketTableData[]
|
||||
}> => {
|
||||
} => {
|
||||
const accountBorrowedAssets: BorrowMarketTableData[] = [],
|
||||
availableAssets: BorrowMarketTableData[] = []
|
||||
|
||||
@ -33,7 +31,7 @@ export default function useBorrowMarketAssetsTableData(suspense = true) {
|
||||
const marketDepositAmount = BN(marketDeposits.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
|
||||
|
||||
const borrowMarketAsset: BorrowMarketTableData = {
|
||||
@ -53,9 +51,5 @@ export default function useBorrowMarketAssetsTableData(suspense = true) {
|
||||
availableAssets,
|
||||
allAssets: [...accountBorrowedAssets, ...availableAssets],
|
||||
}
|
||||
},
|
||||
{
|
||||
suspense,
|
||||
},
|
||||
)
|
||||
}, [account?.debts, assets, borrowData, marketDeposits, marketLiquidities, markets])
|
||||
}
|
||||
|
@ -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])
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
|
||||
export default function useCurrentAccountDebts() {
|
||||
const account = useCurrentAccount()
|
||||
return account?.debts ?? []
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
|
||||
export default function useCurrentAccountDeposits() {
|
||||
const account = useCurrentAccount()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import useCurrentAccount from 'hooks/useCurrentAccount'
|
||||
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
|
||||
|
||||
export default function useCurrentAccountLends() {
|
||||
const account = useCurrentAccount()
|
||||
|
Loading…
Reference in New Issue
Block a user