mirror of
https://github.com/acid-info/Kurate.git
synced 2025-02-11 23:36:25 +00:00
feat: logout on metamask account change (#378)
This commit is contained in:
parent
cdec7fce30
commit
e1ef4d74b3
@ -3,7 +3,7 @@ import { chats, type Chat, type Message } from '$lib/stores/chat'
|
||||
import { personas, type DraftPersona, type Persona } from '$lib/stores/persona'
|
||||
import { profile } from '$lib/stores/profile'
|
||||
import { getFromLocalStorage, saveToLocalStorage } from '$lib/utils'
|
||||
import type { Signer } from 'ethers'
|
||||
import type { Signer, providers } from 'ethers'
|
||||
import { create } from 'ipfs-http-client'
|
||||
import {
|
||||
CREATE_PERSONA_GO_PRICE,
|
||||
@ -55,6 +55,9 @@ const app = initializeApp(firebaseConfig)
|
||||
// Initialize Cloud Firestore and get a reference to the service
|
||||
const db = getFirestore(app)
|
||||
|
||||
type WindowWithEthereum = Window &
|
||||
typeof globalThis & { ethereum: providers.ExternalProvider | any }
|
||||
|
||||
function epochCounter(): () => unknown {
|
||||
const interval = setInterval(() => {
|
||||
tokens.update(({ epochDuration, ...rest }) => {
|
||||
@ -154,6 +157,21 @@ export class Firebase implements Adapter {
|
||||
})
|
||||
this.subscriptions.push(unsubscribeUser)
|
||||
this.subscriptions.push(epochCounter())
|
||||
|
||||
const windowWithEthereum = window as WindowWithEthereum
|
||||
if (
|
||||
windowWithEthereum &&
|
||||
windowWithEthereum.ethereum &&
|
||||
typeof windowWithEthereum.ethereum.on === 'function'
|
||||
) {
|
||||
windowWithEthereum.ethereum.on('accountsChanged', () => {
|
||||
profile.set({}) // Clear profile
|
||||
personas.update((state) => ({ ...state, draft: [] }))
|
||||
tokens.update((state) => ({ ...state, go: 0, repStaked: 0, repTotal: 0, loading: true }))
|
||||
chats.set({ chats: new Map<string, Chat>(), loading: true, unread: 0 })
|
||||
transaction.set({ transactions: [] })
|
||||
})
|
||||
}
|
||||
}
|
||||
stop() {
|
||||
this.subscriptions.forEach((s) => s())
|
||||
|
Loading…
x
Reference in New Issue
Block a user