fix: added isCreate flag to the vaultModal (#450)

This commit is contained in:
Linkie Link 2023-09-11 11:34:30 +02:00 committed by GitHub
parent 9f359bb6d0
commit f61dd3e4e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import Button from 'components/Button' import ActionButton from 'components/Button/ActionButton'
import VaultLogo from 'components/Earn/Farm/VaultLogo' import VaultLogo from 'components/Earn/Farm/VaultLogo'
import Text from 'components/Text' import Text from 'components/Text'
import TitleAndSubCell from 'components/TitleAndSubCell' import TitleAndSubCell from 'components/TitleAndSubCell'
@ -23,13 +23,14 @@ export default function VaultCard(props: Props) {
vaultModal: { vaultModal: {
vault: props.vault, vault: props.vault,
selectedBorrowDenoms: [props.vault.denoms.secondary], selectedBorrowDenoms: [props.vault.denoms.secondary],
isCreate: true,
}, },
}) })
} }
return ( return (
<div className='border-r-[1px] border-r-white/10 p-4'> <div className='border-r-[1px] border-r-white/10 p-4'>
<div className='align-center mb-8 flex justify-between'> <div className='flex justify-between mb-8 align-center'>
<div> <div>
<Text size='xs' className='mb-2 text-white/60'> <Text size='xs' className='mb-2 text-white/60'>
{props.subtitle} {props.subtitle}
@ -45,7 +46,7 @@ export default function VaultCard(props: Props) {
</div> </div>
<VaultLogo vault={props.vault} /> <VaultLogo vault={props.vault} />
</div> </div>
<div className='mb-6 flex justify-between'> <div className='flex justify-between mb-6'>
<TitleAndSubCell <TitleAndSubCell
className='text-xs' className='text-xs'
title={props.vault.apy ? formatPercent(props.vault.apy, 2) : '-'} title={props.vault.apy ? formatPercent(props.vault.apy, 2) : '-'}
@ -73,14 +74,7 @@ export default function VaultCard(props: Props) {
sub={'Depo. Cap'} sub={'Depo. Cap'}
/> />
</div> </div>
<Button <ActionButton onClick={openVaultModal} color='secondary' text='Deposit' className='w-full' />
color='secondary'
onClick={openVaultModal}
className='w-full'
disabled={!currentAccount}
>
{currentAccount ? 'Deposit' : 'Select Account'}
</Button>
</div> </div>
) )
} }

View File

@ -26,6 +26,7 @@ export default function VaultExpanded(props: Props) {
vault: props.row.original, vault: props.row.original,
isDeposited: true, isDeposited: true,
selectedBorrowDenoms: [props.row.original.denoms.secondary], selectedBorrowDenoms: [props.row.original.denoms.secondary],
isCreate: false,
}, },
}) })
} }
@ -99,7 +100,7 @@ export default function VaultExpanded(props: Props) {
return ( return (
<tr <tr
key={props.row.id} key={props.row.id}
className='cursor-pointer bg-black/20 transition-colors' className='transition-colors cursor-pointer bg-black/20'
onClick={(e) => { onClick={(e) => {
e.preventDefault() e.preventDefault()
const isExpanded = props.row.getIsExpanded() const isExpanded = props.row.getIsExpanded()
@ -108,7 +109,7 @@ export default function VaultExpanded(props: Props) {
}} }}
> >
<td colSpan={!status ? 7 : 8}> <td colSpan={!status ? 7 : 8}>
<div className='align-center flex justify-end gap-3 p-4'> <div className='flex justify-end gap-3 p-4 align-center'>
{status && <DepositMoreButton />} {status && <DepositMoreButton />}
{status === VaultStatus.ACTIVE && <UnlockButton />} {status === VaultStatus.ACTIVE && <UnlockButton />}
{status === VaultStatus.UNLOCKING && <UnlockingButton />} {status === VaultStatus.UNLOCKING && <UnlockingButton />}

View File

@ -209,6 +209,7 @@ export const VaultTable = (props: Props) => {
vaultModal: { vaultModal: {
vault, vault,
selectedBorrowDenoms: [vault.denoms.secondary], selectedBorrowDenoms: [vault.denoms.secondary],
isCreate: true,
}, },
}) })
} }

View File

@ -144,13 +144,14 @@ export default function VaultBorrowings(props: VaultBorrowingsProps) {
} }
async function onConfirm() { async function onConfirm() {
if (!updatedAccount) return if (!updatedAccount || !vaultModal) return
setIsConfirming(true) setIsConfirming(true)
const isSuccess = await depositIntoVault({ const isSuccess = await depositIntoVault({
accountId: updatedAccount.id, accountId: updatedAccount.id,
actions: props.depositActions, actions: props.depositActions,
deposits: props.deposits, deposits: props.deposits,
borrowings: props.borrowings, borrowings: props.borrowings,
isCreate: vaultModal.isCreate,
}) })
setIsConfirming(false) setIsConfirming(false)
if (isSuccess) { if (isSuccess) {

View File

@ -13,6 +13,7 @@ import useLocalStorage from 'hooks/useLocalStorage'
import useTransactionStore from 'hooks/useTransactionStore' import useTransactionStore from 'hooks/useTransactionStore'
import useStore from 'store' import useStore from 'store'
import { formatAmountWithSymbol } from 'utils/formatters' import { formatAmountWithSymbol } from 'utils/formatters'
import { BN } from 'utils/helpers'
export function generateToastContent(content: ToastSuccess['content']): ReactNode { export function generateToastContent(content: ToastSuccess['content']): ReactNode {
return content.map((item, index) => ( return content.map((item, index) => (
@ -23,11 +24,13 @@ export function generateToastContent(content: ToastSuccess['content']): ReactNod
{item.text} {item.text}
</Text> </Text>
<ul className='flex flex-wrap w-full gap-1 p-1 pl-4 list-disc'> <ul className='flex flex-wrap w-full gap-1 p-1 pl-4 list-disc'>
{item.coins.map((coin) => ( {item.coins.map((coin) =>
<li className='w-full p-0 text-sm text-white' key={coin.denom}> BN(coin.amount).isZero() ? null : (
{formatAmountWithSymbol(coin)} <li className='w-full p-0 text-sm text-white' key={coin.denom}>
</li> {formatAmountWithSymbol(coin)}
))} </li>
),
)}
</ul> </ul>
</> </>
)} )}
@ -70,7 +73,7 @@ export default function Toaster() {
<Text className='mb-1 font-bold text-white'>{`Credit Account ${toast.accountId}`}</Text> <Text className='mb-1 font-bold text-white'>{`Credit Account ${toast.accountId}`}</Text>
)} )}
{toast.message && ( {toast.message && (
<Text size='sm' className='text-white'> <Text size='sm' className='w-full mb-1 text-white'>
{toast.message} {toast.message}
</Text> </Text>
)} )}

View File

@ -29,6 +29,7 @@ interface HandleResponse {
| 'borrow' | 'borrow'
| 'repay' | 'repay'
| 'vault' | 'vault'
| 'vaultCreate'
| 'lend' | 'lend'
| 'create' | 'create'
| 'delete' | 'delete'
@ -94,10 +95,10 @@ export default function createBroadcastSlice(
switch (action) { switch (action) {
case 'borrow': case 'borrow':
const borrowCoin = changes.debts ? [changes.debts[0].toCoin()] : [] const borrowCoin = changes.debts ? [changes.debts[0].toCoin()] : []
const action = lend ? 'Borrowed and lend' : 'Borrowed' const borrowAction = lend ? 'Borrowed and lend' : 'Borrowed'
toast.content.push({ toast.content.push({
coins: borrowCoin, coins: borrowCoin,
text: target === 'wallet' ? 'Borrowed to wallet' : action, text: target === 'wallet' ? 'Borrowed to wallet' : borrowAction,
}) })
break break
@ -132,7 +133,9 @@ export default function createBroadcastSlice(
break break
case 'vault': case 'vault':
toast.message = 'Add to Vault Position' case 'vaultCreate':
toast.message =
action === 'vaultCreate' ? 'Created a Vault Position' : 'Add to Vault Position'
toast.content.push({ toast.content.push({
coins: changes.debts?.map((debt) => debt.toCoin()) ?? [], coins: changes.debts?.map((debt) => debt.toCoin()) ?? [],
text: 'Borrowed for the Vault Position', text: 'Borrowed for the Vault Position',
@ -422,6 +425,7 @@ export default function createBroadcastSlice(
actions: Action[] actions: Action[]
deposits: BNCoin[] deposits: BNCoin[]
borrowings: BNCoin[] borrowings: BNCoin[]
isCreate: boolean
}) => { }) => {
const msg: CreditManagerExecuteMsg = { const msg: CreditManagerExecuteMsg = {
update_credit_account: { update_credit_account: {
@ -436,7 +440,7 @@ export default function createBroadcastSlice(
handleResponseMessages({ handleResponseMessages({
response, response,
action: 'vault', action: options.isCreate ? 'vaultCreate' : 'vault',
accountId: options.accountId, accountId: options.accountId,
changes: { deposits: options.deposits, debts: options.borrowings }, changes: { deposits: options.deposits, debts: options.borrowings },
}) })

View File

@ -50,6 +50,7 @@ interface BroadcastSlice {
actions: Action[] actions: Action[]
deposits: BNCoin[] deposits: BNCoin[]
borrowings: BNCoin[] borrowings: BNCoin[]
isCreate: boolean
}) => Promise<boolean> }) => Promise<boolean>
executeMsg: (options: { messages: MsgExecuteContract[] }) => Promise<BroadcastResult> executeMsg: (options: { messages: MsgExecuteContract[] }) => Promise<BroadcastResult>
lend: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean> lend: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean>

View File

@ -47,6 +47,7 @@ interface VaultModal {
vault: Vault | DepositedVault vault: Vault | DepositedVault
isDeposited?: boolean isDeposited?: boolean
selectedBorrowDenoms: string[] selectedBorrowDenoms: string[]
isCreate: boolean
} }
interface AddVaultBorrowingsModal { interface AddVaultBorrowingsModal {