mirror of
https://github.com/acid-info/Kurate.git
synced 2025-02-14 08:46:45 +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 { personas, type DraftPersona, type Persona } from '$lib/stores/persona'
|
||||||
import { profile } from '$lib/stores/profile'
|
import { profile } from '$lib/stores/profile'
|
||||||
import { getFromLocalStorage, saveToLocalStorage } from '$lib/utils'
|
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 } from 'ipfs-http-client'
|
||||||
import {
|
import {
|
||||||
CREATE_PERSONA_GO_PRICE,
|
CREATE_PERSONA_GO_PRICE,
|
||||||
@ -55,6 +55,9 @@ const app = initializeApp(firebaseConfig)
|
|||||||
// Initialize Cloud Firestore and get a reference to the service
|
// Initialize Cloud Firestore and get a reference to the service
|
||||||
const db = getFirestore(app)
|
const db = getFirestore(app)
|
||||||
|
|
||||||
|
type WindowWithEthereum = Window &
|
||||||
|
typeof globalThis & { ethereum: providers.ExternalProvider | any }
|
||||||
|
|
||||||
function epochCounter(): () => unknown {
|
function epochCounter(): () => unknown {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
tokens.update(({ epochDuration, ...rest }) => {
|
tokens.update(({ epochDuration, ...rest }) => {
|
||||||
@ -154,6 +157,21 @@ export class Firebase implements Adapter {
|
|||||||
})
|
})
|
||||||
this.subscriptions.push(unsubscribeUser)
|
this.subscriptions.push(unsubscribeUser)
|
||||||
this.subscriptions.push(epochCounter())
|
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() {
|
stop() {
|
||||||
this.subscriptions.forEach((s) => s())
|
this.subscriptions.forEach((s) => s())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user