From 97666e0cfb9a4330ebbae786880e6a3ea32820ce Mon Sep 17 00:00:00 2001 From: Onno Visser Date: Fri, 4 Aug 2023 16:28:58 +0200 Subject: [PATCH] CentrifugeJS: Loan refactor (#1521) --- .../pages/IssuerPool/Assets/CreateLoan.tsx | 3 + .../pages/IssuerPool/Assets/PricingInput.tsx | 30 ++- .../src/pages/Loan/ExternalFinanceForm.tsx | 21 +- centrifuge-app/src/pages/Loan/FinanceForm.tsx | 25 +- centrifuge-js/src/modules/pools.ts | 220 +++++++++++------- fabric/src/components/CurrencyInput/index.tsx | 21 +- 6 files changed, 194 insertions(+), 126 deletions(-) diff --git a/centrifuge-app/src/pages/IssuerPool/Assets/CreateLoan.tsx b/centrifuge-app/src/pages/IssuerPool/Assets/CreateLoan.tsx index 3127e5ccc8..a9b3f191b3 100644 --- a/centrifuge-app/src/pages/IssuerPool/Assets/CreateLoan.tsx +++ b/centrifuge-app/src/pages/IssuerPool/Assets/CreateLoan.tsx @@ -68,6 +68,7 @@ export type CreateLoanFormValues = { discountRate: number | '' maxBorrowQuantity: number | '' Isin: string + notional: number | '' } } @@ -220,6 +221,7 @@ function IssuerCreateLoan() { discountRate: '', maxBorrowQuantity: '', Isin: '', + notional: '', }, }, onSubmit: async (values, { setSubmitting }) => { @@ -234,6 +236,7 @@ function IssuerCreateLoan() { : null, Isin: values.pricing.Isin || '', maturityDate: new Date(values.pricing.maturityDate), + interestRate: Rate.fromPercent(values.pricing.interestRate), } : { valuationMethod: values.pricing.valuationMethod, diff --git a/centrifuge-app/src/pages/IssuerPool/Assets/PricingInput.tsx b/centrifuge-app/src/pages/IssuerPool/Assets/PricingInput.tsx index 5d02a8a491..f5796eeae0 100644 --- a/centrifuge-app/src/pages/IssuerPool/Assets/PricingInput.tsx +++ b/centrifuge-app/src/pages/IssuerPool/Assets/PricingInput.tsx @@ -44,6 +44,19 @@ export function PricingInput({ poolId }: { poolId: string }) { name="pricing.Isin" validate={validate.Isin} /> + + {({ field, meta, form }: FieldProps) => ( + form.setFieldValue('pricing.notional', value)} + variant="small" + /> + )} + )} @@ -93,18 +106,17 @@ export function PricingInput({ poolId }: { poolId: string }) { max={new Date(Date.now() + 5 * 365 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10)} /> + } + placeholder="0.00" + rightElement="%" + name="pricing.interestRate" + validate={validate.fee} + /> {(values.pricing.valuationMethod === 'discountedCashFlow' || values.pricing.valuationMethod === 'outstandingDebt') && ( <> - } - placeholder="0.00" - rightElement="%" - name="pricing.interestRate" - validate={validate.fee} - /> - } diff --git a/centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx b/centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx index 00b4a8224e..f87c1afc82 100644 --- a/centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx +++ b/centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx @@ -114,7 +114,6 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) { const debt = loan.outstandingDebt?.toDecimal() || Dec(0) const poolReserve = pool?.reserve.available.toDecimal() ?? Dec(0) const maxBorrow = poolReserve.lessThan(availableFinancing) ? poolReserve : availableFinancing - const maturityDatePassed = loan?.pricing && 'maturityDate' in loan.pricing && new Date() > new Date(loan.pricing.maturityDate) @@ -201,16 +200,16 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) { This is calculated through the amount multiplied by the current price of the asset - {poolReserve.lessThan(availableFinancing) || - ('valuationMethod' in loan.pricing && !loan.pricing.maxBorrowAmount && ( - - - - The pool's available reserve ({formatBalance(poolReserve, pool?.currency.symbol)}) is smaller - than the available financing - - - ))} + {(poolReserve.lessThan(availableFinancing) || + ('valuationMethod' in loan.pricing && !loan.pricing.maxBorrowAmount)) && ( + + + + The pool's available reserve ({formatBalance(poolReserve, pool?.currency.symbol)}) is smaller + than the available financing + + + )}