2023-04-28 14:36:24 -07:00
|
|
|
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'
|
2023-08-01 13:27:12 -07:00
|
|
|
import useMangoAccount from 'hooks/useMangoAccount'
|
2023-04-28 14:36:24 -07:00
|
|
|
|
|
|
|
export function useNotificationSettings() {
|
|
|
|
const { publicKey } = useWallet()
|
2023-08-01 13:27:12 -07:00
|
|
|
const { mangoAccountAddress } = useMangoAccount()
|
2023-04-28 14:36:24 -07:00
|
|
|
const walletPubKey = publicKey?.toBase58()
|
|
|
|
const token = NotificationCookieStore((s) => s.currentToken)
|
|
|
|
const isAuth = useIsAuthorized()
|
|
|
|
|
2023-08-01 13:27:12 -07:00
|
|
|
const criteria = [token, isAuth, mangoAccountAddress]
|
2023-04-28 14:36:24 -07:00
|
|
|
|
|
|
|
return useQuery(
|
2023-08-01 13:27:12 -07:00
|
|
|
['notificationSettings', ...criteria],
|
|
|
|
() => fetchNotificationSettings(walletPubKey!, token!, mangoAccountAddress),
|
2023-04-28 14:36:24 -07:00
|
|
|
{
|
2023-08-01 13:27:12 -07:00
|
|
|
enabled: !!isAuth && !!mangoAccountAddress,
|
2023-04-28 14:36:24 -07:00
|
|
|
retry: 1,
|
2023-07-13 22:47:05 -07:00
|
|
|
staleTime: DAILY_MILLISECONDS,
|
2023-07-21 11:47:53 -07:00
|
|
|
},
|
2023-04-28 14:36:24 -07:00
|
|
|
)
|
|
|
|
}
|