Skip to content

Commit

Permalink
Fix check
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Jan 2, 2025
1 parent 83ba347 commit 6d049aa
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ import {isString, useAsyncStorage, useMutationWithInvalidations} from '@yoroi/co
import {App} from '@yoroi/types'
import {useQuery} from 'react-query'

import {useSelectedWallet} from '../../../../WalletManager/common/hooks/useSelectedWallet'
import {useWalletManager} from '../../../../WalletManager/context/WalletManagerProvider'

const defaultNotificationsEnabled = true

export const useNotificationDisplaySettings = () => {
const storage = useAsyncStorage()
const selectedWallet = useSelectedWallet()
const selectedWalletId = selectedWallet.wallet.id
const walletManager = useWalletManager()
const selectedWalletId = walletManager.selected.wallet?.id
const query = useQuery({
queryKey: ['settings', selectedWalletId, 'notifications'],
queryFn: () => getNotificationDisplaySettings(storage, selectedWalletId),
queryFn: () => {
if (!isString(selectedWalletId)) return defaultNotificationsEnabled
return getNotificationDisplaySettings(storage, selectedWalletId)
},
enabled: isString(selectedWalletId),
})

return query.data ?? defaultNotificationsEnabled
}

export const useChangeNotificationDisplaySettings = () => {
const storage = useAsyncStorage()
const selectedWallet = useSelectedWallet()
const selectedWalletId = selectedWallet.wallet.id
const mutationFn = (value: boolean) => changeNotificationDisplaySettings(storage, selectedWalletId, value)
const walletManager = useWalletManager()
const selectedWalletId = walletManager.selected.wallet?.id
const mutationFn = async (value: boolean) => {
if (!isString(selectedWalletId)) throw new Error('useChangeNotificationDisplaySettings: No wallet selected')
await changeNotificationDisplaySettings(storage, selectedWalletId, value)
}
return useMutationWithInvalidations({
mutationFn,
invalidateQueries: [['settings', selectedWalletId, 'notifications']],
Expand Down

0 comments on commit 6d049aa

Please sign in to comment.