From f66ca6346ff80e2b4c0b18e1a6151cbda91c06fa Mon Sep 17 00:00:00 2001 From: hoppe <41467626+tajava2006@users.noreply.github.com> Date: Mon, 23 Jun 2025 10:56:08 +0900 Subject: [PATCH] feat: reuse existing bunker connection on account switch (#401) --- src/providers/NostrProvider/bunker.signer.ts | 6 ++++-- src/providers/NostrProvider/index.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/providers/NostrProvider/bunker.signer.ts b/src/providers/NostrProvider/bunker.signer.ts index a4fa5706..f2861222 100644 --- a/src/providers/NostrProvider/bunker.signer.ts +++ b/src/providers/NostrProvider/bunker.signer.ts @@ -12,7 +12,7 @@ export class BunkerSigner implements ISigner { this.clientSecretKey = clientSecretKey ? hexToBytes(clientSecretKey) : generateSecretKey() } - async login(bunker: string): Promise { + async login(bunker: string, isInitialConnection = true): Promise { 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() } diff --git a/src/providers/NostrProvider/index.tsx b/src/providers/NostrProvider/index.tsx index a4c42329..bb989e28 100644 --- a/src/providers/NostrProvider/index.tsx +++ b/src/providers/NostrProvider/index.tsx @@ -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