refactor: llamalend user borrow position queries#2037
refactor: llamalend user borrow position queries#2037OnlyJousting wants to merge 11 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| }), | ||
| pendingMessage: () => t`Closing position...`, | ||
| successMessage: () => t`Position closed successfully!`, | ||
| onSuccess: () => invalidateAllUserBorrowDetails({ chainId, marketId, userAddress }), |
There was a problem hiding this comment.
invalidation was duplicated here, it happens in useLlammaMutation
| <NoPosition type="supply" /> | ||
| </Stack> | ||
| )} | ||
| {hasSupplyPosition ? <SupplyPositionDetails {...supplyPositionDetails} /> : <NoPosition type="supply" />} |
There was a problem hiding this comment.
I missed this in a previous PR so I snuck it into this one 🙈
| import { useMarketUserBandsBalances } from '@/llamalend/features/bands-chart/queries/market-user-bands-balances.query' | ||
| import { parseFetchedBandsBalances } from '@/llamalend/features/bands-chart/queries/utils' | ||
| import { useLoanExists } from '@/llamalend/queries/loan-exists' | ||
| import { useLoanExists } from '@/llamalend/queries/user' |
| import { type CloseLoanMutation, useClosePositionMutation } from '@/llamalend/mutations/close-position.mutation' | ||
| import { useCloseLoanIsApproved } from '@/llamalend/queries/close-loan/close-loan-is-approved.query' | ||
| import { useUserState } from '@/llamalend/queries/user-state.query' | ||
| import { useUserState } from '@/llamalend/queries/user/user-state.query' |
There was a problem hiding this comment.
Could've used the index.ts no?
| import { useCloseEstimateGas } from '@/llamalend/queries/close-loan/close-loan-gas-estimate.query' | ||
| import { useCloseLoanIsApproved } from '@/llamalend/queries/close-loan/close-loan-is-approved.query' | ||
| import { useUserState } from '@/llamalend/queries/user-state.query' | ||
| import { useUserState } from '@/llamalend/queries/user/user-state.query' |
| @@ -0,0 +1 @@ | |||
| export * from './useBorrowPositionDetails' | |||
There was a problem hiding this comment.
Not sure a barrel is useful here but I'll allow it
| marketId: market.id, | ||
| userAddress: api.signerAddress, | ||
| }) | ||
| void Promise.all([ |
There was a problem hiding this comment.
why void and not await? It's already async and awaiting the loan exists, might as well complete it
(the answer is you copied it from user-loan-details but i only found out later, i dunno might as well add an await here)
| invalidateUserHealth({ marketId, userAddress, chainId, isFull: true }), | ||
| invalidateUserHealth({ marketId, userAddress, chainId, isFull: false }), | ||
| invalidateUserBalances({ marketId, userAddress, chainId }), | ||
| invalidateAllUserPositionQueries({ marketId, userAddress, chainId }), |
There was a problem hiding this comment.
Should we actually move this to invalidation.ts in the user folder?
| } | ||
|
|
||
| // invalidate user prices to keep ohlc chart liquidation range in sync | ||
| await invalidateUserPrices({ |
There was a problem hiding this comment.
Not invalidating user prices anymore is deliberate? It's not covered by invalidateAllUserMarketDetails
| } from '@/llamalend/features/market-position-details' | ||
| import { calculateLtv, getIsUserCloseToLiquidation, getLiquidationStatus, hasV2Leverage } from '@/llamalend/llama.utils' | ||
| import type { LlamaMarketTemplate } from '@/llamalend/llamalend.types' | ||
| import { useLoanExists } from '@/llamalend/queries/user' |
Changes:
useBorrowPositionDetails(lend) anduseLoanPositionDetails(loan) hooks, replacing them with a single shareduseBorrowPositionDetailsinllamalend/features/market-position-detailstogether with shared query usageuser-balances,user-health,user-prices,user-state,user-current-leverage) into a consolidatedllamalend/queries/user/directory with a barrel exportindex.tsuser-bands,user-loss,user-market-balances, anduser-supply-boost(previously inlined or scattered)invalidation.tsin the user queries directory andinvalidate.tsin lend entities, providing a singleinvalidateAllUserMarketDetailsfunction for joint invalidation of all user position querieslend,loan, andllamalenddomains to import from the new consolidated locationsNumber()conversions with unary+operator, and removed duplicate invalidation calls (e.g. inclose-position.mutation.tsand in/lend/PageLendMarket/ManageLoanTabs), normalize market and marketId naming from llamma/llammaId