Skip to content

Commit

Permalink
add var to check account owner is connected wallet, allow self delega…
Browse files Browse the repository at this point in the history
…ted accounts to edit settings
  • Loading branch information
riordanp committed Aug 14, 2024
1 parent 8a9efdf commit ba2af55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit ba2af55

Please sign in to comment.