Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BorrowPreset } from '@/llamalend/constants'
import { hasLeverage } from '@/llamalend/llama.utils'
import type { LlamaMarketTemplate, NetworkDict } from '@/llamalend/llamalend.types'
import type { CreateLoanOptions } from '@/llamalend/mutations/create-loan.mutation'
import { FormMessage } from '@/llamalend/widgets/manage-loan/FormMessage'
import { LoanFormAlerts } from '@/llamalend/widgets/manage-loan/LoanFormAlerts'
import { LoanFormTokenInput } from '@/llamalend/widgets/manage-loan/LoanFormTokenInput'
import { LoanFormWrapper } from '@/llamalend/widgets/manage-loan/LoanFormWrapper'
Expand Down Expand Up @@ -115,6 +116,9 @@ export const CreateLoanForm = <ChainId extends IChainId>({
testId="borrow-debt-input"
network={network}
maxFieldName="maxDebt"
message={
values.maxDebt && <FormMessage label={t`Max borrow:`} value={values.maxDebt} symbol={borrowToken?.symbol} />
}
/>
</Stack>

Expand Down
23 changes: 23 additions & 0 deletions apps/main/src/llamalend/widgets/manage-loan/FormMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Stack from '@mui/material/Stack'
import Typography from '@mui/material/Typography'
import { Decimal, formatNumber } from '@ui-kit/utils'

export const FormMessage = ({
value,
label,
symbol,
}: {
value: Decimal
label: string
symbol: string | undefined
}) => (
<Stack alignItems="center" direction="row" gap={1}>
<Typography color="text.secondary" variant="bodyXsRegular">
{label}
</Typography>
<Typography color="text.tertiary" variant="bodyXsRegular">
{formatNumber(value, { abbreviate: true }) ?? '...'}
{symbol}
</Typography>
</Stack>
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react'
import { type ReactNode, useCallback, useMemo } from 'react'
import type { FieldPath, FieldPathValue, FieldValues, UseFormReturn } from 'react-hook-form'
import type { Address } from 'viem'
import { useAccount } from 'wagmi'
Expand All @@ -24,6 +24,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
isError,
form,
testId,
message,
network,
maxFieldName,
}: {
Expand All @@ -36,6 +37,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
name: TFieldName
form: UseFormReturn<TFieldValues> // the form, used to set the value and get errors
testId: string
message?: ReactNode
network: LlamaNetwork
/** Optional related max-field name whose errors should be reflected here */
maxFieldName?: FieldPath<TFieldValues>
Expand Down Expand Up @@ -68,7 +70,7 @@ export const LoanFormTokenInput = <TFieldValues extends FieldValues, TFieldName
[form, name],
)}
isError={isError || isBalanceError || !!errors[name] || !!relatedMaxFieldError}
message={errors[name]?.message ?? relatedMaxFieldError?.message}
message={errors[name]?.message ?? relatedMaxFieldError?.message ?? message}
walletBalance={useMemo(
// todo: separate isLoading for balance and for maxBalance
() => ({ balance, symbol: token?.symbol, loading: isBalanceLoading || isMaxLoading }),
Expand Down
Loading