improve repay borrow order description
This commit is contained in:
parent
621839af25
commit
317c7579c2
|
@ -26,7 +26,7 @@ const BuyTokenInput = ({
|
|||
handleAmountOutChange: (e: NumberFormatValues, info: SourceInfo) => void
|
||||
loading?: boolean
|
||||
setShowTokenSelect: Dispatch<SetStateAction<'input' | 'output' | undefined>>
|
||||
handleRepay: (amountOut: string) => void
|
||||
handleRepay?: (amountOut: string) => void
|
||||
}) => {
|
||||
const { t } = useTranslation('common')
|
||||
const { mangoAccount } = useMangoAccount()
|
||||
|
@ -49,7 +49,7 @@ const BuyTokenInput = ({
|
|||
<div className="mb-2 grid grid-cols-2 rounded-xl bg-th-bkg-2 p-3">
|
||||
<div className="col-span-2 mb-2 flex items-end justify-between">
|
||||
<p className="text-th-fgd-2">{t('buy')}</p>
|
||||
{outputTokenBalanceBorrow ? (
|
||||
{handleRepay && outputTokenBalanceBorrow ? (
|
||||
<MaxAmountButton
|
||||
className="mb-0.5 text-xs"
|
||||
decimals={outputBank?.mintDecimals || 9}
|
||||
|
|
|
@ -222,14 +222,19 @@ const LimitSwapForm = ({
|
|||
|
||||
const handleTokenSelect = (type: 'input' | 'output') => {
|
||||
setShowTokenSelect(type)
|
||||
setFormErrors({})
|
||||
setTriggerPrice('')
|
||||
}
|
||||
|
||||
const hasBorrowToRepay = useMemo(() => {
|
||||
if (orderType !== OrderTypes.REPAY_BORROW || !outputBank || !mangoAccount)
|
||||
return
|
||||
const borrow = mangoAccount.getTokenBorrowsUi(outputBank)
|
||||
return borrow
|
||||
const balance = mangoAccount.getTokenBalanceUi(outputBank)
|
||||
const roundedBalance = floorToDecimal(
|
||||
balance,
|
||||
outputBank.mintDecimals,
|
||||
).toNumber()
|
||||
return balance && balance < 0 ? Math.abs(roundedBalance) : 0
|
||||
}, [mangoAccount, orderType, outputBank])
|
||||
|
||||
const isFormValid = useCallback(
|
||||
|
@ -611,13 +616,31 @@ const LimitSwapForm = ({
|
|||
? `${inputBankName} per ${outputBankName}`
|
||||
: `${outputBankName} per ${inputBankName}`
|
||||
|
||||
if (orderType === OrderTypes.REPAY_BORROW) {
|
||||
return t('trade:repay-borrow-order-desc', {
|
||||
amount: floorToDecimal(amountOutFormValue, outputBankDecimals),
|
||||
priceUnit: quoteString,
|
||||
symbol: outputBankName,
|
||||
triggerPrice: floorToDecimal(triggerPrice, inputBankDecimals),
|
||||
})
|
||||
if (hasBorrowToRepay && orderType === OrderTypes.REPAY_BORROW) {
|
||||
const amountOut = floorToDecimal(
|
||||
amountOutFormValue,
|
||||
outputBankDecimals,
|
||||
).toNumber()
|
||||
if (amountOut <= hasBorrowToRepay) {
|
||||
return t('trade:repay-borrow-order-desc', {
|
||||
amount: amountOut,
|
||||
priceUnit: quoteString,
|
||||
symbol: outputBankName,
|
||||
triggerPrice: floorToDecimal(triggerPrice, inputBankDecimals),
|
||||
})
|
||||
} else {
|
||||
const depositAmount = floorToDecimal(
|
||||
amountOut - hasBorrowToRepay,
|
||||
outputBankDecimals,
|
||||
).toNumber()
|
||||
return t('trade:repay-borrow-deposit-order-desc', {
|
||||
borrowAmount: hasBorrowToRepay,
|
||||
depositAmount: depositAmount,
|
||||
priceUnit: quoteString,
|
||||
symbol: outputBankName,
|
||||
triggerPrice: floorToDecimal(triggerPrice, inputBankDecimals),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
const orderTypeString =
|
||||
orderType === OrderTypes.STOP_LOSS
|
||||
|
@ -640,6 +663,7 @@ const LimitSwapForm = ({
|
|||
amountInFormValue,
|
||||
amountOutFormValue,
|
||||
flipPrices,
|
||||
hasBorrowToRepay,
|
||||
inputBankDecimals,
|
||||
inputBankName,
|
||||
orderType,
|
||||
|
@ -816,7 +840,9 @@ const LimitSwapForm = ({
|
|||
error={formErrors.hasBorrows}
|
||||
handleAmountOutChange={handleAmountOutChange}
|
||||
setShowTokenSelect={() => handleTokenSelect('output')}
|
||||
handleRepay={handleRepay}
|
||||
handleRepay={
|
||||
orderType === OrderTypes.REPAY_BORROW ? handleRepay : undefined
|
||||
}
|
||||
/>
|
||||
{swapFormSizeUi === 'slider' ? (
|
||||
<SwapSlider
|
||||
|
@ -838,7 +864,11 @@ const LimitSwapForm = ({
|
|||
<InlineNotification
|
||||
desc={
|
||||
<>
|
||||
<span className="text-th-down">{t('sell')}</span>{' '}
|
||||
{orderType !== OrderTypes.REPAY_BORROW ? (
|
||||
<>
|
||||
<span className="text-th-down">{t('sell')}</span>{' '}
|
||||
</>
|
||||
) : null}
|
||||
{orderDescription}
|
||||
</>
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"reduce": "Reduce",
|
||||
"reduce-only": "Reduce Only",
|
||||
"repay-borrow-order-desc": "Repay {{amount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"repay-borrow-deposit-order-desc": "Repay {{borrowAmount}} and buy {{depositAmount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"rises-to": "rises to",
|
||||
"sells": "Sells",
|
||||
"settle-funds": "Settle Funds",
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"reduce": "Reduce",
|
||||
"reduce-only": "Reduce Only",
|
||||
"repay-borrow-order-desc": "Repay {{amount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"repay-borrow-deposit-order-desc": "Repay {{borrowAmount}} and buy {{depositAmount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"rises-to": "rises to",
|
||||
"sells": "Sells",
|
||||
"settle-funds": "Settle Funds",
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"reduce": "Reduce",
|
||||
"reduce-only": "Reduce Only",
|
||||
"repay-borrow-order-desc": "Repay {{amount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"repay-borrow-deposit-order-desc": "Repay {{borrowAmount}} and buy {{depositAmount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"rises-to": "rises to",
|
||||
"sells": "Sells",
|
||||
"settle-funds": "Settle Funds",
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
"reduce": "Reduce",
|
||||
"reduce-only": "限减少",
|
||||
"repay-borrow-order-desc": "Repay {{amount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"repay-borrow-deposit-order-desc": "Repay {{borrowAmount}} and buy {{depositAmount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"rises-to": "rises to",
|
||||
"sells": "卖单",
|
||||
"settle-funds": "借清资金",
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"reduce": "Reduce",
|
||||
"reduce-only": "限減少",
|
||||
"repay-borrow-order-desc": "Repay {{amount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"repay-borrow-deposit-order-desc": "Repay {{borrowAmount}} and buy {{depositAmount}} {{symbol}} if the oracle price reaches {{triggerPrice}} {{priceUnit}}",
|
||||
"rises-to": "rises to",
|
||||
"sells": "賣單",
|
||||
"settle-funds": "借清資金",
|
||||
|
|
Loading…
Reference in New Issue