format srm balances correctly when multiple mango srm accounts exist

This commit is contained in:
Tyler Shipe 2021-05-04 20:00:37 -04:00
parent 1ebae0eb07
commit 4f7e1b4990
2 changed files with 9 additions and 12 deletions

View File

@ -95,12 +95,15 @@ export default function useWallet() {
if (!wallet) return
wallet.on('connect', async () => {
console.log('connected wallet')
sleep(500)
// wait for margin account before fetching trade history
sleep(250)
await actions.fetchMarginAccounts()
actions.fetchWalletBalances()
actions.fetchMangoSrmAccounts()
setMangoStore((state) => {
state.wallet.connected = true
})
// set connected before fetching data
actions.fetchTradeHistory()
actions.fetchMangoSrmAccounts()
actions.fetchWalletBalances()
notify({
message: 'Wallet connected',
description:
@ -109,9 +112,6 @@ export default function useWallet() {
'...' +
wallet.publicKey.toString().substr(-5),
})
setMangoStore((state) => {
state.wallet.connected = true
})
})
wallet.on('disconnect', () => {
console.log('disconnecting wallet')

View File

@ -212,13 +212,10 @@ const useMangoStore = create<MangoStore>((set, get) => ({
set((state) => {
state.wallet.srmAccountsForOwner = usersMangoSrmAccounts
const totalSrmDeposits = usersMangoSrmAccounts.reduce(
(prev, cur) => prev + cur.amount,
(prev, cur) => prev + nativeToUi(cur.amount, SRM_DECIMALS),
0
)
state.wallet.contributedSrm = nativeToUi(
totalSrmDeposits,
SRM_DECIMALS
)
state.wallet.contributedSrm = totalSrmDeposits
})
}
}