Browse Source

feat: reuse existing bunker connection on account switch (#401)

imwald
hoppe 9 months ago committed by GitHub
parent
commit
f66ca6346f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/providers/NostrProvider/bunker.signer.ts
  2. 2
      src/providers/NostrProvider/index.tsx

4
src/providers/NostrProvider/bunker.signer.ts

@ -12,7 +12,7 @@ export class BunkerSigner implements ISigner {
this.clientSecretKey = clientSecretKey ? hexToBytes(clientSecretKey) : generateSecretKey() this.clientSecretKey = clientSecretKey ? hexToBytes(clientSecretKey) : generateSecretKey()
} }
async login(bunker: string): Promise<string> { async login(bunker: string, isInitialConnection = true): Promise<string> {
const bunkerPointer = await parseBunkerInput(bunker) const bunkerPointer = await parseBunkerInput(bunker)
if (!bunkerPointer) { if (!bunkerPointer) {
throw new Error('Invalid bunker') throw new Error('Invalid bunker')
@ -23,7 +23,9 @@ export class BunkerSigner implements ISigner {
window.open(url, '_blank') window.open(url, '_blank')
} }
}) })
if (isInitialConnection) {
await this.signer.connect() await this.signer.connect()
}
return await this.signer.getPublicKey() return await this.signer.getPublicKey()
} }

2
src/providers/NostrProvider/index.tsx

@ -450,7 +450,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
} else if (account.signerType === 'bunker') { } else if (account.signerType === 'bunker') {
if (account.bunker && account.bunkerClientSecretKey) { if (account.bunker && account.bunkerClientSecretKey) {
const bunkerSigner = new BunkerSigner(account.bunkerClientSecretKey) const bunkerSigner = new BunkerSigner(account.bunkerClientSecretKey)
const pubkey = await bunkerSigner.login(account.bunker) const pubkey = await bunkerSigner.login(account.bunker, false)
if (!pubkey) { if (!pubkey) {
storage.removeAccount(account) storage.removeAccount(account)
return null return null

Loading…
Cancel
Save