Skip to content

Commit

Permalink
Add explanation for isInitialized and isInitializedProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 19, 2024
1 parent a496cf1 commit b38e97e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/activity/MyNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const NOTIFICATION_TITLE = 'My notifications'

export const MyNotifications = () => {
const myAddress = useMyAddress()
const isInitializedProxy = useMyAccount(state => state.isInitializedProxy)
const isInitialized = useMyAccount(state => state.isInitialized)

if (!myAddress) return <NotAuthorized />

return (
<PageContent meta={{ title: NOTIFICATION_TITLE }} className={styles.NotificationPage}>
{!isInitializedProxy ? (
{!isInitialized ? (
<Loading center />
) : (
<Notifications title={NOTIFICATION_TITLE} address={myAddress} />
Expand Down
11 changes: 5 additions & 6 deletions src/components/activity/NotifCounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function InnerNotifCounterProvider(props: React.PropsWithChildren<{}>) {
storageKeyType: 'user',
})
const myAddress = useMyAddress()
const isInitializedProxy = useMyAccount(state => state.isInitializedProxy)
const isInitialized = useMyAccount(state => state.isInitialized)

const [unreadCount, setUnreadCount] = useState(0)
const [previousLastRead, setPreviousLastRead] = useState<string | null>(null)
Expand All @@ -47,15 +47,15 @@ function InnerNotifCounterProvider(props: React.PropsWithChildren<{}>) {
}

useEffect(() => {
if (!isInitializedProxy || !myAddress) return
if (!isInitialized || !myAddress) return
;(async () => {
const unreadCount = await getNotificationsCount({
address: myAddress,
afterDate: getDataForAddress(myAddress) || undefined,
})
setUnreadCount(unreadCount)
})()
}, [myAddress, isInitializedProxy])
}, [myAddress, isInitialized])

return (
<NotifCounterContext.Provider
Expand Down Expand Up @@ -99,12 +99,11 @@ const Bell = ({ unreadCount }: NotificationsProps) => (

export const NotificationsBell = ({ unreadCount }: NotificationsProps) => {
const myAddress = useMyAddress()
const isInitializedProxy = useMyAccount(state => state.isInitializedProxy)
const isInitialized = useMyAccount(state => state.isInitialized)
const { getLastReadNotif } = useNotifCounterContext()

if (!enableNotifications) return null
if (!unreadCount || unreadCount <= 0 || !isInitializedProxy)
return <Bell unreadCount={unreadCount} />
if (!unreadCount || unreadCount <= 0 || !isInitialized) return <Bell unreadCount={unreadCount} />

const showWithoutCount = !getLastReadNotif(myAddress)

Expand Down
7 changes: 7 additions & 0 deletions src/stores/my-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import { useAnalytics } from './analytics'
import { create } from './utils'

type State = {
/**
* `isInitialized` is `true` when the addresses (address & parentProxyAddress) are all set
* but there is still a case where the proxy is invalid and user will be logged out after that
*/
isInitialized?: boolean
/**
* `isInitializedProxy` is `true` when the initialization process is all done, including checking the proxy
*/
isInitializedProxy?: boolean

preferredWallet: any | null
Expand Down

0 comments on commit b38e97e

Please sign in to comment.