Only re-reg push noty token when account changes (#2654)

zio/stable
Eric Bailey 2024-02-05 16:41:14 -06:00 committed by GitHub
parent 5ee802bb1f
commit 96f39657d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 6 deletions

View File

@ -52,6 +52,8 @@ function ShellInner() {
const canGoBack = useNavigationState(state => !isStateAtTabRoot(state)) const canGoBack = useNavigationState(state => !isStateAtTabRoot(state))
const {hasSession, currentAccount} = useSession() const {hasSession, currentAccount} = useSession()
const closeAnyActiveElement = useCloseAnyActiveElement() const closeAnyActiveElement = useCloseAnyActiveElement()
// start undefined
const currentAccountDid = React.useRef<string | undefined>(undefined)
React.useEffect(() => { React.useEffect(() => {
let listener = {remove() {}} let listener = {remove() {}}
@ -66,13 +68,10 @@ function ShellInner() {
}, [closeAnyActiveElement]) }, [closeAnyActiveElement])
React.useEffect(() => { React.useEffect(() => {
if (currentAccount) { // only runs when did changes
if (currentAccount && currentAccountDid.current !== currentAccount.did) {
currentAccountDid.current = currentAccount.did
notifications.requestPermissionsAndRegisterToken(currentAccount) notifications.requestPermissionsAndRegisterToken(currentAccount)
}
}, [currentAccount])
React.useEffect(() => {
if (currentAccount) {
const unsub = notifications.registerTokenChangeHandler(currentAccount) const unsub = notifications.registerTokenChangeHandler(currentAccount)
return unsub return unsub
} }