c4f8f4eab0
* MP-1757: implemented the WalletProvider and connect buttons * tidy: tidy up the search * MP-1691: moved modals outside of the DOM * MP-1691: changed CreditManager into AccountDetails * fix: fixed the naming * MP-1691: UX approvements * MP-1691: global confirm and delete modal added * fix: merged the credit-account and wallet branch * MP-1757: added the status store * fix: updated the store interaction * MP-1757: major cleanup of stores * tidy: format
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import { Coin } from '@cosmjs/stargate'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useMemo } from 'react'
|
|
|
|
import { contractAddresses } from 'config/contracts'
|
|
import { useWalletStore } from 'stores'
|
|
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.signingClient)
|
|
|
|
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(() => {
|
|
if (!address) return
|
|
|
|
return result?.data && { ...result.data }
|
|
}, [result.data, address]),
|
|
}
|
|
}
|
|
|
|
export default useCreditAccountPositions
|