Skip to content

Commit 918cc2e

Browse files
feat: show max debt on new borrow form
1 parent 4bb139b commit 918cc2e

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

apps/main/src/llamalend/features/borrow/components/CreateLoanForm.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BorrowPreset } from '@/llamalend/constants'
33
import { hasLeverage } from '@/llamalend/llama.utils'
44
import type { LlamaMarketTemplate, NetworkDict } from '@/llamalend/llamalend.types'
55
import type { CreateLoanOptions } from '@/llamalend/mutations/create-loan.mutation'
6+
import { FormMessage } from '@/llamalend/widgets/manage-loan/FormMessage'
67
import { LoanFormAlerts } from '@/llamalend/widgets/manage-loan/LoanFormAlerts'
78
import { LoanFormTokenInput } from '@/llamalend/widgets/manage-loan/LoanFormTokenInput'
89
import { LoanFormWrapper } from '@/llamalend/widgets/manage-loan/LoanFormWrapper'
@@ -115,6 +116,9 @@ export const CreateLoanForm = <ChainId extends IChainId>({
115116
testId="borrow-debt-input"
116117
network={network}
117118
maxFieldName="maxDebt"
119+
message={
120+
values.maxDebt && <FormMessage label={t`Max borrow:`} value={values.maxDebt} symbol={borrowToken?.symbol} />
121+
}
118122
/>
119123
</Stack>
120124

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Stack from '@mui/material/Stack'
2+
import Typography from '@mui/material/Typography'
3+
import { formatNumber } from '@ui-kit/utils'
4+
5+
export const FormMessage = ({
6+
value,
7+
label,
8+
symbol,
9+
}: {
10+
value: Decimal
11+
label: string
12+
symbol: string | undefined
13+
}) => (
14+
<Typography component={Stack} alignItems="center" direction="row" gap={1}>
15+
{label}
16+
<Typography color="text.secondary">
17+
{formatNumber(value, { abbreviate: true }) ?? '...'}
18+
{symbol}
19+
</Typography>
20+
</Typography>
21+
)

apps/main/src/llamalend/widgets/manage-loan/LoanFormTokenInput.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo } from 'react'
1+
import { type ReactNode, useCallback, useMemo } from 'react'
22
import type { FieldPath, FieldPathValue, FieldValues, UseFormReturn } from 'react-hook-form'
33
import type { Address } from 'viem'
44
import { useAccount } from 'wagmi'
@@ -24,6 +24,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
2424
isError,
2525
form,
2626
testId,
27+
message,
2728
network,
2829
maxFieldName,
2930
}: {
@@ -36,6 +37,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
3637
name: TFieldName
3738
form: UseFormReturn<TFieldValues> // the form, used to set the value and get errors
3839
testId: string
40+
message?: ReactNode
3941
network: LlamaNetwork
4042
/** Optional related max-field name whose errors should be reflected here */
4143
maxFieldName?: FieldPath<TFieldValues>
@@ -68,7 +70,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
6870
[form, name],
6971
)}
7072
isError={isError || isBalanceError || !!errors[name] || !!relatedMaxFieldError}
71-
message={errors[name]?.message ?? relatedMaxFieldError?.message}
73+
message={errors[name]?.message ?? relatedMaxFieldError?.message ?? message}
7274
walletBalance={useMemo(
7375
// todo: separate isLoading for balance and for maxBalance
7476
() => ({ balance, symbol: token?.symbol, loading: isBalanceLoading || isMaxLoading }),

0 commit comments

Comments
 (0)