reload new selected acct after closing an acct
This commit is contained in:
parent
643e3287ed
commit
624997dcaf
|
@ -92,7 +92,7 @@ const MangoAccountsList = ({
|
|||
onClick={() => setShowNewAccountModal(true)}
|
||||
>
|
||||
<PlusCircleIcon className="h-5 w-5" />
|
||||
<span className="ml-2">New Account</span>
|
||||
<span className="ml-2">New Sub Account</span>
|
||||
</LinkButton>
|
||||
</div>
|
||||
</Popover.Panel>
|
||||
|
|
|
@ -7,6 +7,7 @@ import Button from '../shared/Button'
|
|||
import { useTranslation } from 'next-i18next'
|
||||
import { useState } from 'react'
|
||||
import BounceLoader from '../shared/BounceLoader'
|
||||
import { MangoAccount } from '@blockworks-foundation/mango-v4'
|
||||
|
||||
const CloseAccountModal = ({ isOpen, onClose }: ModalProps) => {
|
||||
const { t } = useTranslation('common')
|
||||
|
@ -17,12 +18,22 @@ const CloseAccountModal = ({ isOpen, onClose }: ModalProps) => {
|
|||
const handleCloseMangoAccount = async () => {
|
||||
const client = mangoStore.getState().client
|
||||
const mangoAccount = mangoStore.getState().mangoAccount.current
|
||||
const mangoAccounts = mangoStore.getState().mangoAccounts.accounts
|
||||
const group = mangoStore.getState().group
|
||||
if (!mangoAccount || !group) return
|
||||
setLoading(true)
|
||||
try {
|
||||
const tx = await client.closeMangoAccount(group, mangoAccount)
|
||||
if (tx) {
|
||||
const newMangoAccounts = mangoAccounts.filter(
|
||||
(ma) => !ma.publicKey.equals(mangoAccount.publicKey)
|
||||
)
|
||||
let newCurrentAccount: MangoAccount
|
||||
if (newMangoAccounts[0]) {
|
||||
await newMangoAccounts[0].reload(client, group)
|
||||
newCurrentAccount = newMangoAccounts[0]
|
||||
}
|
||||
|
||||
setLoading(false)
|
||||
onClose()
|
||||
notify({
|
||||
|
@ -31,7 +42,8 @@ const CloseAccountModal = ({ isOpen, onClose }: ModalProps) => {
|
|||
txid: tx,
|
||||
})
|
||||
set((state) => {
|
||||
state.mangoAccount.current = undefined
|
||||
state.mangoAccounts.accounts = newMangoAccounts
|
||||
state.mangoAccount.current = newCurrentAccount
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
"governance": "Governance",
|
||||
"health": "Health",
|
||||
"health-impact": "Health Impact",
|
||||
"insufficient-sol": "The Solana blockchain requires 0.00757 SOL to create a Mango Account. This covers rent for your account and will be refunded if you close your account.",
|
||||
"insufficient-sol": "Solana requires 0.00757 SOL rent to create a Mango Account. This will be returned if you close your account.",
|
||||
"interest-earned": "Interest Earned",
|
||||
"interest-earned-paid": "Interest Earned/Paid",
|
||||
"language": "Language",
|
||||
|
|
Loading…
Reference in New Issue