Skip to content

Commit

Permalink
fix: change account modal not dismissing after selection (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Feb 23, 2025
1 parent c994119 commit da35101
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/features/auth/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { setAccounts } from "./authSlice";

type AccountSwitcherProps = {
onDismiss: (data?: string, role?: string) => void;
onSelectAccount: (account: string) => Promise<void>;
onSelectAccount: ((account: string) => Promise<void>) | void;
showGuest?: boolean;
activeHandle?: string;
} & (
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export function isPromiseResolvedByPaint(
resolve(false);
});
}),
]);
// If promise rejected, it's still resolved by paint
]).catch(() => true);
}

0 comments on commit da35101

Please sign in to comment.