Merge pull request #444 from blockworks-foundation/pan/fix-self-delegated-account-settings

Fix self delegated account settings
This commit is contained in:
saml33 2024-08-14 22:28:20 +10:00 committed by GitHub
commit 6601cfe84e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -57,7 +57,8 @@ const AccountSettings = () => {
const { t } = useTranslation(['common', 'settings', 'trade'])
const { mangoAccount, mangoAccountAddress } = useMangoAccount()
const { group } = useMangoGroup()
const { isDelegatedAccount, isUnownedAccount } = useUnownedAccount()
const { isDelegatedAccount, isUnownedAccount, isOwnedAccount } =
useUnownedAccount()
const { connected } = useWallet()
const [showAccountSizeModal, setShowAccountSizeModal] = useState(false)
const [showEditAccountModal, setShowEditAccountModal] = useState(false)
@ -737,7 +738,7 @@ const AccountSettings = () => {
<div className="rounded-lg border border-th-bkg-3 p-4 md:p-6">
<p className="text-center">{t('settings:account-settings-unowned')}</p>
</div>
) : isDelegatedAccount ? (
) : isDelegatedAccount && !isOwnedAccount ? (
<div className="rounded-lg border border-th-bkg-3 p-4 md:p-6">
<p className="text-center">{t('settings:account-settings-delegated')}</p>
</div>

View File

@ -5,6 +5,7 @@ import useMangoAccount from './useMangoAccount'
const useUnownedAccount = (): {
isUnownedAccount: boolean
isDelegatedAccount: boolean
isOwnedAccount: boolean
} => {
const { connected, publicKey } = useWallet()
const { mangoAccountAddress, mangoAccount } = useMangoAccount()
@ -21,7 +22,14 @@ const useUnownedAccount = (): {
return false
}, [publicKey, mangoAccount])
return { isUnownedAccount, isDelegatedAccount }
const isOwnedAccount: boolean = useMemo(() => {
if (publicKey && mangoAccount) {
return mangoAccount?.owner.equals(publicKey)
}
return false
}, [publicKey, mangoAccount])
return { isUnownedAccount, isDelegatedAccount, isOwnedAccount }
}
export default useUnownedAccount