From aab51962ed3e370ebb6d38dc94feec82459c269b Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:06:18 +0100 Subject: [PATCH] fix comments --- .../Wallet/WalletConnectedButton.tsx | 2 +- .../borrow/Table/Columns/BorrowButton.tsx | 3 +- .../common/Button/DropDownButton.tsx | 43 ++++++++++++++----- .../earn/lend/Table/Columns/Manage.tsx | 15 ++++--- .../interfaces/components/DropDownMenu.d.ts | 2 + 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/components/Wallet/WalletConnectedButton.tsx b/src/components/Wallet/WalletConnectedButton.tsx index fa60b15f..8c05a572 100644 --- a/src/components/Wallet/WalletConnectedButton.tsx +++ b/src/components/Wallet/WalletConnectedButton.tsx @@ -90,7 +90,7 @@ export default function WalletConnectedButton() { }) } - navigate(getRoute(getPage(pathname), searchParams)) + navigate(getRoute(getPage(pathname), new URLSearchParams())) } useEffect(() => { diff --git a/src/components/borrow/Table/Columns/BorrowButton.tsx b/src/components/borrow/Table/Columns/BorrowButton.tsx index 9f2c6606..1df103e5 100644 --- a/src/components/borrow/Table/Columns/BorrowButton.tsx +++ b/src/components/borrow/Table/Columns/BorrowButton.tsx @@ -19,7 +19,8 @@ interface Props { } export default function BorrowButton(props: Props) { const account = useCurrentAccount() - const hasNoDeposits = !!account?.deposits?.length && !!account?.lends?.length + const address = useStore((s) => s.address) + const hasNoDeposits = !!account?.deposits?.length && !!account?.lends?.length && !!address const borrowHandler = useCallback(() => { if (!props.data.asset) return null diff --git a/src/components/common/Button/DropDownButton.tsx b/src/components/common/Button/DropDownButton.tsx index fb54de85..752ae397 100644 --- a/src/components/common/Button/DropDownButton.tsx +++ b/src/components/common/Button/DropDownButton.tsx @@ -1,7 +1,10 @@ +import classNames from 'classnames' + import Button from 'components/common/Button/index' import { ChevronDown } from 'components/common/Icons' import Text from 'components/common/Text' import { Tooltip } from 'components/common/Tooltip' +import ConditionalWrapper from 'hocs/ConditionalWrapper' import useToggle from 'hooks/useToggle' interface Props extends ButtonProps { @@ -57,17 +60,35 @@ interface DropDownItemProps { function DropDownItem(props: DropDownItemProps) { return ( - + + ) } diff --git a/src/components/earn/lend/Table/Columns/Manage.tsx b/src/components/earn/lend/Table/Columns/Manage.tsx index 82a808a3..4f031e9f 100644 --- a/src/components/earn/lend/Table/Columns/Manage.tsx +++ b/src/components/earn/lend/Table/Columns/Manage.tsx @@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react' import { ACCOUNT_MENU_BUTTON_ID } from 'components/account/AccountMenuContent' import DropDownButton from 'components/common/Button/DropDownButton' import { ArrowDownLine, ArrowUpLine, Enter, ExclamationMarkCircled } from 'components/common/Icons' +import useCurrentAccount from 'hooks/accounts/useCurrentAccount' import useAlertDialog from 'hooks/useAlertDialog' import useAutoLend from 'hooks/useAutoLend' import useLendAndReclaimModal from 'hooks/useLendAndReclaimModal' @@ -22,10 +23,11 @@ export default function Manage(props: Props) { const { isAutoLendEnabledForCurrentAccount } = useAutoLend() const { open: showAlertDialog } = useAlertDialog() const address = useStore((s) => s.address) + const account = useCurrentAccount() - const hasLendAsset = useMemo( - () => !!props.data.accountLentValue && props.data.accountLentValue.isGreaterThan(0), - [props.data.accountLentValue], + const hasAssetInDeposits = useMemo( + () => !!account?.deposits?.find((deposit) => deposit.denom === props.data.asset.denom), + [account?.deposits, props.data.asset.denom], ) const handleUnlend = useCallback(() => { @@ -55,8 +57,11 @@ export default function Manage(props: Props) { () => [ { icon: , - text: hasLendAsset ? 'Lend more' : 'Lend', + text: 'Lend more', onClick: () => openLend(props.data), + disabled: !hasAssetInDeposits, + disabledTooltip: `You don’t have any ${props.data.asset.symbol}. + Please first deposit ${props.data.asset.symbol} into your Credit Account before lending.`, }, { icon: , @@ -64,7 +69,7 @@ export default function Manage(props: Props) { onClick: handleUnlend, }, ], - [handleUnlend, hasLendAsset, openLend, props.data], + [handleUnlend, hasAssetInDeposits, openLend, props.data], ) if (!address) return null diff --git a/src/types/interfaces/components/DropDownMenu.d.ts b/src/types/interfaces/components/DropDownMenu.d.ts index 58bcd761..193a9387 100644 --- a/src/types/interfaces/components/DropDownMenu.d.ts +++ b/src/types/interfaces/components/DropDownMenu.d.ts @@ -2,4 +2,6 @@ interface DropDownItem { icon: import('react').ReactNode onClick: () => void text: string + disabled?: boolean + disabledTooltip?: string }