mirror of
https://github.com/cerc-io/mars-interface.git
synced 2025-07-01 07:15:19 +00:00
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { Coin } from '@cosmjs/stargate'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { gql, request } from 'graphql-request'
|
|
import useStore from 'store'
|
|
import { QUERY_KEYS } from 'types/enums/queryKeys'
|
|
|
|
export interface SafetyFundBalanceData {
|
|
balance: {
|
|
balance: Coin[]
|
|
}
|
|
}
|
|
|
|
export const useSafetyFundBalance = () => {
|
|
const hiveUrl = useStore((s) => s.networkConfig?.hiveUrl)
|
|
const safetyFundAddress = useStore((s) => s.addressProviderConfig?.safety_fund_address)
|
|
const processSafetyFundQuery = useStore((s) => s.processSafetyFundQuery)
|
|
|
|
useQuery<SafetyFundBalanceData>(
|
|
[QUERY_KEYS.SAFETY_FUND_BALANCE],
|
|
async () => {
|
|
return await request(
|
|
hiveUrl!,
|
|
gql`
|
|
query SafetyFundBalanceQuery {
|
|
balance: bank {
|
|
balance(
|
|
address: "${safetyFundAddress}"
|
|
) {
|
|
amount
|
|
denom
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
)
|
|
},
|
|
{
|
|
enabled: !!hiveUrl && !!safetyFundAddress,
|
|
refetchInterval: 30000,
|
|
onSuccess: processSafetyFundQuery,
|
|
},
|
|
)
|
|
}
|