From 7439bea0d8a0988e7e46b586eb41e2307d56ca2e Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:05:39 +0100 Subject: [PATCH] Hls staking manage actions (#622) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨Add basic modal for HLS staking * ✨UI components for Manage * ✨All Manage actions (except change lev) * 🐛hls intro icons + checkbox, hide repay when no debt, clickable dropdown * fix build --- src/api/hls/getHLSStakingAccounts.ts | 6 +- .../Account/Health/HealthTooltip.tsx | 4 +- src/components/Button/DropDownButton.tsx | 11 +- src/components/Checkbox.tsx | 6 +- .../HLS/Farm/Table/Columns/Deposit.tsx | 8 +- .../HLS/Staking/Table/Columns/Manage.tsx | 46 +++- src/components/Icons/Circle.svg | 10 + src/components/Icons/Scale.svg | 5 + src/components/Icons/index.ts | 2 + src/components/Modal.tsx | 4 +- src/components/Modals/AlertDialog/index.tsx | 2 +- .../HLS/{ => Deposit}/CreateAccount.tsx | 0 .../Modals/HLS/{ => Deposit}/Leverage.tsx | 2 +- .../HLS/{ => Deposit}/LeverageSummary.tsx | 20 +- .../HLS/{ => Deposit}/ProvideCollateral.tsx | 0 .../HLS/{ => Deposit}/SelectAccount.tsx | 0 .../Modals/HLS/{ => Deposit}/SubTitles.tsx | 0 .../{ => Deposit}/Summary/ApyBreakdown.tsx | 0 .../{ => Deposit}/Summary/AssetSummary.tsx | 2 +- .../HLS/{ => Deposit}/Summary/Container.tsx | 0 .../{ => Deposit}/Summary/YourPosition.tsx | 10 +- .../HLS/{ => Deposit}/Summary/index.tsx | 4 +- .../Modals/HLS/{Content => Deposit}/index.tsx | 6 +- .../useAccordionItems.tsx | 16 +- .../useStakingController.tsx | 39 +--- .../useVaultController.tsx | 0 src/components/Modals/HLS/Header.tsx | 8 +- .../Modals/HLS/Manage/ChangeLeverage.tsx | 10 + src/components/Modals/HLS/Manage/Deposit.tsx | 204 ++++++++++++++++++ src/components/Modals/HLS/Manage/Repay.tsx | 98 +++++++++ src/components/Modals/HLS/Manage/Withdraw.tsx | 62 ++++++ src/components/Modals/HLS/Manage/index.tsx | 60 ++++-- src/components/Modals/HLS/index.tsx | 2 +- .../Modals/ModalContentWithSummary.tsx | 38 ++++ src/components/SummaryItems.tsx | 25 +++ src/components/Tooltip/index.tsx | 6 +- src/hooks/HLS/useClosePositionActions.ts | 59 +++++ src/hooks/HLS/useDepositActions.ts | 38 ++++ src/hooks/useDepositHlsVault.ts | 44 ++++ src/hooks/useUpdatedAccount/index.ts | 18 +- src/store/slices/broadcast.ts | 37 +++- .../interfaces/components/SummaryItems.d.ts | 5 + src/types/interfaces/store/broadcast.d.ts | 5 + src/types/interfaces/store/modals.d.ts | 5 +- 44 files changed, 805 insertions(+), 122 deletions(-) create mode 100644 src/components/Icons/Circle.svg create mode 100644 src/components/Icons/Scale.svg rename src/components/Modals/HLS/{ => Deposit}/CreateAccount.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/Leverage.tsx (91%) rename src/components/Modals/HLS/{ => Deposit}/LeverageSummary.tsx (58%) rename src/components/Modals/HLS/{ => Deposit}/ProvideCollateral.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/SelectAccount.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/SubTitles.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/Summary/ApyBreakdown.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/Summary/AssetSummary.tsx (94%) rename src/components/Modals/HLS/{ => Deposit}/Summary/Container.tsx (100%) rename src/components/Modals/HLS/{ => Deposit}/Summary/YourPosition.tsx (85%) rename src/components/Modals/HLS/{ => Deposit}/Summary/index.tsx (88%) rename src/components/Modals/HLS/{Content => Deposit}/index.tsx (95%) rename src/components/Modals/HLS/{Content => Deposit}/useAccordionItems.tsx (89%) rename src/components/Modals/HLS/{Content => Deposit}/useStakingController.tsx (63%) rename src/components/Modals/HLS/{Content => Deposit}/useVaultController.tsx (100%) create mode 100644 src/components/Modals/HLS/Manage/ChangeLeverage.tsx create mode 100644 src/components/Modals/HLS/Manage/Deposit.tsx create mode 100644 src/components/Modals/HLS/Manage/Repay.tsx create mode 100644 src/components/Modals/HLS/Manage/Withdraw.tsx create mode 100644 src/components/Modals/ModalContentWithSummary.tsx create mode 100644 src/components/SummaryItems.tsx create mode 100644 src/hooks/HLS/useClosePositionActions.ts create mode 100644 src/hooks/HLS/useDepositActions.ts create mode 100644 src/types/interfaces/components/SummaryItems.d.ts diff --git a/src/api/hls/getHLSStakingAccounts.ts b/src/api/hls/getHLSStakingAccounts.ts index 180e049f..3b5ab3eb 100644 --- a/src/api/hls/getHLSStakingAccounts.ts +++ b/src/api/hls/getHLSStakingAccounts.ts @@ -13,12 +13,10 @@ export default async function getHLSStakingAccounts( const hlsAccountsWithStrategy: HLSAccountWithStrategy[] = [] activeAccounts.forEach((account) => { - if (account.deposits.length === 0 || account.debts.length === 0) return + if (account.deposits.length === 0) return const strategy = hlsStrategies.find( - (strategy) => - strategy.denoms.deposit === account.deposits.at(0).denom && - strategy.denoms.borrow === account.debts.at(0).denom, + (strategy) => strategy.denoms.deposit === account.deposits.at(0).denom, ) if (!strategy) return diff --git a/src/components/Account/Health/HealthTooltip.tsx b/src/components/Account/Health/HealthTooltip.tsx index 6682990d..14a84dff 100644 --- a/src/components/Account/Health/HealthTooltip.tsx +++ b/src/components/Account/Health/HealthTooltip.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react' +import React, { ReactElement, useMemo } from 'react' import { CircularProgress } from 'components/CircularProgress' import Text from 'components/Text' @@ -8,7 +8,7 @@ import { BN } from 'utils/helpers' interface Props { health: number healthFactor: number - children: React.ReactNode + children: ReactElement } function HealthTooltipContent({ health, healthFactor }: { health: number; healthFactor: number }) { diff --git a/src/components/Button/DropDownButton.tsx b/src/components/Button/DropDownButton.tsx index 0ea46a6e..18a7bc21 100644 --- a/src/components/Button/DropDownButton.tsx +++ b/src/components/Button/DropDownButton.tsx @@ -2,6 +2,7 @@ import Button from 'components/Button' import { ChevronDown } from 'components/Icons' import Text from 'components/Text' import { Tooltip } from 'components/Tooltip' +import useToggle from 'hooks/useToggle' interface Props extends ButtonProps { items: DropDownItem[] @@ -9,6 +10,7 @@ interface Props extends ButtonProps { } export default function DropDownButton(props: Props) { + const [isOpen, toggleIsOpen] = useToggle(false) return ( } @@ -17,8 +19,15 @@ export default function DropDownButton(props: Props) { contentClassName='!bg-white/10 border border-white/20 backdrop-blur-xl !p-0' interactive hideArrow + visible={isOpen} + onClickOutside={() => toggleIsOpen(false)} > -