Skip to content

Commit

Permalink
Add extra check for assistant visibility (#594)
Browse files Browse the repository at this point in the history
Closes #576

This PR adds a logic for an extra check of assistant visibility.
  • Loading branch information
xpaczka authored Nov 2, 2023
2 parents 94ba487 + 22e5bd5 commit f43d98b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/shared/hooks/assistant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LOCAL_STORAGE_ASSISTANT } from "shared/constants"
import { selectStakingRealmId, useDappSelector } from "redux-state"
import { useLocalStorageChange } from "./helpers"

type AssistantType = "welcome" | "quests" | "default" | "first-realm"
Expand All @@ -14,12 +15,17 @@ export function useAssistant(): {
updateAssistant: (newValue: Assistant) => void
assistantVisible: (type: AssistantType) => boolean
} {
const isStakedInRealm = useDappSelector(selectStakingRealmId)

const { value, updateStorage } = useLocalStorageChange<Assistant>(
LOCAL_STORAGE_ASSISTANT
)

const assistantVisible = (type: AssistantType): boolean =>
value ? value.visible && value.type === type : false
const assistantVisible = (type: AssistantType): boolean => {
if ((type === "welcome" || type === "first-realm") && isStakedInRealm)
return false
return value ? value.visible && value.type === type : false
}

return { assistant: value, updateAssistant: updateStorage, assistantVisible }
}
5 changes: 1 addition & 4 deletions src/ui/Assistant/AssistantContent/AssistantFirstRealm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from "react"
import { useAssistant, useLocalStorageChange } from "shared/hooks"
import { LOCAL_STORAGE_VISITED_REALM } from "shared/constants"
import { selectStakingRealmId, useDappSelector } from "redux-state"
import AssistantContent from "."

export default function AssistantFirstRealm() {
const isStakedInRealm = useDappSelector(selectStakingRealmId)

const { updateAssistant, assistantVisible } = useAssistant()
const { updateStorage } = useLocalStorageChange<boolean>(
LOCAL_STORAGE_VISITED_REALM
Expand All @@ -20,7 +17,7 @@ export default function AssistantFirstRealm() {
return (
<>
<AssistantContent
isVisible={assistantVisible("first-realm") && !isStakedInRealm}
isVisible={assistantVisible("first-realm")}
close={closeAssistant}
>
<div className="header">Why join a Realm?</div>
Expand Down

0 comments on commit f43d98b

Please sign in to comment.