diff --git a/centrifuge-app/src/pages/Loan/RepayForm.tsx b/centrifuge-app/src/pages/Loan/RepayForm.tsx index 1f391c1db..6ecbf4ecc 100644 --- a/centrifuge-app/src/pages/Loan/RepayForm.tsx +++ b/centrifuge-app/src/pages/Loan/RepayForm.tsx @@ -8,7 +8,7 @@ import { combineLatest, switchMap } from 'rxjs' import { Dec, max as maxDec, min } from '../../utils/Decimal' import { formatBalance, roundDown } from '../../utils/formatting' import { useFocusInvalidInput } from '../../utils/useFocusInvalidInput' -import { useAvailableFinancing, useLoans } from '../../utils/useLoans' +import { useLoans } from '../../utils/useLoans' import { useBorrower } from '../../utils/usePermissions' import { usePool } from '../../utils/usePools' import { @@ -18,7 +18,7 @@ import { positiveNumberNotRequired, } from '../../utils/validation' import { useChargePoolFees } from './ChargeFeesFields' -import { ExternalRepayForm } from './ExternalRepayForm' +import { SellForm } from './SellForm' import { SourceSelect } from './SourceSelect' import { isExternalLoan } from './utils' @@ -37,7 +37,7 @@ export function RepayForm({ loan }: { loan: ActiveLoan }) { {isExternalLoan(loan) ? 'Sell' : 'Repay'} setDestination(newSource)} type="repay" /> {isExternalLoan(loan) ? ( - + ) : ( )} @@ -50,8 +50,6 @@ function InternalRepayForm({ loan, destination }: { loan: ActiveLoan; destinatio const account = useBorrower(loan.poolId, loan.id) const balances = useBalances(account?.actingAddress) const balance = (balances && findBalance(balances.currencies, pool.currency.key)?.balance.toDecimal()) || Dec(0) - console.log('🚀 ~ balance:', balance.toString()) - const { debtWithMargin } = useAvailableFinancing(loan.poolId, loan.id) const poolFees = useChargePoolFees(loan.poolId, loan.id) const loans = useLoans(loan.poolId) const destinationLoan = loans?.find((l) => l.id === destination) as ActiveLoan @@ -133,7 +131,7 @@ function InternalRepayForm({ loan, destination }: { loan: ActiveLoan; destinatio if (destination !== 'reserve') { maxAvailable = destinationLoan.outstandingDebt?.toDecimal() maxPrincipal = destinationLoan.outstandingDebt.toDecimal() - maxInterest = destinationLoan.outstandingInterest.toDecimal() + maxInterest = loan.outstandingInterest.toDecimal() } const totalRepay = Dec(principal || 0) .add(Dec(interest || 0)) @@ -187,7 +185,7 @@ function InternalRepayForm({ loan, destination }: { loan: ActiveLoan; destinatio value={field.value instanceof Decimal ? field.value.toNumber() : field.value} label="Interest" secondaryLabel={`${formatBalance( - destination === 'reserve' ? loan.outstandingInterest : destinationLoan.outstandingInterest, + loan.outstandingInterest, pool?.currency.symbol, 2 )} interest accrued`} diff --git a/centrifuge-app/src/pages/Loan/ExternalRepayForm.tsx b/centrifuge-app/src/pages/Loan/SellForm.tsx similarity index 97% rename from centrifuge-app/src/pages/Loan/ExternalRepayForm.tsx rename to centrifuge-app/src/pages/Loan/SellForm.tsx index f10612968..af5e98e61 100644 --- a/centrifuge-app/src/pages/Loan/ExternalRepayForm.tsx +++ b/centrifuge-app/src/pages/Loan/SellForm.tsx @@ -21,8 +21,10 @@ type RepayValues = { quantity: number | '' fees: { id: string; amount: number | '' | Decimal }[] } - -export function ExternalRepayForm({ loan, destination }: { loan: ExternalLoan; destination: string }) { +/** + * Repay form for loans with `valuationMethod === oracle + */ +export function SellForm({ loan, destination }: { loan: ExternalLoan; destination: string }) { const pool = usePool(loan.poolId) const account = useBorrower(loan.poolId, loan.id) const balances = useBalances(account?.actingAddress) @@ -122,7 +124,7 @@ export function ExternalRepayForm({ loan, destination }: { loan: ExternalLoan; d let maxInterest = min(balance, outstandingInterest) if (destination !== 'reserve') { maxAvailable = destinationLoan.outstandingDebt?.toDecimal() || Dec(0) - maxInterest = destinationLoan.outstandingInterest.toDecimal() || Dec(0) + maxInterest = outstandingInterest || Dec(0) } return { maxAvailable, @@ -207,7 +209,7 @@ export function ExternalRepayForm({ loan, destination }: { loan: ExternalLoan; d label="Interest" errorMessage={meta.touched ? meta.error : undefined} secondaryLabel={`${formatBalance( - destination === 'reserve' ? loan.outstandingInterest : destinationLoan.outstandingInterest, + loan.outstandingInterest, pool?.currency.symbol, 2 )} interest accrued`}