add warning for delegate accounts
This commit is contained in:
parent
8423750c9f
commit
917080ac09
|
@ -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 (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<div style={{ height: ACCOUNT_ACTION_MODAL_HEIGHT }}>
|
||||
<div className="pb-2">
|
||||
<TabUnderline
|
||||
activeValue={activeTab}
|
||||
values={['borrow', 'repay']}
|
||||
onChange={(v) => setActiveTab(v)}
|
||||
/>
|
||||
</div>
|
||||
{activeTab === 'borrow' ? (
|
||||
<BorrowForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{activeTab === 'repay' ? (
|
||||
<RepayForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{!isDelegatedAccount ? (
|
||||
<>
|
||||
<div className="pb-2">
|
||||
<TabUnderline
|
||||
activeValue={activeTab}
|
||||
values={['borrow', 'repay']}
|
||||
onChange={(v) => setActiveTab(v)}
|
||||
/>
|
||||
</div>
|
||||
{activeTab === 'borrow' ? (
|
||||
<BorrowForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{activeTab === 'repay' ? (
|
||||
<RepayForm onSuccess={onClose} token={token} />
|
||||
) : null}{' '}
|
||||
</>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="text-th-fgd-4">
|
||||
Unavailable for delegate accounts
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
|
|
|
@ -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 (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<div style={{ height: ACCOUNT_ACTION_MODAL_HEIGHT }}>
|
||||
<div className="pb-2">
|
||||
<TabUnderline
|
||||
activeValue={activeTab}
|
||||
values={['deposit', 'withdraw']}
|
||||
onChange={(v) => setActiveTab(v)}
|
||||
/>
|
||||
</div>
|
||||
{activeTab === 'deposit' ? (
|
||||
<DepositForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{activeTab === 'withdraw' ? (
|
||||
<WithdrawForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{!isDelegatedAccount ? (
|
||||
<>
|
||||
<div className="pb-2">
|
||||
<TabUnderline
|
||||
activeValue={activeTab}
|
||||
values={['deposit', 'withdraw']}
|
||||
onChange={(v) => setActiveTab(v)}
|
||||
/>
|
||||
</div>
|
||||
{activeTab === 'deposit' ? (
|
||||
<DepositForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
{activeTab === 'withdraw' ? (
|
||||
<WithdrawForm onSuccess={onClose} token={token} />
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="text-th-fgd-4">
|
||||
Unavailable for delegate accounts
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
|
@ -511,6 +512,7 @@ const SwapFormSubmitButton = ({
|
|||
selectedRoute,
|
||||
setShowConfirm,
|
||||
useMargin,
|
||||
isDelegatedAccount,
|
||||
}: {
|
||||
amountIn: Decimal
|
||||
amountOut: number | undefined
|
||||
|
@ -519,6 +521,7 @@ const SwapFormSubmitButton = ({
|
|||
selectedRoute: RouteInfo | undefined | null
|
||||
setShowConfirm: (x: boolean) => void
|
||||
useMargin: boolean
|
||||
isDelegatedAccount: boolean
|
||||
}) => {
|
||||
const { t } = useTranslation('common')
|
||||
const { connected } = useWallet()
|
||||
|
@ -546,7 +549,9 @@ const SwapFormSubmitButton = ({
|
|||
disabled={disabled}
|
||||
size="large"
|
||||
>
|
||||
{connected ? (
|
||||
{isDelegatedAccount ? (
|
||||
<div>Swap Unavailable for Delegates</div>
|
||||
) : connected ? (
|
||||
showInsufficientBalance ? (
|
||||
<div className="flex items-center">
|
||||
<ExclamationCircleIcon className="mr-2 h-5 w-5 flex-shrink-0" />
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { MangoAccount } from '@blockworks-foundation/mango-v4'
|
||||
import { useWallet } from '@solana/wallet-adapter-react'
|
||||
import { PublicKey } from '@solana/web3.js'
|
||||
import mangoStore from '@store/mangoStore'
|
||||
import { useMemo } from 'react'
|
||||
|
@ -8,9 +9,11 @@ export default function useMangoAccount(): {
|
|||
initialLoad: boolean
|
||||
mangoAccountPk: PublicKey | undefined
|
||||
mangoAccountAddress: string
|
||||
isDelegatedAccount: boolean
|
||||
} {
|
||||
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
||||
const initialLoad = mangoStore((s) => s.mangoAccount.initialLoad)
|
||||
const { publicKey } = useWallet()
|
||||
|
||||
const mangoAccountPk = useMemo(() => {
|
||||
return mangoAccount?.publicKey
|
||||
|
@ -20,5 +23,18 @@ export default function useMangoAccount(): {
|
|||
return mangoAccountPk?.toString() || ''
|
||||
}, [mangoAccountPk])
|
||||
|
||||
return { mangoAccount, initialLoad, mangoAccountAddress, mangoAccountPk }
|
||||
const isDelegatedAccount: boolean = useMemo(() => {
|
||||
if (publicKey && mangoAccount) {
|
||||
return mangoAccount?.delegate.equals(publicKey)
|
||||
}
|
||||
return false
|
||||
}, [publicKey, mangoAccount])
|
||||
|
||||
return {
|
||||
mangoAccount,
|
||||
initialLoad,
|
||||
mangoAccountAddress,
|
||||
mangoAccountPk,
|
||||
isDelegatedAccount,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue