11import lodash from 'lodash'
22import type { StoreApi } from 'zustand'
3+ import { invalidateLoanExists } from '@/llamalend/queries/loan-exists'
34import type { FormDetailInfo , FormStatus , FormValues } from '@/loan/components/PageLoanManage/LoanDeleverage/types'
45import {
56 DEFAULT_DETAIL_INFO ,
@@ -35,7 +36,7 @@ export type LoanDeleverageSlice = {
3536 fetchDetailInfo ( activeKey : string , curve : LlamaApi , llamma : Llamma , formValues : FormValues , maxSlippage : string , userState : UserLoanDetails [ 'userState' ] ) : Promise < FormDetailInfo >
3637 setFormValues ( llammaId : string , curve : LlamaApi | null , llamma : Llamma | null , formValues : Partial < FormValues > , maxSlippage : string , isFullReset ?: boolean ) : Promise < void >
3738 fetchEstGas ( activeKey : string , chainId : ChainId , llamma : Llamma , formValues : FormValues , maxSlippage : string ) : Promise < void >
38- fetchStepRepay ( activeKey : string , curve : LlamaApi , llamma : Llamma , formValues : FormValues , maxSlippage : string ) : Promise < { activeKey : string ; error : string ; hash : string ; loanExists : boolean } | undefined >
39+ fetchStepRepay ( activeKey : string , curve : LlamaApi , llamma : Llamma , formValues : FormValues , maxSlippage : string ) : Promise < { activeKey : string ; error : string ; hash : string ; } | undefined >
3940 setStateByActiveKey < T > ( key : StateKey , activeKey : string , value : T ) : void
4041 setStateByKey < T > ( key : StateKey , value : T ) : void
4142 setStateByKeys ( SliceState : Partial < SliceState > ) : void
@@ -169,20 +170,17 @@ const createLoanDeleverageSlice = (
169170 // update user events api
170171 void getUserMarketCollateralEvents ( wallet ?. account ?. address , networks [ chainId ] . id , llamma . controller , resp . hash )
171172 if ( resp . activeKey === get ( ) [ sliceKey ] . activeKey ) {
172- let loanExists = true
173173 const cFormStatus = cloneDeep ( DEFAULT_FORM_STATUS )
174174 cFormStatus . isApproved = get ( ) [ sliceKey ] . formStatus . isApproved
175175
176176 if ( resp . error ) {
177177 get ( ) [ sliceKey ] . setStateByKey ( 'formStatus' , cloneDeep ( { ...cFormStatus , error : resp . error } ) )
178178 } else {
179- // re-fetch loan info
180- const respLoanDetails = await get ( ) . loans . fetchLoanDetails ( curve , llamma )
181- loanExists = respLoanDetails . loanExists
179+ await get ( ) . loans . fetchLoanDetails ( curve , llamma )
182180
183- if ( ! loanExists ) {
184- invalidateUserLoanDetails ( { chainId , marketId : llamma . id , userAddress : wallet ?. account ?. address } )
185- }
181+ const queryParams = { chainId , marketId : llamma . id , userAddress : wallet ?. account ?. address }
182+ invalidateLoanExists ( queryParams )
183+ invalidateUserLoanDetails ( queryParams )
186184
187185 get ( ) [ sliceKey ] . setStateByKeys ( {
188186 formValues : DEFAULT_FORM_VALUES ,
@@ -192,7 +190,7 @@ const createLoanDeleverageSlice = (
192190 } )
193191 }
194192
195- return { ... resp , loanExists }
193+ return resp
196194 }
197195 } ,
198196
0 commit comments