Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix self delegated account settings #444

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>
Expand Down
10 changes: 9 additions & 1 deletion hooks/useUnownedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useMangoAccount from './useMangoAccount'
const useUnownedAccount = (): {
isUnownedAccount: boolean
isDelegatedAccount: boolean
isOwnedAccount: boolean
} => {
const { connected, publicKey } = useWallet()
const { mangoAccountAddress, mangoAccount } = useMangoAccount()
Expand All @@ -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
Loading