mars-v2-frontend/hooks/useCreditAccountPositions.tsx
Gustavo Mauricio 18c7547c00
MP-1638: Repay (#35)
* added repay action percentage buffer

* moved repay amount calculation to RepayFunds component

* refetch interval added to credit account positions query

* feat: revamp borrow and repay components to modals

* remove references to deleted components

* cosmo signing client added to wallet store

* amount decimal normalized for borrow action

* amount decimals conversion lifted for borrow and repay

* refactor: moved hooks to mutations folder

* update button disable condition and min input value

* refactor: reset modal states when reopened

* react-number-format dependency and borrow/repay modals revamp

* renamed borrow modal state variable

* style: borrow table ui revamp
2022-10-28 12:14:14 +01:00

55 lines
1.2 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import { Coin } from '@cosmjs/stargate'
import useWalletStore from 'stores/useWalletStore'
import { contractAddresses } from 'config/contracts'
import { queryKeys } from 'types/query-keys-factory'
interface DebtAmount {
amount: string
denom: string
shares: string
}
interface VaultPosition {
locked: string
unlocked: string
}
interface Result {
account_id: string
coins: Coin[]
debts: DebtAmount[]
vaults: VaultPosition[]
}
const useCreditAccountPositions = (accountId: string) => {
const address = useWalletStore((s) => s.address)
const client = useWalletStore((s) => s.client)
const result = useQuery<Result>(
queryKeys.creditAccountsPositions(accountId),
async () =>
client?.queryContractSmart(contractAddresses.creditManager, {
positions: {
account_id: accountId,
},
}),
{
enabled: !!address && !!client,
refetchInterval: 30000,
staleTime: Infinity,
}
)
return {
...result,
data: useMemo(() => {
return result?.data && { ...result.data }
}, [result.data]),
}
}
export default useCreditAccountPositions