From 917080ac097b03f3c7978bf089b746780b3415f8 Mon Sep 17 00:00:00 2001 From: tjs Date: Sat, 4 Mar 2023 13:42:46 -0500 Subject: [PATCH] add warning for delegate accounts --- components/modals/BorrowRepayModal.tsx | 38 ++++++++++++++-------- components/modals/DepositWithdrawModal.tsx | 38 ++++++++++++++-------- components/swap/SwapForm.tsx | 9 +++-- hooks/useMangoAccount.ts | 18 +++++++++- 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/components/modals/BorrowRepayModal.tsx b/components/modals/BorrowRepayModal.tsx index 6130538c..a1f8ec18 100644 --- a/components/modals/BorrowRepayModal.tsx +++ b/components/modals/BorrowRepayModal.tsx @@ -7,6 +7,7 @@ import RepayForm from '@components/RepayForm' import { ACCOUNT_ACTION_MODAL_HEIGHT } from 'utils/constants' import { useWallet } from '@solana/wallet-adapter-react' import mangoStore from '@store/mangoStore' +import useMangoAccount from 'hooks/useMangoAccount' interface BorrowRepayModalProps { action: 'borrow' | 'repay' @@ -23,6 +24,7 @@ const BorrowRepayModal = ({ }: ModalCombinedProps) => { const [activeTab, setActiveTab] = useState(action) const { publicKey: walletPk } = useWallet() + const { isDelegatedAccount } = useMangoAccount() useEffect(() => { if (walletPk) { @@ -33,19 +35,29 @@ const BorrowRepayModal = ({ return (
-
- setActiveTab(v)} - /> -
- {activeTab === 'borrow' ? ( - - ) : null} - {activeTab === 'repay' ? ( - - ) : null} + {!isDelegatedAccount ? ( + <> +
+ setActiveTab(v)} + /> +
+ {activeTab === 'borrow' ? ( + + ) : null} + {activeTab === 'repay' ? ( + + ) : null}{' '} + + ) : ( +
+
+ Unavailable for delegate accounts +
+
+ )}
) diff --git a/components/modals/DepositWithdrawModal.tsx b/components/modals/DepositWithdrawModal.tsx index e8cd2827..83c479da 100644 --- a/components/modals/DepositWithdrawModal.tsx +++ b/components/modals/DepositWithdrawModal.tsx @@ -7,6 +7,7 @@ import WithdrawForm from '@components/WithdrawForm' import { ACCOUNT_ACTION_MODAL_HEIGHT } from 'utils/constants' import mangoStore from '@store/mangoStore' import { useWallet } from '@solana/wallet-adapter-react' +import useMangoAccount from 'hooks/useMangoAccount' interface DepositWithdrawModalProps { action: 'deposit' | 'withdraw' @@ -23,6 +24,7 @@ const DepositWithdrawModal = ({ }: ModalCombinedProps) => { const [activeTab, setActiveTab] = useState(action) const { publicKey: walletPk } = useWallet() + const { isDelegatedAccount } = useMangoAccount() useEffect(() => { if (walletPk) { @@ -33,19 +35,29 @@ const DepositWithdrawModal = ({ return (
-
- setActiveTab(v)} - /> -
- {activeTab === 'deposit' ? ( - - ) : null} - {activeTab === 'withdraw' ? ( - - ) : null} + {!isDelegatedAccount ? ( + <> +
+ setActiveTab(v)} + /> +
+ {activeTab === 'deposit' ? ( + + ) : null} + {activeTab === 'withdraw' ? ( + + ) : null} + + ) : ( +
+
+ Unavailable for delegate accounts +
+
+ )}
) diff --git a/components/swap/SwapForm.tsx b/components/swap/SwapForm.tsx index 4c465f7b..80d49c50 100644 --- a/components/swap/SwapForm.tsx +++ b/components/swap/SwapForm.tsx @@ -83,7 +83,7 @@ const SwapForm = () => { } = mangoStore((s) => s.swap) const [debouncedAmountIn] = useDebounce(amountInFormValue, 300) const [debouncedAmountOut] = useDebounce(amountOutFormValue, 300) - const { mangoAccount } = useMangoAccount() + const { mangoAccount, isDelegatedAccount } = useMangoAccount() const { connected, publicKey } = useWallet() const amountInAsDecimal: Decimal | null = useMemo(() => { @@ -440,6 +440,7 @@ const SwapForm = () => { amountOut={ selectedRoute ? amountOutAsDecimal.toNumber() : undefined } + isDelegatedAccount={isDelegatedAccount} /> ) : (