Skip to content
Open
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
41 changes: 0 additions & 41 deletions apps/main/src/lend/lib/apiLending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
RewardCrv,
RewardOther,
UserLoanDetails,
UserLoanHealth,
UserLoanState,
UserLoss,
UserMarketBalances,
} from '@/lend/types/lend.types'
Expand Down Expand Up @@ -316,45 +314,6 @@ const market = {
}

const user = {
fetchLoansDetailsHealth: async (api: Api, markets: OneWayMarketTemplate[]) => {
log('fetchUsersLoansDetailsHealth', api.chainId, markets.length)
const results: { [userActiveKey: string]: UserLoanHealth } = {}

await PromisePool.for(markets)
.handleError((errorObj, market) => {
console.error(errorObj)
const error = getErrorMessage(errorObj, 'error-api')
const userActiveKey = helpers.getUserActiveKey(api, market)
results[userActiveKey] = { healthFull: '', healthNotFull: '', error }
})
.process(async (market) => {
const userActiveKey = helpers.getUserActiveKey(api, market)
const [healthFull, healthNotFull] = await Promise.all([market.userHealth(), market.userHealth(false)])

results[userActiveKey] = { healthFull, healthNotFull, error: '' }
})

return results
},
fetchLoansDetailsState: async (api: Api, markets: OneWayMarketTemplate[]) => {
log('fetchUsersLoansDetailsState', api.chainId, markets.length)
const results: { [userActiveKey: string]: UserLoanState } = {}

await PromisePool.for(markets)
.handleError((errorObj, market) => {
console.error(errorObj)
const error = getErrorMessage(errorObj, 'error-api')
const userActiveKey = helpers.getUserActiveKey(api, market)
results[userActiveKey] = { collateral: '', borrowed: '', debt: '', N: '', error }
})
.process(async (market) => {
const userActiveKey = helpers.getUserActiveKey(api, market)
const state = await market.userState()
results[userActiveKey] = { ...state, error: '' }
})

return results
},
fetchLoansDetails: async (api: Api, markets: OneWayMarketTemplate[]) => {
log('fetchUsersLoansDetails', api.chainId, markets.length)
const results: { [userActiveKey: string]: UserLoanDetails } = {}
Expand Down
10 changes: 6 additions & 4 deletions apps/main/src/lend/store/createLoanRepaySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ const createLoanRepaySlice = (set: StoreApi<State>['setState'], get: StoreApi<St

const { stateCollateral, userBorrowed, userCollateral } = cFormValues

// userState
const userState = await user.fetchUserLoanState(api, market, shouldRefetch)

if (typeof userState === 'undefined') return
let userState: UserLoanState
try {
userState = { ...(await market.userState()), error: '' }
} catch (error) {
userState = { collateral: '', borrowed: '', debt: '', N: '', error }
}

// validation
const userBalancesResp = await user.fetchUserMarketBalances(api, market, true)
Expand Down
20 changes: 0 additions & 20 deletions apps/main/src/lend/store/createUserSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {
Api,
OneWayMarketTemplate,
UserLoanDetails,
UserLoanState,
UserMarketBalances,
UsersLoansDetailsMapper,
UsersLoansHealthsMapper,
UsersLoansStatesMapper,
UsersMarketsBalancesMapper,
} from '@/lend/types/lend.types'
import { getLoanExists } from '@/llamalend/queries/loan-exists'
Expand All @@ -22,10 +19,6 @@ const { cloneDeep } = lodash
type SliceState = {
loansDetailsMapper: UsersLoansDetailsMapper
marketsBalancesMapper: UsersMarketsBalancesMapper

// for market list
loansHealthsMapper: UsersLoansHealthsMapper
loansStatesMapper: UsersLoansStatesMapper
}

const sliceKey = 'user'
Expand All @@ -40,7 +33,6 @@ export type UserSlice = {
// individual
fetchUserLoanDetails(api: Api, market: OneWayMarketTemplate, shouldRefetch?: boolean): Promise<UserLoanDetails>
fetchUserMarketBalances(api: Api, market: OneWayMarketTemplate, shouldRefetch?: boolean): Promise<UserMarketBalances>
fetchUserLoanState(api: Api, market: OneWayMarketTemplate, shouldRefetch?: boolean): Promise<UserLoanState>
fetchAll(api: Api, market: OneWayMarketTemplate, shouldRefetch?: boolean): Promise<{ userLoanDetailsResp: UserLoanDetails | null; userLoanBalancesResp: UserMarketBalances; }>

// helpers
Expand All @@ -54,10 +46,6 @@ export type UserSlice = {
const DEFAULT_STATE: SliceState = {
loansDetailsMapper: {},
marketsBalancesMapper: {},

// for market list
loansHealthsMapper: {},
loansStatesMapper: {},
}

const createUserSlice = (set: StoreApi<State>['setState'], get: StoreApi<State>['getState']): UserSlice => ({
Expand Down Expand Up @@ -95,8 +83,6 @@ const createUserSlice = (set: StoreApi<State>['setState'], get: StoreApi<State>[

const fnMapper = {
loansDetailsMapper: apiLending.user.fetchLoansDetails,
loansHealthsMapper: apiLending.user.fetchLoansDetailsHealth,
loansStatesMapper: apiLending.user.fetchLoansDetailsState,
marketsBalancesMapper: apiLending.user.fetchMarketBalances,
}

Expand Down Expand Up @@ -147,12 +133,6 @@ const createUserSlice = (set: StoreApi<State>['setState'], get: StoreApi<State>[
const userActiveKey = helpers.getUserActiveKey(api, market)
return get()[sliceKey][key][userActiveKey]
},
fetchUserLoanState: async (api, market, shouldRefetch) => {
const key = 'loansStatesMapper'
await get()[sliceKey].fetchLoanDatas(key, api, [market], shouldRefetch)
const userActiveKey = helpers.getUserActiveKey(api, market)
return get()[sliceKey][key][userActiveKey]
},
fetchUserMarketBalances: async (api, market, shouldRefetch) => {
const key = 'marketsBalancesMapper'
await get()[sliceKey].fetchDatas(key, api, [market], shouldRefetch)
Expand Down
3 changes: 0 additions & 3 deletions apps/main/src/lend/types/lend.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ export type UserLoss = {
loss: string
loss_pct: string
}
export type UserLoanHealth = { healthFull: string; healthNotFull: string; error: string }
export type UsersLoansHealthsMapper = { [userActiveKey: string]: UserLoanHealth }
export type UserLoanState = { collateral: string; borrowed: string; debt: string; N: string; error: string }
export type UsersLoansStatesMapper = { [userActiveKey: string]: UserLoanState }
export type UserLoanDetails = {
details: {
health: string
Expand Down
Loading