diff --git a/stores/useMangoStore.tsx b/stores/useMangoStore.tsx index 7c07ef0..ec220a7 100644 --- a/stores/useMangoStore.tsx +++ b/stores/useMangoStore.tsx @@ -247,7 +247,16 @@ const useMangoStore = create((set, get) => ({ if (marginAccounts.length > 0) { set((state) => { state.marginAccounts = marginAccounts - state.selectedMarginAccount.current = marginAccounts[0] + if (state.selectedMarginAccount.current) { + state.selectedMarginAccount.current = marginAccounts.find( + (ma) => + ma.publicKey.equals( + state.selectedMarginAccount.current.publicKey + ) + ) + } else { + state.selectedMarginAccount.current = marginAccounts[0] + } }) } })