Skip to content

Commit

Permalink
Merge branch 'main' into fix-execute-epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Jan 19, 2024
2 parents c9d5850 + 8f6cb4f commit c8d36ba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
18 changes: 3 additions & 15 deletions centrifuge-app/src/components/DebugFlags/DebugFlags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Panel: React.FC<{
const { showUnusedFlags } = useDebugFlags()

return (
<StyledPanel position="fixed" bottom={0} right={0} zIndex="overlay">
<StyledPanel position="fixed" bottom={0} right={0} zIndex="onTopOfTheWorld">
<Shelf
justifyContent="center"
width="400px"
Expand Down Expand Up @@ -94,17 +94,11 @@ const Panel: React.FC<{
name={key}
checked={value as boolean}
onChange={(e) => onChange(key as Key, e.target.checked)}
disabled={!used}
/>
)
} else if (obj.type === 'select' && obj.options) {
el = (
<select
name={key}
value={value as string}
onChange={(e) => onChange(key as Key, e.target.value)}
disabled={!used}
>
<select name={key} value={value as string} onChange={(e) => onChange(key as Key, e.target.value)}>
{Object.keys(obj.options).map((option, index) => (
<option key={`${option}-${index}`} value={option}>
{option}
Expand All @@ -121,18 +115,12 @@ const Panel: React.FC<{
onChange={(e) => onChange(key as Key, e.target.value)}
type="text"
color="#ddd"
disabled={!used}
/>
)
}

return visible ? (
<Shelf
as="label"
justifyContent="space-between"
key={key}
style={{ pointerEvents: used ? 'initial' : 'none' }}
>
<Shelf as="label" justifyContent="space-between" key={key}>
<Text
fontSize="inherit"
fontFamily="inherit"
Expand Down
5 changes: 2 additions & 3 deletions centrifuge-app/src/pages/Loan/ExternalFinanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useFocusInvalidInput } from '../../utils/useFocusInvalidInput'
import { useAvailableFinancing } from '../../utils/useLoans'
import { useBorrower } from '../../utils/usePermissions'
import { usePool } from '../../utils/usePools'
import { combine, maxPriceVariance, positiveNumber, settlementPrice } from '../../utils/validation'
import { combine, maxPriceVariance, nonNegativeNumber, settlementPrice } from '../../utils/validation'
import { WithdrawSelect } from './FinanceForm'

type FinanceValues = {
Expand All @@ -23,7 +23,6 @@ export function ExternalFinanceForm({ loan }: { loan: ExternalLoan }) {
const pool = usePool(loan.poolId) as Pool
const account = useBorrower(loan.poolId, loan.id)
if (!account) throw new Error('No borrower')
console.log('account', account)
const { current: availableFinancing } = useAvailableFinancing(loan.poolId, loan.id)
const { execute: doFinanceTransaction, isLoading: isFinanceLoading } = useCentrifugeTransaction(
'Finance asset',
Expand Down Expand Up @@ -125,7 +124,7 @@ export function ExternalFinanceFields({
const maxBorrow = min(poolReserve, availableFinancing)
return (
<>
<Field name="faceValue" validate={combine(positiveNumber())}>
<Field name="faceValue" validate={combine(nonNegativeNumber())}>
{({ field, meta, form }: FieldProps) => {
return (
<CurrencyInput
Expand Down
10 changes: 6 additions & 4 deletions centrifuge-app/src/utils/useLiquidityPools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Centrifuge from '@centrifuge/centrifuge-js'
import { useCentrifuge, useCentrifugeQuery, useWallet } from '@centrifuge/centrifuge-react'
import { useQuery } from 'react-query'
import { useAddress } from './useAddress'

export function useDomainRouters(suspense?: boolean) {
const [data] = useCentrifugeQuery(['domainRouters'], (cent) => cent.liquidityPools.getDomainRouters(), { suspense })
Expand Down Expand Up @@ -106,8 +107,9 @@ export function useLPEvents(poolId: string, trancheId: string, lpAddress?: strin

export function useLiquidityPoolInvestment(poolId: string, trancheId: string, lpIndex?: number) {
const {
evm: { chainId, getProvider, selectedAddress },
evm: { chainId, getProvider },
} = useWallet()
const address = useAddress('evm')
const cent = useCentrifuge()
const { data: domains } = useActiveDomains(poolId)
const managerAddress = domains?.find((d) => d.chainId === chainId)?.managerAddress
Expand All @@ -116,10 +118,10 @@ export function useLiquidityPoolInvestment(poolId: string, trancheId: string, lp
const lp = lps?.[lpIndex ?? 0]

const query = useQuery(
['lpInvestment', chainId, lp?.lpAddress, selectedAddress],
['lpInvestment', chainId, lp?.lpAddress, address],
async () => ({
...(await cent.liquidityPools.getLiquidityPoolInvestment(
[selectedAddress!, managerAddress!, lp!.lpAddress, lp!.currencyAddress],
[address!, managerAddress!, lp!.lpAddress, lp!.currencyAddress],
{
rpcProvider: getProvider(chainId!),
}
Expand All @@ -128,7 +130,7 @@ export function useLiquidityPoolInvestment(poolId: string, trancheId: string, lp
}),

{
enabled: !!lp && !!selectedAddress,
enabled: !!lp && !!address,
}
)

Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/utils/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const required = (err?: CustomError) => (val?: any) =>

export const nonNegativeNumber = (err?: CustomError) => (val?: any) => {
const num = val instanceof Decimal ? val.toNumber() : val
return Number.isFinite(num) && num >= 0 ? '' : getError(`Value must be positive`, err, num)
return Number.isFinite(num) && num >= 0 ? '' : getError(`Value must be positive or zero`, err, num)
}

export const positiveNumber = (err?: CustomError) => (val?: any) => {
Expand Down
19 changes: 9 additions & 10 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2848,12 +2848,11 @@ export function getPoolsModule(inst: Centrifuge) {
api.query.loans.createdLoan.entries(poolId),
api.query.loans.activeLoans(poolId),
api.query.loans.closedLoan.entries(poolId),
api.query.oraclePriceFeed.fedValues.entries(),
api.query.ormlAssetRegistry.metadata((poolValue.toPrimitive() as any).currency),
api.call.loansApi.portfolio(poolId), // TODO: remove loans.activeLoans and use values from this runtime call
]).pipe(take(1))
}),
map(([createdLoanValues, activeLoanValues, closedLoanValues, oracles, rawCurrency, rawPortfolio]) => {
map(([createdLoanValues, activeLoanValues, closedLoanValues, rawCurrency, rawPortfolio]) => {
const currency = rawCurrency.toPrimitive() as AssetCurrencyData

const oraclePrices: Record<
Expand All @@ -2863,14 +2862,14 @@ export function getPoolsModule(inst: Centrifuge) {
value: CurrencyBalance
}
> = {}
oracles.forEach(() => {
// TODO: Fix oracles
// const { timestamp, value } = oracle[1].toPrimitive() as any
// oraclePrices[(oracle[0].toHuman() as any)[0].Isin] = {
// timestamp,
// value: new CurrencyBalance(value, currency.decimals),
// }
})
// oracles.forEach(() => {
// TODO: Fix oracles
// const { timestamp, value } = oracle[1].toPrimitive() as any
// oraclePrices[(oracle[0].toHuman() as any)[0].Isin] = {
// timestamp,
// value: new CurrencyBalance(value, currency.decimals),
// }
// })

const activeLoansPortfolio: Record<
string,
Expand Down

0 comments on commit c8d36ba

Please sign in to comment.