2023-08-25 08:57:55 -07:00
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { MANGO_DATA_API_URL } from 'utils/constants'
|
|
|
|
|
2023-08-28 06:35:42 -07:00
|
|
|
const fetchAllHiddenMangoAccounts = async (): Promise<string[]> => {
|
2023-08-25 08:57:55 -07:00
|
|
|
try {
|
|
|
|
const hideResponse = await fetch(
|
|
|
|
`${MANGO_DATA_API_URL}/user-data/private-accounts`,
|
|
|
|
)
|
|
|
|
const res = await hideResponse.json()
|
|
|
|
return res?.private_accounts ?? []
|
|
|
|
} catch (e) {
|
2023-08-28 06:35:42 -07:00
|
|
|
console.error('Failed to fetch private mango accounts', e)
|
|
|
|
return []
|
2023-08-25 08:57:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useHiddenMangoAccounts() {
|
2023-11-13 20:41:16 -08:00
|
|
|
const { data: hiddenAccounts, isInitialLoading: loadingHiddenAccounts } =
|
|
|
|
useQuery(['all-hidden-accounts'], () => fetchAllHiddenMangoAccounts(), {
|
2023-08-25 08:57:55 -07:00
|
|
|
cacheTime: 1000 * 60 * 10,
|
|
|
|
staleTime: 1000 * 60,
|
|
|
|
retry: 3,
|
|
|
|
refetchOnWindowFocus: false,
|
2023-11-13 20:41:16 -08:00
|
|
|
})
|
2023-08-25 08:57:55 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
hiddenAccounts,
|
|
|
|
loadingHiddenAccounts,
|
|
|
|
}
|
|
|
|
}
|