Skip to content

Commit

Permalink
Add Solend to treasury investments UI (solana-labs#749)
Browse files Browse the repository at this point in the history
* add withdraw

* complete solend investment integration

* DRY investment mint

* remove console.log

* fix case where token has no strategy in main market

* fix case where token has no strategy in main market for withdraw too
  • Loading branch information
0xodia authored Jun 14, 2022
1 parent 0b7f00a commit e95676c
Show file tree
Hide file tree
Showing 10 changed files with 1,514 additions and 47 deletions.
16 changes: 13 additions & 3 deletions Strategies/components/DepositModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Modal from '@components/Modal'
import ModalHeader from './ModalHeader'
import SolendModalContent from './SolendModalContent'
import MangoDeposit from './MangoDepositComponent'
import BigNumber from 'bignumber.js'
import { SolendStrategy } from 'Strategies/types/types'

const DepositModal = ({
onClose,
isOpen,
proposedInvestment,
handledMint,
apy,
protocolName,
Expand All @@ -20,16 +22,24 @@ const DepositModal = ({
const currentPositionFtm = new BigNumber(
currentPosition.toFixed(0)
).toFormat()

return (
<Modal onClose={onClose} isOpen={isOpen}>
<Modal onClose={onClose} isOpen={Boolean(proposedInvestment)}>
<ModalHeader
apy={apy}
protocolLogoURI={protocolLogoSrc}
protocolName={protocolName}
TokenName={handledTokenName}
strategy={strategyName}
/>

{protocolName === 'Solend' ? (
<SolendModalContent
proposedInvestment={proposedInvestment as SolendStrategy}
governedTokenAccount={governedTokenAccount}
handledMint={handledMint}
createProposalFcn={createProposalFcn}
/>
) : null}
{protocolName === 'Mango' ? (
<MangoDeposit
governedTokenAccount={governedTokenAccount}
Expand Down
57 changes: 57 additions & 0 deletions Strategies/components/SolendModalContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useState } from 'react'
import { SolendStrategy } from 'Strategies/types/types'
import ButtonGroup from '@components/ButtonGroup'
import { AssetAccount } from '@utils/uiTypes/assets'
import { CreateSolendStrategyParams } from 'Strategies/protocols/solend'
import SolendDeposit from './solend/SolendDeposit'
import SolendWithdraw from './solend/SolendWithdraw'

const DEPOSIT = 'Deposit'
const WITHDRAW = 'Withdraw'

const SolendDepositComponent = ({
proposedInvestment,
handledMint,
createProposalFcn,
governedTokenAccount,
}: {
proposedInvestment: SolendStrategy
handledMint: string
createProposalFcn: CreateSolendStrategyParams
governedTokenAccount: AssetAccount
}) => {
const [proposalType, setProposalType] = useState('Deposit')

const tabs = [DEPOSIT, WITHDRAW]

return (
<div>
<div className="pb-4">
<ButtonGroup
activeValue={proposalType}
className="h-10"
onChange={(v) => setProposalType(v)}
values={tabs}
/>
</div>
{proposalType === WITHDRAW && (
<SolendWithdraw
proposedInvestment={proposedInvestment}
handledMint={handledMint}
createProposalFcn={createProposalFcn}
governedTokenAccount={governedTokenAccount}
/>
)}
{proposalType === DEPOSIT && (
<SolendDeposit
proposedInvestment={proposedInvestment}
handledMint={handledMint}
createProposalFcn={createProposalFcn}
governedTokenAccount={governedTokenAccount}
/>
)}
</div>
)
}

export default SolendDepositComponent
Loading

0 comments on commit e95676c

Please sign in to comment.