Skip to content

Commit

Permalink
Fix Tinlake Asset list (#2329)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Aug 1, 2024
1 parent 5e11184 commit fcbd16f
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions centrifuge-app/src/utils/tinlake/useTinlakePools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ function getTinlakeLoanStatus(loan: TinlakeLoanData, writeOffPercentage: Rate) {

// TODO: refactor to use multicall instead of subgraph
async function getTinlakeLoans(poolId: string) {
let pools: {
loans: unknown[]
}[] = []

const response = await fetch(import.meta.env.REACT_APP_TINLAKE_SUBGRAPH_URL, {
method: 'POST',
headers: {
Expand All @@ -255,25 +251,20 @@ async function getTinlakeLoans(poolId: string) {
body: JSON.stringify({
query: `
query GetLoansByPoolId($poolId: String!) {
pools (where: { id_in: [$poolId]}) {
loans (first: 1000) {
nftId
id
index
financingDate
debt
pool {
id
}
maturityDate
interestRatePerSecond
borrowsAggregatedAmount
repaysAggregatedAmount
ceiling
closed
riskGroup
owner
}
loans (where: { pool_: { id: $poolId } }, first: 1000) {
nftId
id
index
financingDate
debt
maturityDate
interestRatePerSecond
borrowsAggregatedAmount
repaysAggregatedAmount
ceiling
closed
riskGroup
owner
}
}
`,
Expand All @@ -288,19 +279,10 @@ async function getTinlakeLoans(poolId: string) {
if (errors?.length) {
throw new Error(`Issue fetching loans for Tinlake pool ${poolId}. Errors: ${errors}`)
}
pools = data.pools
return data.loans
} else {
throw new Error(`Issue fetching loans for Tinlake pool ${poolId}. Status: ${response?.status}`)
}

const loans = pools.reduce((assets: any[], pool: any) => {
if (pool.loans) {
assets.push(...pool.loans)
}
return assets
}, [])

return loans
}

export async function getWriteOffPercentages(pool: TinlakePool, loans: any[]) {
Expand Down

0 comments on commit fcbd16f

Please sign in to comment.