mango-v4-ui/hooks/notifications/useNotificationSettings.ts

28 lines
1015 B
TypeScript
Raw Normal View History

import { useQuery } from '@tanstack/react-query'
import NotificationCookieStore from '@store/notificationCookieStore'
import { useWallet } from '@solana/wallet-adapter-react'
import { fetchNotificationSettings } from 'apis/notifications/notificationSettings'
import { useIsAuthorized } from './useIsAuthorized'
2023-07-13 22:47:05 -07:00
import { DAILY_MILLISECONDS } from 'utils/constants'
import useMangoAccount from 'hooks/useMangoAccount'
export function useNotificationSettings() {
const { publicKey } = useWallet()
const { mangoAccountAddress } = useMangoAccount()
const walletPubKey = publicKey?.toBase58()
const token = NotificationCookieStore((s) => s.currentToken)
const isAuth = useIsAuthorized()
const criteria = [token, isAuth, mangoAccountAddress]
return useQuery(
['notificationSettings', ...criteria],
() => fetchNotificationSettings(walletPubKey!, token!, mangoAccountAddress),
{
enabled: !!isAuth && !!mangoAccountAddress,
retry: 1,
2023-07-13 22:47:05 -07:00
staleTime: DAILY_MILLISECONDS,
2023-07-21 11:47:53 -07:00
},
)
}