From 13f0d374ba0e283be4b572128afefbbdcc0cf057 Mon Sep 17 00:00:00 2001 From: Victor Oliva Date: Tue, 21 Jan 2025 12:59:16 +0100 Subject: [PATCH] fix: pjs extension not loading accounts the first time --- src/state/extension-accounts.state.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/state/extension-accounts.state.ts b/src/state/extension-accounts.state.ts index 1aff685..86a7830 100644 --- a/src/state/extension-accounts.state.ts +++ b/src/state/extension-accounts.state.ts @@ -17,6 +17,7 @@ import { NEVER, Observable, of, + retry, scan, startWith, switchMap, @@ -73,11 +74,23 @@ const setPreselectedExtension = (extension: string, selected: boolean) => { const extension$ = (name: string) => { const connect$ = defer(() => connectInjectedExtension(name)).pipe( + // PolkadotJS rejects the promise straight away instead of waiting for user input + retry({ + delay(error) { + if (error?.message.includes("pending authorization request")) { + return timer(1000) + } + throw error + }, + }), map((extension) => ({ type: ConnectStatus.Connected as const, extension, })), - catchError(() => of({ type: ConnectStatus.Disconnected as const })), + catchError((ex) => { + console.error(ex) + return of({ type: ConnectStatus.Disconnected as const }) + }), startWith({ type: ConnectStatus.Connecting as const }), )