restore last viewed acct functionality

This commit is contained in:
tjs 2023-03-02 20:18:52 -05:00
parent 96f9945746
commit 8d28ab1cb6
3 changed files with 10 additions and 5 deletions

View File

@ -82,6 +82,7 @@ export default function useLocalStorageState<T = any>(
try {
return JSON.parse(stringState)
} catch (e) {
console.log('Error parsing JSON from localStorage', e)
return stringState
}
}

View File

@ -622,11 +622,15 @@ const mangoStore = create<MangoStore>()(
if (!selectedMangoAccount || !selectedAccountIsNotInAccountsList) {
const lastAccount = localStorage.getItem(LAST_ACCOUNT_KEY)
newSelectedMangoAccount = mangoAccounts[0]
let lastViewedAccount
if (typeof lastAccount === 'string') {
const lastViewedAccount = mangoAccounts.find(
(m) => m.publicKey.toString() === lastAccount
)
try {
lastViewedAccount = mangoAccounts.find(
(m) => m.publicKey.toString() === JSON.parse(lastAccount)
)
} catch (e) {
console.error('Error parsing last account', e)
}
newSelectedMangoAccount = lastViewedAccount || mangoAccounts[0]
}
}

View File

@ -1,4 +1,4 @@
export const LAST_ACCOUNT_KEY = 'mangoAccount-0.2'
export const LAST_ACCOUNT_KEY = 'mangoAccount-0.3'
export const CLIENT_TX_TIMEOUT = 90000