Possibly fix weird race conditions

No idea how this happen at all
This commit is contained in:
Lim Chee Aun 2024-03-27 14:58:32 +08:00
parent 2bc24cc495
commit 1692637e22
2 changed files with 5 additions and 3 deletions

View file

@ -27,9 +27,10 @@ function NavMenu(props) {
const [currentAccount, moreThanOneAccount] = useMemo(() => {
const accounts = store.local.getJSON('accounts') || [];
const acc = accounts.find(
(account) => account.info.id === store.session.get('currentAccount'),
);
const acc =
accounts.find(
(account) => account.info.id === store.session.get('currentAccount'),
) || accounts[0];
return [acc, accounts.length > 1];
}, []);

View file

@ -2,6 +2,7 @@ import store from './store';
export function getAccount(id) {
const accounts = store.local.getJSON('accounts') || [];
if (!id) return accounts[0];
return accounts.find((a) => a.info.id === id) || accounts[0];
}