refresh selected margin account

This commit is contained in:
Tyler Shipe 2021-04-26 01:47:45 -04:00
parent f18d61b216
commit 36b3b62a95
1 changed files with 10 additions and 1 deletions

View File

@ -247,7 +247,16 @@ const useMangoStore = create<MangoStore>((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]
}
})
}
})