From 15bf588dce65cbb81b9877187b784d16c3f76fbb Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:24:02 +0400 Subject: [PATCH] fix: display lending positions post-hardfork shenanigans (#7747) * fix: display lending positions post-hardfork shenanigans * fix: don't throw on no positions for pool --- src/lib/utils/thorchain/lending.ts | 2 +- src/pages/Lending/YourLoans.tsx | 5 ++++- .../Lending/hooks/useAllLendingPositionsData.tsx | 5 ++++- .../Lending/hooks/useLendingSupportedAssets/index.ts | 12 ++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/utils/thorchain/lending.ts b/src/lib/utils/thorchain/lending.ts index 7a824f4106c..b14d8fa73ea 100644 --- a/src/lib/utils/thorchain/lending.ts +++ b/src/lib/utils/thorchain/lending.ts @@ -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) diff --git a/src/pages/Lending/YourLoans.tsx b/src/pages/Lending/YourLoans.tsx index 2fc559117a3..5708886c8f3 100644 --- a/src/pages/Lending/YourLoans.tsx +++ b/src/pages/Lending/YourLoans.tsx @@ -207,7 +207,10 @@ export const YourLoans = () => { const translate = useTranslate() const lendingHeader = useMemo(() => , []) - const { data: lendingSupportedAssets } = useLendingSupportedAssets({ type: 'collateral' }) + const { data: lendingSupportedAssets } = useLendingSupportedAssets({ + type: 'collateral', + hasLoanCollateral: false, + }) const history = useHistory() diff --git a/src/pages/Lending/hooks/useAllLendingPositionsData.tsx b/src/pages/Lending/hooks/useAllLendingPositionsData.tsx index c320a6414d0..d3423ac1548 100644 --- a/src/pages/Lending/hooks/useAllLendingPositionsData.tsx +++ b/src/pages/Lending/hooks/useAllLendingPositionsData.tsx @@ -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( diff --git a/src/pages/Lending/hooks/useLendingSupportedAssets/index.ts b/src/pages/Lending/hooks/useLendingSupportedAssets/index.ts index 6cd2e910d7c..d2a1e0e9948 100644 --- a/src/pages/Lending/hooks/useLendingSupportedAssets/index.ts +++ b/src/pages/Lending/hooks/useLendingSupportedAssets/index.ts @@ -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() @@ -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 => { @@ -99,7 +103,7 @@ export const useLendingSupportedAssets = ({ } return supportedAssets }, - [availablePools, type, wallet, walletChainIds, walletSupportChains], + [availablePools, hasLoanCollateral, type, wallet, walletChainIds, walletSupportChains], ) const lendingSupportedAssetsQuery = useQuery({