Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Point subquery to new version #2434

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion centrifuge-app/.env-config/.env.ff-prod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REACT_APP_ONBOARDING_API_URL=https://europe-central2-centrifuge-production-x.clo
REACT_APP_PINNING_API_URL=https://europe-central2-centrifuge-production-x.cloudfunctions.net/pinning-api-production
REACT_APP_POOL_CREATION_TYPE=propose
REACT_APP_RELAY_WSS_URL=wss://rpc.polkadot.io
REACT_APP_SUBQUERY_URL=https://subql.embrio.tech
REACT_APP_SUBQUERY_URL=https://api.centrifuge.io
REACT_APP_SUBSCAN_URL=https://centrifuge.subscan.io
REACT_APP_TINLAKE_NETWORK=mainnet
REACT_APP_INFURA_KEY=8ed99a9a115349bbbc01dcf3a24edc96
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/.env-config/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REACT_APP_ONBOARDING_API_URL=https://europe-central2-centrifuge-production-x.clo
REACT_APP_PINNING_API_URL=https://europe-central2-centrifuge-production-x.cloudfunctions.net/pinning-api-production
REACT_APP_POOL_CREATION_TYPE=propose
REACT_APP_RELAY_WSS_URL=wss://rpc.polkadot.io
REACT_APP_SUBQUERY_URL=https://subql.embrio.tech
REACT_APP_SUBQUERY_URL=https://api.centrifuge.io
REACT_APP_SUBSCAN_URL=https://centrifuge.subscan.io
REACT_APP_TINLAKE_NETWORK=mainnet
REACT_APP_INFURA_KEY=8ed99a9a115349bbbc01dcf3a24edc96
Expand Down
46 changes: 33 additions & 13 deletions centrifuge-app/src/pages/Loan/FinanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@
}
return combineLatest([financeTx, withdraw.getBatch(financeForm), poolFees.getBatch(financeForm)]).pipe(
switchMap(([loanTx, withdrawBatch, poolFeesBatch]) => {
const batch = [...withdrawBatch, ...poolFeesBatch]
let batch = []
if (withdrawBatch.length) {
}
batch = [...withdrawBatch, ...poolFeesBatch]
let tx = wrapProxyCallsForAccount(api, loanTx, account, 'Borrow')
if (batch.length) {
tx = api.tx.utility.batchAll([tx, ...batch])
Expand Down Expand Up @@ -163,7 +166,7 @@

React.useEffect(() => {
financeForm.validateForm()
}, [source])

Check warning on line 169 in centrifuge-app/src/pages/Loan/FinanceForm.tsx

View workflow job for this annotation

GitHub Actions / build-app

React Hook React.useEffect has a missing dependency: 'financeForm'. Either include it or remove the dependency array

Check warning on line 169 in centrifuge-app/src/pages/Loan/FinanceForm.tsx

View workflow job for this annotation

GitHub Actions / ff-prod / build-app

React Hook React.useEffect has a missing dependency: 'financeForm'. Either include it or remove the dependency array

const financeFormRef = React.useRef<HTMLFormElement>(null)
useFocusInvalidInput(financeForm, financeFormRef)
Expand Down Expand Up @@ -487,6 +490,30 @@
const ao = access.assetOriginators.find((a) => a.address === borrower.actingAddress)
const withdrawAddresses = ao?.transferAllowlist ?? []

const sortedBalances = sortBalances(muxBalances?.currencies || [], pool.currency)
const ignoredCurrencies = Object.entries(selectedAddressIndexByCurrency).flatMap(([key, index]) => {
return index === -1 ? [key] : []
})
const { buckets: withdrawAmounts } = muxBalances?.currencies
? divideBetweenCurrencies(amount, sortedBalances, withdrawAddresses, ignoredCurrencies)
: { buckets: [] }

const totalAvailable = withdrawAmounts.reduce((acc, cur) => acc.add(cur.amount), Dec(0))

React.useEffect(() => {
if (withdrawAddresses.length > 0 && sortedBalances.length > 0) {
const initialSelectedAddresses: Record<string, number> = {}
sortedBalances.forEach((balance) => {
const currencyKey = currencyToString(balance.currency.key)
if (!(currencyKey in initialSelectedAddresses)) {
initialSelectedAddresses[currencyKey] = 0
}
})
setSelectedAddressIndexByCurrency(initialSelectedAddresses)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [withdrawAddresses])

if (!isLocalAsset) {
return {
render: () => <WithdrawSelect withdrawAddresses={withdrawAddresses} poolId={poolId} />,
Expand Down Expand Up @@ -514,16 +541,6 @@
}
}

const sortedBalances = sortBalances(muxBalances?.currencies || [], pool.currency)
const ignoredCurrencies = Object.entries(selectedAddressIndexByCurrency).flatMap(([key, index]) => {
return index === -1 ? [key] : []
})
const { buckets: withdrawAmounts } = muxBalances?.currencies
? divideBetweenCurrencies(amount, sortedBalances, withdrawAddresses, ignoredCurrencies)
: { buckets: [] }

const totalAvailable = withdrawAmounts.reduce((acc, cur) => acc.add(cur.amount), Dec(0))

return {
render: () => (
<Mux
Expand All @@ -540,10 +557,13 @@
amount={amount}
/>
),
isValid: ({ values }: { values: Pick<FinanceValues, 'withdraw'> }) => {
return source === 'reserve' ? amount.lte(totalAvailable) && !!values.withdraw : true
isValid: (_: { values: Pick<FinanceValues, 'withdraw'> }) => {
const withdrawalAddresses = Object.values(selectedAddressIndexByCurrency).filter((index) => index !== -1)
return source === 'reserve' ? amount.lte(totalAvailable) && !!withdrawalAddresses.length : true
},
getBatch: () => {
const withdrawalAddresses = Object.values(selectedAddressIndexByCurrency).filter((index) => index !== -1)
if (!withdrawalAddresses.length) return of([])
return combineLatest(
withdrawAmounts.flatMap((bucket) => {
const index = selectedAddressIndexByCurrency[bucket.currencyKey] ?? 0
Expand Down
26 changes: 2 additions & 24 deletions centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { switchMap } from 'rxjs'
import daiLogo from '../../assets/images/dai-logo.svg'
import usdcLogo from '../../assets/images/usdc-logo.svg'
import { ButtonGroup } from '../../components/ButtonGroup'
import { DataCol, DataRow, DataTable } from '../../components/DataTable'
import { DataTable } from '../../components/DataTable'
import { LayoutSection } from '../../components/LayoutBase/LayoutSection'
import { AssetName } from '../../components/LoanList'
import { RouterTextLink } from '../../components/TextLink'
Expand Down Expand Up @@ -371,29 +371,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) {
)
}
>
<DataTable
data={[...reserveRow, ...cashLoans, ...form.values.feed]}
columns={columns}
footer={
<DataRow>
<DataCol align="left">
<Text color="accentPrimary" variant="body2">
Total
</Text>
</DataCol>
<DataCol />
<DataCol />
<DataCol />
<DataCol />
{isEditing && <DataCol />}
<DataCol>
<Text color="accentPrimary" variant="body2">
{formatBalance(newNav, pool.currency.symbol)}
</Text>
</DataCol>
</DataRow>
}
/>
<DataTable data={[...reserveRow, ...cashLoans, ...form.values.feed]} columns={columns} />
</LayoutSection>
</FormikProvider>
</Stack>
Expand Down
6 changes: 5 additions & 1 deletion centrifuge-app/src/pages/NavManagement/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export function NavOverviewCard({ poolId }: { poolId: string }) {
current={pool.nav.total.toFloat()}
change={changeInValuation ? new CurrencyBalance(changeInValuation, pool.currency.decimals).toFloat() : 0}
pendingFees={pendingFees.toFloat()}
pendingNav={pool.nav.total.toFloat() - pendingFees.toFloat()}
pendingNav={new CurrencyBalance(changeInValuation, pool.currency.decimals)
.toDecimal()
.add(pool.nav.total.toDecimal())
.sub(pendingFees.toDecimal())
.toNumber()}
/>
)
}
Expand Down
Loading