From ba2af553b20fb2936fd83c608c4c54774c3d9fa9 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Wed, 14 Aug 2024 12:11:12 +0100 Subject: [PATCH] add var to check account owner is connected wallet, allow self delegated accounts to edit settings --- components/settings/AccountSettings.tsx | 5 +++-- hooks/useUnownedAccount.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/settings/AccountSettings.tsx b/components/settings/AccountSettings.tsx index becbc06dd..0032da1ca 100644 --- a/components/settings/AccountSettings.tsx +++ b/components/settings/AccountSettings.tsx @@ -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 = () => {

{t('settings:account-settings-unowned')}

- ) : isDelegatedAccount ? ( + ) : isDelegatedAccount && !isOwnedAccount ? (

{t('settings:account-settings-delegated')}

diff --git a/hooks/useUnownedAccount.ts b/hooks/useUnownedAccount.ts index d046094ae..9cca56a7d 100644 --- a/hooks/useUnownedAccount.ts +++ b/hooks/useUnownedAccount.ts @@ -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