Skip to content

Commit db9ad72

Browse files
committed
refactor add invalidateAllUserBorrowDetails
1 parent d59011a commit db9ad72

8 files changed

+21
-42
lines changed

apps/main/src/loan/entities/user-loan-details.query.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cloneDeep } from 'lodash'
22
import { zeroAddress } from 'viem'
3+
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
34
import { BN } from '@ui/utils'
45
import { requireLib } from '@ui-kit/features/connect-wallet'
56
import { queryFactory, rootKeys, type UserMarketParams, type UserMarketQuery } from '@ui-kit/lib/model'
@@ -164,3 +165,8 @@ export const {
164165
staleTime: '1m',
165166
validationSuite: userMarketValidationSuite,
166167
})
168+
169+
export const invalidateAllUserBorrowDetails = (params: UserMarketParams) => {
170+
invalidateLoanExists(params)
171+
invalidateUserLoanDetails(params)
172+
}

apps/main/src/loan/store/createLoanCollateralDecreaseSlice.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import lodash from 'lodash'
22
import type { StoreApi } from 'zustand'
3-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
43
import type { FormStatus, FormValues } from '@/loan/components/PageLoanManage/CollateralDecrease/types'
54
import type { FormDetailInfo, FormEstGas } from '@/loan/components/PageLoanManage/types'
65
import {
@@ -16,7 +15,7 @@ import { getTokenName } from '@/loan/utils/utilsLoan'
1615
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1716
import { useWallet } from '@ui-kit/features/connect-wallet'
1817
import { setMissingProvider } from '@ui-kit/utils/store.util'
19-
import { invalidateUserLoanDetails } from '../entities/user-loan-details.query'
18+
import { invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
2019

2120
type StateKey = keyof typeof DEFAULT_STATE
2221
const { cloneDeep } = lodash
@@ -171,10 +170,7 @@ const createLoanCollateralDecrease = (set: StoreApi<State>['setState'], get: Sto
171170
void get()[sliceKey].fetchMaxRemovable(chainId, llamma)
172171

173172
await get().loans.fetchLoanDetails(curve, llamma)
174-
175-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
176-
invalidateLoanExists(queryParams)
177-
invalidateUserLoanDetails(queryParams)
173+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
178174

179175
if (resp.activeKey === get()[sliceKey].activeKey) {
180176
get()[sliceKey].setStateByKeys({

apps/main/src/loan/store/createLoanCollateralIncreaseSlice.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import lodash from 'lodash'
22
import type { StoreApi } from 'zustand'
3-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
43
import type { FormStatus, FormValues } from '@/loan/components/PageLoanManage/CollateralIncrease/types'
54
import type { FormDetailInfo, FormEstGas } from '@/loan/components/PageLoanManage/types'
65
import {
@@ -15,7 +14,7 @@ import { loadingLRPrices } from '@/loan/utils/utilsCurvejs'
1514
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1615
import { useWallet } from '@ui-kit/features/connect-wallet'
1716
import { setMissingProvider } from '@ui-kit/utils/store.util'
18-
import { invalidateUserLoanDetails } from '../entities/user-loan-details.query'
17+
import { invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
1918

2019
type StateKey = keyof typeof DEFAULT_STATE
2120
const { cloneDeep } = lodash
@@ -188,10 +187,7 @@ const createLoanCollateralIncrease = (set: StoreApi<State>['setState'], get: Sto
188187
void getUserMarketCollateralEvents(wallet?.account?.address, networks[chainId].id, llamma.controller, resp.hash)
189188
if (activeKey === get()[sliceKey].activeKey) {
190189
await get().loans.fetchLoanDetails(curve, llamma)
191-
192-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
193-
invalidateLoanExists(queryParams)
194-
invalidateUserLoanDetails(queryParams)
190+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
195191

196192
get()[sliceKey].setStateByKeys({
197193
detailInfo: {},

apps/main/src/loan/store/createLoanCreateSlice.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import lodash from 'lodash'
22
import type { StoreApi } from 'zustand'
3-
import { invalidateLoanExists, refetchLoanExists } from '@/llamalend/queries/loan-exists'
3+
import { refetchLoanExists } from '@/llamalend/queries/loan-exists'
44
import type {
55
FormDetailInfoLeverage,
66
FormStatus,
@@ -22,7 +22,7 @@ import { loadingLRPrices } from '@/loan/utils/utilsCurvejs'
2222
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
2323
import { useWallet } from '@ui-kit/features/connect-wallet'
2424
import { setMissingProvider } from '@ui-kit/utils/store.util'
25-
import { invalidateUserLoanDetails } from '../entities/user-loan-details.query'
25+
import { invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
2626

2727
type StateKey = keyof typeof DEFAULT_STATE
2828

@@ -432,10 +432,7 @@ const createLoanCreate = (set: StoreApi<State>['setState'], get: StoreApi<State>
432432
})
433433

434434
await get().loans.fetchLoanDetails(curve, llamma)
435-
436-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
437-
invalidateLoanExists(queryParams)
438-
invalidateUserLoanDetails(queryParams)
435+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
439436

440437
// reset form values
441438
const updatedFormValues = DEFAULT_FORM_VALUES

apps/main/src/loan/store/createLoanDecreaseSlice.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import lodash from 'lodash'
22
import { zeroAddress } from 'viem'
33
import type { StoreApi } from 'zustand'
4-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
54
import type { FormStatus, FormValues } from '@/loan/components/PageLoanManage/LoanDecrease/types'
65
import type { FormDetailInfo, FormEstGas } from '@/loan/components/PageLoanManage/types'
76
import {
@@ -16,7 +15,7 @@ import { loadingLRPrices } from '@/loan/utils/utilsCurvejs'
1615
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1716
import { useWallet } from '@ui-kit/features/connect-wallet'
1817
import { setMissingProvider } from '@ui-kit/utils/store.util'
19-
import { getUserLoanDetails, invalidateUserLoanDetails } from '../entities/user-loan-details.query'
18+
import { getUserLoanDetails, invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
2019

2120
type StateKey = keyof typeof DEFAULT_STATE
2221
const { cloneDeep } = lodash
@@ -217,10 +216,7 @@ const createLoanDecrease = (set: StoreApi<State>['setState'], get: StoreApi<Stat
217216
void getUserMarketCollateralEvents(wallet?.account?.address, networks[chainId].id, llamma.controller, resp.hash)
218217
if (activeKey === get()[sliceKey].activeKey) {
219218
await get().loans.fetchLoanDetails(curve, llamma)
220-
221-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
222-
invalidateLoanExists(queryParams)
223-
invalidateUserLoanDetails(queryParams)
219+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
224220

225221
get()[sliceKey].setStateByKey('formStatus', {
226222
...get()[sliceKey].formStatus,

apps/main/src/loan/store/createLoanDeleverageSlice.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import lodash from 'lodash'
22
import type { StoreApi } from 'zustand'
3-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
43
import type { FormDetailInfo, FormStatus, FormValues } from '@/loan/components/PageLoanManage/LoanDeleverage/types'
54
import {
65
DEFAULT_DETAIL_INFO,
@@ -15,7 +14,7 @@ import { ChainId, LlamaApi, Llamma, UserLoanDetails } from '@/loan/types/loan.ty
1514
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1615
import { useWallet } from '@ui-kit/features/connect-wallet'
1716
import { setMissingProvider } from '@ui-kit/utils/store.util'
18-
import { getUserLoanDetails, invalidateUserLoanDetails } from '../entities/user-loan-details.query'
17+
import { getUserLoanDetails, invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
1918

2019
type StateKey = keyof typeof DEFAULT_STATE
2120
const { cloneDeep } = lodash
@@ -177,10 +176,7 @@ const createLoanDeleverageSlice = (
177176
get()[sliceKey].setStateByKey('formStatus', cloneDeep({ ...cFormStatus, error: resp.error }))
178177
} else {
179178
await get().loans.fetchLoanDetails(curve, llamma)
180-
181-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
182-
invalidateLoanExists(queryParams)
183-
invalidateUserLoanDetails(queryParams)
179+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
184180

185181
get()[sliceKey].setStateByKeys({
186182
formValues: DEFAULT_FORM_VALUES,

apps/main/src/loan/store/createLoanIncreaseSlice.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import lodash from 'lodash'
22
import type { StoreApi } from 'zustand'
3-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
43
import type { FormStatus, FormValues } from '@/loan/components/PageLoanManage/LoanIncrease/types'
54
import type { FormDetailInfo, FormEstGas } from '@/loan/components/PageLoanManage/types'
65
import {
@@ -15,7 +14,7 @@ import { loadingLRPrices } from '@/loan/utils/utilsCurvejs'
1514
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1615
import { useWallet } from '@ui-kit/features/connect-wallet'
1716
import { setMissingProvider } from '@ui-kit/utils/store.util'
18-
import { invalidateUserLoanDetails } from '../entities/user-loan-details.query'
17+
import { invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
1918

2019
type StateKey = keyof typeof DEFAULT_STATE
2120
const { cloneDeep } = lodash
@@ -226,10 +225,7 @@ const createLoanIncrease = (set: StoreApi<State>['setState'], get: StoreApi<Stat
226225
void get()[sliceKey].fetchMaxRecv(chainId, llamma, formValues)
227226

228227
await get().loans.fetchLoanDetails(curve, llamma)
229-
230-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
231-
invalidateLoanExists(queryParams)
232-
invalidateUserLoanDetails(queryParams)
228+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
233229

234230
if (activeKey === get()[sliceKey].activeKey) {
235231
get()[sliceKey].setStateByKeys({

apps/main/src/loan/store/createLoanLiquidate.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import lodash from 'lodash'
22
import { StoreApi } from 'zustand'
3-
import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
43
import type { FormStatus } from '@/loan/components/PageLoanManage/LoanLiquidate/types'
54
import type { FormEstGas } from '@/loan/components/PageLoanManage/types'
65
import { DEFAULT_FORM_EST_GAS, DEFAULT_FORM_STATUS as FORM_STATUS } from '@/loan/components/PageLoanManage/utils'
@@ -10,7 +9,7 @@ import { ChainId, LlamaApi, Llamma, UserWalletBalances } from '@/loan/types/loan
109
import { getUserMarketCollateralEvents } from '@curvefi/prices-api/crvusd'
1110
import { useWallet } from '@ui-kit/features/connect-wallet'
1211
import { setMissingProvider } from '@ui-kit/utils/store.util'
13-
import { invalidateUserLoanDetails } from '../entities/user-loan-details.query'
12+
import { invalidateAllUserBorrowDetails } from '../entities/user-loan-details.query'
1413

1514
type StateKey = keyof typeof DEFAULT_STATE
1615
const { cloneDeep } = lodash
@@ -144,10 +143,7 @@ const createLoanLiquidate = (set: StoreApi<State>['setState'], get: StoreApi<Sta
144143
void getUserMarketCollateralEvents(wallet?.account?.address, networks[chainId].id, llamma.controller, resp.hash)
145144

146145
await get().loans.fetchLoanDetails(curve, llamma)
147-
148-
const queryParams = { chainId, marketId: llamma.id, userAddress: wallet?.account?.address }
149-
invalidateLoanExists(queryParams)
150-
invalidateUserLoanDetails(queryParams)
146+
invalidateAllUserBorrowDetails({ chainId, marketId: llamma.id, userAddress: wallet?.account?.address })
151147

152148
get()[sliceKey].setStateByKeys({
153149
formEstGas: DEFAULT_FORM_EST_GAS,

0 commit comments

Comments
 (0)