Skip to content

Commit

Permalink
fix: display lending positions post-hardfork shenanigans (#7747)
Browse files Browse the repository at this point in the history
* fix: display lending positions post-hardfork shenanigans

* fix: don't throw on no positions for pool
  • Loading branch information
gomesalexandre authored Sep 16, 2024
1 parent a445d82 commit 15bf588
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/utils/thorchain/lending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const getThorchainLendingPosition = async ({

const allPositions = lendingPositionsResponse
if (!allPositions.length) {
throw new Error(`No lending positions found for asset ID: ${assetId}`)
return null
}

const accountAddresses = await getAccountAddresses(accountId)
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Lending/YourLoans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ export const YourLoans = () => {
const translate = useTranslate()
const lendingHeader = useMemo(() => <LendingHeader />, [])

const { data: lendingSupportedAssets } = useLendingSupportedAssets({ type: 'collateral' })
const { data: lendingSupportedAssets } = useLendingSupportedAssets({
type: 'collateral',
hasLoanCollateral: false,
})

const history = useHistory()

Expand Down
5 changes: 4 additions & 1 deletion src/pages/Lending/hooks/useAllLendingPositionsData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ type UseAllLendingPositionsDataProps = {
}

export const useAllLendingPositionsData = ({ assetId }: UseAllLendingPositionsDataProps = {}) => {
const { data: lendingSupportedAssets } = useLendingSupportedAssets({ type: 'collateral' })
const { data: lendingSupportedAssets } = useLendingSupportedAssets({
type: 'collateral',
hasLoanCollateral: false,
})

const accountIds = useAppSelector(selectWalletAccountIds)
const accounts = useMemo(
Expand Down
12 changes: 8 additions & 4 deletions src/pages/Lending/hooks/useLendingSupportedAssets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ const queryKey = ['lendingSupportedAssets']
export const useLendingSupportedAssets = ({
type,
statusFilter = 'Available',
hasLoanCollateral = true,
}: {
type: 'collateral' | 'borrow'
statusFilter?: ThornodePoolStatuses | 'All'
hasLoanCollateral?: boolean
}) => {
const wallet = useWallet().state.wallet
const { isSnapInstalled } = useIsSnapInstalled()
Expand Down Expand Up @@ -66,9 +68,11 @@ export const useLendingSupportedAssets = ({
const selectSupportedAssets = useCallback(
(data: ThornodePoolResponse[] | undefined) => {
if (!data) return []
const pools = (availablePools ?? []).filter(
pool => type === 'borrow' || bnOrZero(pool.loan_collateral).gt(0),
)
const pools = (availablePools ?? []).filter(pool => {
if (type === 'borrow') return true
if (type === 'collateral') return !hasLoanCollateral || bnOrZero(pool.loan_collateral).gt(0)
return false
})

const supportedAssets = pools
.map(pool => {
Expand Down Expand Up @@ -99,7 +103,7 @@ export const useLendingSupportedAssets = ({
}
return supportedAssets
},
[availablePools, type, wallet, walletChainIds, walletSupportChains],
[availablePools, hasLoanCollateral, type, wallet, walletChainIds, walletSupportChains],
)

const lendingSupportedAssetsQuery = useQuery({
Expand Down

0 comments on commit 15bf588

Please sign in to comment.