use mangoAccounts for number of accounts
This commit is contained in:
parent
0a0b1f7f84
commit
1739d04499
|
@ -1,4 +1,4 @@
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { abbreviateAddress } from '../utils/index'
|
import { abbreviateAddress } from '../utils/index'
|
||||||
import useLocalStorageState from '../hooks/useLocalStorageState'
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
||||||
|
@ -31,10 +31,8 @@ const TopBar = () => {
|
||||||
const { t } = useTranslation('common')
|
const { t } = useTranslation('common')
|
||||||
const { connected, publicKey } = useWallet()
|
const { connected, publicKey } = useWallet()
|
||||||
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
||||||
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
|
const mangoAccounts = useMangoStore((s) => s.mangoAccounts)
|
||||||
const cluster = useMangoStore((s) => s.connection.cluster)
|
const cluster = useMangoStore((s) => s.connection.cluster)
|
||||||
const mangoClient = useMangoStore((s) => s.connection.client)
|
|
||||||
const [numberOfAccounts, setNumberOfAccounts] = useState<number | null>(null)
|
|
||||||
const [showAccountsModal, setShowAccountsModal] = useState(false)
|
const [showAccountsModal, setShowAccountsModal] = useState(false)
|
||||||
const [defaultMarket] = useLocalStorageState(
|
const [defaultMarket] = useLocalStorageState(
|
||||||
DEFAULT_MARKET_KEY,
|
DEFAULT_MARKET_KEY,
|
||||||
|
@ -42,19 +40,6 @@ const TopBar = () => {
|
||||||
)
|
)
|
||||||
const isDevnet = cluster === 'devnet'
|
const isDevnet = cluster === 'devnet'
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (mangoAccount && mangoGroup && publicKey) {
|
|
||||||
const getMangoAccounts = async () => {
|
|
||||||
const mangoAccounts = await mangoClient.getMangoAccountsForOwner(
|
|
||||||
mangoGroup,
|
|
||||||
publicKey
|
|
||||||
)
|
|
||||||
setNumberOfAccounts(mangoAccounts.length)
|
|
||||||
}
|
|
||||||
getMangoAccounts()
|
|
||||||
}
|
|
||||||
}, [mangoAccount, mangoGroup, publicKey])
|
|
||||||
|
|
||||||
const handleCloseAccounts = useCallback(() => {
|
const handleCloseAccounts = useCallback(() => {
|
||||||
setShowAccountsModal(false)
|
setShowAccountsModal(false)
|
||||||
}, [])
|
}, [])
|
||||||
|
@ -159,10 +144,10 @@ const TopBar = () => {
|
||||||
onClick={() => setShowAccountsModal(true)}
|
onClick={() => setShowAccountsModal(true)}
|
||||||
>
|
>
|
||||||
<div className="text-xs font-normal text-th-primary">
|
<div className="text-xs font-normal text-th-primary">
|
||||||
{numberOfAccounts
|
{mangoAccounts
|
||||||
? numberOfAccounts === 1
|
? mangoAccounts.length === 1
|
||||||
? `1 ${t('account')}`
|
? `1 ${t('account')}`
|
||||||
: `${numberOfAccounts} ${t('accounts')}`
|
: `${mangoAccounts.length} ${t('accounts')}`
|
||||||
: t('account')}
|
: t('account')}
|
||||||
</div>
|
</div>
|
||||||
{mangoAccount.name
|
{mangoAccount.name
|
||||||
|
|
Loading…
Reference in New Issue