Add basic modal for HLS staking (#615)

This commit is contained in:
Bob van der Helm 2023-11-03 16:44:02 +01:00 committed by GitHub
parent 5a775bcc6b
commit 4ec95c885c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 117 additions and 55 deletions

View File

@ -2,7 +2,7 @@ import { useCallback } from 'react'
import Button from 'components/Button' import Button from 'components/Button'
import ActionButton from 'components/Button/ActionButton' import ActionButton from 'components/Button/ActionButton'
import { Plus, ReceiptCheck } from 'components/Icons' import { HandCoins, Plus } from 'components/Icons'
import useStore from 'store' import useStore from 'store'
import { getEnabledMarketAssets } from 'utils/assets' import { getEnabledMarketAssets } from 'utils/assets'
@ -37,7 +37,7 @@ export default function BorrowActionButtons(props: Props) {
className='min-w-40 text-center' className='min-w-40 text-center'
/> />
{debt && ( {debt && (
<Button color='tertiary' leftIcon={<ReceiptCheck />} text='Repay' onClick={repayHandler} /> <Button color='tertiary' leftIcon={<HandCoins />} text='Repay' onClick={repayHandler} />
)} )}
</div> </div>
) )

View File

@ -1,32 +1,44 @@
import React from 'react' import React, { useCallback, useMemo } from 'react'
import DropDownButton from 'components/Button/DropDownButton' import DropDownButton from 'components/Button/DropDownButton'
import { ArrowDownLine, HandCoins, Plus } from 'components/Icons' import { ArrowDownLine, HandCoins, Plus } from 'components/Icons'
import useStore from 'store'
export const MANAGE_META = { id: 'manage' } export const MANAGE_META = { id: 'manage' }
const ITEMS: DropDownItem[] = [
{
icon: <Plus width={16} />,
text: 'Deposit more',
onClick: () => {},
},
{
icon: <HandCoins />,
text: 'Repay',
onClick: () => {},
},
{
icon: <ArrowDownLine />,
text: 'Withdraw',
onClick: () => {},
},
]
interface Props { interface Props {
account: HLSAccountWithStrategy account: HLSAccountWithStrategy
} }
export default function Manage(props: Props) { export default function Manage(props: Props) {
const openModal = useCallback(
(action: 'deposit' | 'withdraw' | 'repay') =>
useStore.setState({
hlsManageModal: { staking: { strategy: props.account.strategy, action } },
}),
[props.account.strategy],
)
const ITEMS: DropDownItem[] = useMemo(
() => [
{
icon: <Plus width={16} />,
text: 'Deposit more',
onClick: () => openModal('deposit'),
},
{
icon: <HandCoins />,
text: 'Repay',
onClick: () => openModal('repay'),
},
{
icon: <ArrowDownLine />,
text: 'Withdraw',
onClick: () => openModal('withdraw'),
},
],
[openModal],
)
return <DropDownButton items={ITEMS} text='Manage' color='tertiary' /> return <DropDownButton items={ITEMS} text='Manage' color='tertiary' />
} }

View File

@ -11,17 +11,14 @@ import useIsOpenArray from 'hooks/useIsOpenArray'
import useVault from 'hooks/useVault' import useVault from 'hooks/useVault'
import useStore from 'store' import useStore from 'store'
import { isAccountEmpty } from 'utils/accounts' import { isAccountEmpty } from 'utils/accounts'
import { getAssetByDenom } from 'utils/assets'
interface Props { interface Props {
borrowDenom: string borrowAsset: Asset
collateralDenom: string collateralAsset: Asset
vaultAddress: string | null vaultAddress: string | null
} }
export default function Controller(props: Props) { export default function Controller(props: Props) {
const collateralAsset = getAssetByDenom(props.collateralDenom)
const borrowAsset = getAssetByDenom(props.borrowDenom)
const [selectedAccount, setSelectedAccount] = useState<Account>(EMPTY_ACCOUNT_HLS) const [selectedAccount, setSelectedAccount] = useState<Account>(EMPTY_ACCOUNT_HLS)
const [isOpen, toggleIsOpen] = useIsOpenArray(4, false) const [isOpen, toggleIsOpen] = useIsOpenArray(4, false)
const address = useStore((s) => s.address) const address = useStore((s) => s.address)
@ -30,18 +27,16 @@ export default function Controller(props: Props) {
() => hlsAccounts.filter((account) => isAccountEmpty(account)), () => hlsAccounts.filter((account) => isAccountEmpty(account)),
[hlsAccounts], [hlsAccounts],
) )
const walletCollateralAsset = useCurrentWalletBalance(props.collateralDenom) const walletCollateralAsset = useCurrentWalletBalance(props.collateralAsset.denom)
const vault = useVault(props.vaultAddress || '') const vault = useVault(props.vaultAddress || '')
if (!collateralAsset || !borrowAsset) return null
if (vault) if (vault)
return ( return (
<Vault <Vault
walletCollateralAsset={walletCollateralAsset} walletCollateralAsset={walletCollateralAsset}
vault={vault} vault={vault}
collateralAsset={collateralAsset} collateralAsset={props.collateralAsset}
borrowAsset={borrowAsset} borrowAsset={props.borrowAsset}
emptyHlsAccounts={emptyHlsAccounts} emptyHlsAccounts={emptyHlsAccounts}
hlsAccounts={hlsAccounts} hlsAccounts={hlsAccounts}
isOpen={isOpen} isOpen={isOpen}
@ -54,8 +49,8 @@ export default function Controller(props: Props) {
return ( return (
<StakingContent <StakingContent
walletCollateralAsset={walletCollateralAsset} walletCollateralAsset={walletCollateralAsset}
collateralAsset={collateralAsset} collateralAsset={props.collateralAsset}
borrowAsset={borrowAsset} borrowAsset={props.borrowAsset}
emptyHlsAccounts={emptyHlsAccounts} emptyHlsAccounts={emptyHlsAccounts}
hlsAccounts={hlsAccounts} hlsAccounts={hlsAccounts}
isOpen={isOpen} isOpen={isOpen}

View File

@ -3,23 +3,20 @@ import React from 'react'
import DoubleLogo from 'components/DoubleLogo' import DoubleLogo from 'components/DoubleLogo'
import HLSTag from 'components/HLS/HLSTag' import HLSTag from 'components/HLS/HLSTag'
import Text from 'components/Text' import Text from 'components/Text'
import { getAssetByDenom } from 'utils/assets'
interface Props { interface Props {
primaryDenom: string primaryAsset: Asset
secondaryDenom: string secondaryAsset: Asset
} }
export default function Header(props: Props) { export default function Header(props: Props) {
const primaryAsset = getAssetByDenom(props.primaryDenom)
const secondaryAsset = getAssetByDenom(props.secondaryDenom)
if (!primaryAsset || !secondaryAsset) return null
return ( return (
<div className='flex items-center gap-2'> <div className='flex items-center gap-2'>
<DoubleLogo primaryDenom={props.primaryDenom} secondaryDenom={props.secondaryDenom} /> <DoubleLogo
<Text>{`${primaryAsset.symbol} - ${secondaryAsset.symbol}`}</Text> primaryDenom={props.secondaryAsset.denom}
secondaryDenom={props.primaryAsset.denom}
/>
<Text>{`${props.secondaryAsset.symbol} - ${props.primaryAsset.symbol}`}</Text>
<HLSTag /> <HLSTag />
</div> </div>
) )

View File

@ -0,0 +1,40 @@
import React from 'react'
import Modal from 'components/Modal'
import Header from 'components/Modals/HLS/Header'
import useStore from 'store'
import { getAssetByDenom } from 'utils/assets'
export default function HlsManageModalController() {
const modal = useStore((s) => s.hlsManageModal)
const collateralAsset = getAssetByDenom(modal?.staking.strategy.denoms.deposit || '')
const borrowAsset = getAssetByDenom(modal?.staking.strategy.denoms.borrow || '')
if (!modal || !collateralAsset || !borrowAsset) return null
return <HlsModal collateralAsset={collateralAsset} borrowAsset={borrowAsset} />
}
interface Props {
borrowAsset: Asset
collateralAsset: Asset
}
function HlsModal(props: Props) {
function handleClose() {
useStore.setState({ hlsManageModal: null })
}
return (
<Modal
header={<Header primaryAsset={props.collateralAsset} secondaryAsset={props.borrowAsset} />}
headerClassName='gradient-header pl-2 pr-2.5 py-3 border-b-white/5 border-b'
contentClassName='flex flex-col p-6'
modalClassName='max-w-modal-md'
onClose={handleClose}
>
Some kind of text here
</Modal>
)
}

View File

@ -4,33 +4,39 @@ import Modal from 'components/Modal'
import Content from 'components/Modals/HLS/Content' import Content from 'components/Modals/HLS/Content'
import Header from 'components/Modals/HLS/Header' import Header from 'components/Modals/HLS/Header'
import useStore from 'store' import useStore from 'store'
import { getAssetByDenom } from 'utils/assets'
export default function HlsModalController() { export default function HlsModalController() {
const modal = useStore((s) => s.hlsModal) const modal = useStore((s) => s.hlsModal)
const primaryAsset = getAssetByDenom(
modal?.vault?.denoms.primary || modal?.strategy?.denoms.deposit || '',
)
const secondaryAsset = getAssetByDenom(
modal?.vault?.denoms.secondary || modal?.strategy?.denoms.borrow || '',
)
if (!primaryAsset || !secondaryAsset) return null
if (modal?.vault) if (modal?.vault)
return ( return (
<HlsModal <HlsModal
collateralDenom={modal.vault.denoms.primary} primaryAsset={primaryAsset}
borrowDenom={modal.vault.denoms.secondary} secondaryAsset={secondaryAsset}
vaultAddress={modal.vault.address} vaultAddress={modal.vault.address}
/> />
) )
if (modal?.strategy) if (modal?.strategy)
return ( return (
<HlsModal <HlsModal primaryAsset={primaryAsset} secondaryAsset={secondaryAsset} vaultAddress={null} />
collateralDenom={modal.strategy.denoms.deposit}
borrowDenom={modal.strategy.denoms.borrow}
vaultAddress={null}
/>
) )
return null return null
} }
interface Props { interface Props {
borrowDenom: string primaryAsset: Asset
collateralDenom: string secondaryAsset: Asset
vaultAddress: string | null vaultAddress: string | null
} }
@ -41,15 +47,15 @@ function HlsModal(props: Props) {
return ( return (
<Modal <Modal
header={<Header primaryDenom={props.collateralDenom} secondaryDenom={props.borrowDenom} />} header={<Header primaryAsset={props.primaryAsset} secondaryAsset={props.secondaryAsset} />}
headerClassName='gradient-header pl-2 pr-2.5 py-3 border-b-white/5 border-b' headerClassName='gradient-header pl-2 pr-2.5 py-3 border-b-white/5 border-b'
contentClassName='flex flex-col p-6' contentClassName='flex flex-col p-6'
modalClassName='max-w-modal-md' modalClassName='max-w-modal-md'
onClose={handleClose} onClose={handleClose}
> >
<Content <Content
collateralDenom={props.collateralDenom} collateralAsset={props.primaryAsset}
borrowDenom={props.borrowDenom} borrowAsset={props.secondaryAsset}
vaultAddress={props.vaultAddress} vaultAddress={props.vaultAddress}
/> />
</Modal> </Modal>

View File

@ -5,6 +5,7 @@ import {
BorrowModal, BorrowModal,
FundAndWithdrawModal, FundAndWithdrawModal,
GetStartedModal, GetStartedModal,
HlsManageModal,
HlsModal, HlsModal,
LendAndReclaimModalController, LendAndReclaimModalController,
SettingsModal, SettingsModal,
@ -30,6 +31,7 @@ export default function ModalsContainer() {
<WalletAssets /> <WalletAssets />
<AlertDialogController /> <AlertDialogController />
<HlsModal /> <HlsModal />
<HlsManageModal />
</> </>
) )
} }

View File

@ -11,3 +11,4 @@ export { default as VaultModal } from 'components/Modals/Vault'
export { default as WalletAssets } from 'components/Modals/WalletAssets' export { default as WalletAssets } from 'components/Modals/WalletAssets'
export { default as WithdrawFromVaultsModal } from 'components/Modals/WithdrawFromVaultsModal' export { default as WithdrawFromVaultsModal } from 'components/Modals/WithdrawFromVaultsModal'
export { default as HlsModal } from 'components/Modals/HLS' export { default as HlsModal } from 'components/Modals/HLS'
export { default as HlsManageModal } from 'components/Modals/HLS/Manage'

View File

@ -11,6 +11,7 @@ export default function createModalSlice(set: SetState<ModalSlice>, get: GetStat
fundAndWithdrawModal: null, fundAndWithdrawModal: null,
getStartedModal: false, getStartedModal: false,
hlsInformationModal: null, hlsInformationModal: null,
hlsManageModal: null,
lendAndReclaimModal: null, lendAndReclaimModal: null,
resetStettingsModal: false, resetStettingsModal: false,
settingsModal: false, settingsModal: false,

View File

@ -4,6 +4,7 @@ interface ModalSlice {
alertDialog: AlertDialogConfig | null alertDialog: AlertDialogConfig | null
assetOverlayState: OverlayState assetOverlayState: OverlayState
hlsModal: HlsModal | null hlsModal: HlsModal | null
hlsManageModal: HlsManageModal | null
borrowModal: BorrowModal | null borrowModal: BorrowModal | null
fundAndWithdrawModal: 'fund' | 'withdraw' | null fundAndWithdrawModal: 'fund' | 'withdraw' | null
getStartedModal: boolean getStartedModal: boolean
@ -73,3 +74,10 @@ interface HlsModal {
strategy?: HLSStrategy strategy?: HLSStrategy
vault?: Vault vault?: Vault
} }
interface HlsManageModal {
staking: {
strategy: HLSStrategy
action: 'deposit' | 'withdraw' | 'repay'
}
}