From da3510130d58a72d82d37417526d0cc999a27ed3 Mon Sep 17 00:00:00 2001 From: Alexander Harding Date: Sun, 23 Feb 2025 11:54:18 -0600 Subject: [PATCH] fix: change account modal not dismissing after selection (#1863) --- src/features/auth/AccountSwitcher.tsx | 9 ++++++--- src/helpers/promise.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/features/auth/AccountSwitcher.tsx b/src/features/auth/AccountSwitcher.tsx index 702bd5c860..7eb4eee6a1 100644 --- a/src/features/auth/AccountSwitcher.tsx +++ b/src/features/auth/AccountSwitcher.tsx @@ -30,7 +30,7 @@ import { setAccounts } from "./authSlice"; type AccountSwitcherProps = { onDismiss: (data?: string, role?: string) => void; - onSelectAccount: (account: string) => Promise; + onSelectAccount: ((account: string) => Promise) | void; showGuest?: boolean; activeHandle?: string; } & ( @@ -130,10 +130,13 @@ function AccountSwitcherContents({ const old = selectedAccount; setSelectedAccount(e.target.value); - const selectionChangePromise = onSelectAccount(e.target.value); + const selectionChangePromise = onSelectAccount?.(e.target.value); // Bail on rendering the loading indicator - if (await isPromiseResolvedByPaint(selectionChangePromise)) { + if ( + !selectionChangePromise || + (await isPromiseResolvedByPaint(selectionChangePromise)) + ) { onDismiss(); return; } diff --git a/src/helpers/promise.ts b/src/helpers/promise.ts index b50f68d86a..1a6bbb6c18 100644 --- a/src/helpers/promise.ts +++ b/src/helpers/promise.ts @@ -8,5 +8,6 @@ export function isPromiseResolvedByPaint( resolve(false); }); }), - ]); + // If promise rejected, it's still resolved by paint + ]).catch(() => true); }