feat: reuse existing bunker connection on account switch (#401)
This commit is contained in:
@@ -12,7 +12,7 @@ export class BunkerSigner implements ISigner {
|
||||
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)
|
||||
if (!bunkerPointer) {
|
||||
throw new Error('Invalid bunker')
|
||||
@@ -23,7 +23,9 @@ export class BunkerSigner implements ISigner {
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
})
|
||||
await this.signer.connect()
|
||||
if (isInitialConnection) {
|
||||
await this.signer.connect()
|
||||
}
|
||||
return await this.signer.getPublicKey()
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
||||
} else if (account.signerType === 'bunker') {
|
||||
if (account.bunker && 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) {
|
||||
storage.removeAccount(account)
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user