Skip to content

Commit

Permalink
address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Angelle committed Sep 20, 2023
1 parent bcd79c6 commit 4759c09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
10 changes: 7 additions & 3 deletions centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RepayValues = {
export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
const pool = usePool(loan.poolId)
const account = useBorrower(loan.poolId, loan.id)
const balances = useBalances(account.signingAccount.address)
const balances = useBalances(account.actingAddress)
const balance = (balances && findBalance(balances.currencies, pool.currency.key)?.balance.toDecimal()) || Dec(0)
const { current: availableFinancing } = useAvailableFinancing(loan.poolId, loan.id)
const { execute: doFinanceTransaction, isLoading: isFinanceLoading } = useCentrifugeTransaction(
Expand Down Expand Up @@ -63,7 +63,9 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
const price = CurrencyBalance.fromFloat(values.price, pool.currency.decimals).div(new BN(100))
const quantity = Price.fromFloat((values.faceValue as number) / (values.price as number))

doFinanceTransaction([loan.poolId, loan.id, quantity, price, account.actingAddress])
doFinanceTransaction([loan.poolId, loan.id, quantity, price, account.actingAddress], {
account,
})
actions.setSubmitting(false)
},
validateOnMount: true,
Expand All @@ -78,7 +80,9 @@ export function ExternalFinanceForm({ loan }: { loan: LoanType }) {
const price = CurrencyBalance.fromFloat(values.price, pool.currency.decimals).div(new BN(100))
const quantity = Price.fromFloat((values.faceValue as number) / (values.price as number))

doRepayTransaction([loan.poolId, loan.id, quantity, new BN(0), new BN(0), price, account.actingAddress])
doRepayTransaction([loan.poolId, loan.id, quantity, new BN(0), new BN(0), price, account.actingAddress], {
account,
})
actions.setSubmitting(false)
},
validateOnMount: true,
Expand Down
28 changes: 10 additions & 18 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,17 +1390,13 @@ export function getPoolsModule(inst: Centrifuge) {
args: [poolId: string, loanId: string, quantity: BN, price: BN, aoProxy: string],
options?: TransactionOptions
) {
const [poolId, loanId, quantity, price, aoProxy] = args
const [poolId, loanId, quantity, price] = args
const $api = inst.getApi()
return $api.pipe(
switchMap((api) => {
const borrowSubmittable = api.tx.proxy.proxy(
aoProxy,
undefined,
api.tx.loans.borrow(poolId, loanId, {
external: { quantity: quantity.toString(), settlementPrice: price.toString() },
})
)
const borrowSubmittable = api.tx.loans.borrow(poolId, loanId, {
external: { quantity: quantity.toString(), settlementPrice: price.toString() },
})
return inst.wrapSignAndSend(api, borrowSubmittable, options)
})
)
Expand Down Expand Up @@ -1440,20 +1436,16 @@ export function getPoolsModule(inst: Centrifuge) {
args: [poolId: string, loanId: string, quantity: BN, interest: BN, unscheduled: BN, price: BN, aoProxy: string],
options?: TransactionOptions
) {
const [poolId, loanId, quantity, interest, unscheduled, price, aoProxy] = args
const [poolId, loanId, quantity, interest, unscheduled, price] = args
const $api = inst.getApi()

return $api.pipe(
switchMap((api) => {
const repaySubmittable = api.tx.proxy.proxy(
aoProxy,
undefined,
api.tx.loans.repay(poolId, loanId, {
principal: { external: { quantity: quantity.toString(), settlementPrice: price.toString() } },
interest: interest.toString(),
unscheduled: unscheduled.toString(),
})
)
const repaySubmittable = api.tx.loans.repay(poolId, loanId, {
principal: { external: { quantity: quantity.toString(), settlementPrice: price.toString() } },
interest: interest.toString(),
unscheduled: unscheduled.toString(),
})
return inst.wrapSignAndSend(api, repaySubmittable, options)
})
)
Expand Down

0 comments on commit 4759c09

Please sign in to comment.