diff --git a/earn/src/components/markets/borrow/BorrowingWidget.tsx b/earn/src/components/markets/borrow/BorrowingWidget.tsx index 25c035e5..ad95692e 100644 --- a/earn/src/components/markets/borrow/BorrowingWidget.tsx +++ b/earn/src/components/markets/borrow/BorrowingWidget.tsx @@ -260,9 +260,19 @@ export default function BorrowingWidget(props: BorrowingWidgetProps) { } } + const filteredBorrowers = useMemo(() => { + return borrowers?.filter((account) => { + return !( + account.assets.amount0.isZero() && + account.assets.amount1.isZero() && + !account.assets.uniswapPositions.some((pos) => !JSBI.EQ(pos.liquidity, '0')) + ); + }); + }, [borrowers]); + return ( <> - {(borrowers?.length || 0) > 0 && ( + {Boolean(filteredBorrowers?.length) && ( <> Manage positions @@ -277,72 +287,63 @@ export default function BorrowingWidget(props: BorrowingWidgetProps) {
- {borrowers && - borrowers.map((account) => { - const hasNoCollateral = - account.assets.amount0.isZero() && - account.assets.amount1.isZero() && - account.assets.uniswapPositions.every((pos) => JSBI.EQ(pos.liquidity, '0')); - if (hasNoCollateral) return null; - const uniswapPosition = account.assets.uniswapPositions.at(0); - const collateral = account.assets.amount0.isGtZero() ? account.token0 : account.token1; - const collateralAmount = collateral.equals(account.token0) - ? account.assets.amount0 - : account.assets.amount1; - const collateralColor = tokenColors.get(collateral.address); - const ltvPercentage = computeLTV(account.iv, account.nSigma) * 100; - return ( - setHoveredBorrower(account)} - onMouseLeave={() => setHoveredBorrower(null)} - className={account === hoveredBorrower ? 'active' : ''} - onClick={() => - setSelectedBorrower({ - borrower: account, - type: 'supply', - }) - } - > - {uniswapPosition !== undefined ? ( -
- - Uniswap Position - - {uniswapPosition.lower} ⇔ {uniswapPosition.upper} - -
- ) : ( -
- - - {collateralAmount.toString(GNFormat.LOSSY_HUMAN)}  {collateral.symbol} - -
- )} - {roundPercentage(ltvPercentage, 2)}%  LLTV -
- ); - })} + {filteredBorrowers?.map((account) => { + const uniswapPosition = account.assets.uniswapPositions.at(0); + const collateral = account.assets.amount0.isGtZero() ? account.token0 : account.token1; + const collateralAmount = collateral.equals(account.token0) + ? account.assets.amount0 + : account.assets.amount1; + const collateralColor = tokenColors.get(collateral.address); + const ltvPercentage = computeLTV(account.iv, account.nSigma) * 100; + return ( + setHoveredBorrower(account)} + onMouseLeave={() => setHoveredBorrower(null)} + className={account === hoveredBorrower ? 'active' : ''} + onClick={() => + setSelectedBorrower({ + borrower: account, + type: 'supply', + }) + } + > + {uniswapPosition !== undefined ? ( +
+ + Uniswap Position + + {uniswapPosition.lower} ⇔ {uniswapPosition.upper} + +
+ ) : ( +
+ + + {collateralAmount.toString(GNFormat.LOSSY_HUMAN)}  {collateral.symbol} + +
+ )} + {roundPercentage(ltvPercentage, 2)}%  LLTV +
+ ); + })}
- {borrowers && - borrowers.map((borrower) => { - const hasNoCollateral = borrower.assets.amount0.isZero() && borrower.assets.amount1.isZero(); - if (hasNoCollateral) return null; - return ( -
- -
- ); - })} + {filteredBorrowers?.map((borrower) => { + return ( +
+ +
+ ); + })}
@@ -353,56 +354,48 @@ export default function BorrowingWidget(props: BorrowingWidgetProps) {
- {borrowers && - borrowers.map((account) => { - const hasNoCollateral = - account.assets.amount0.isZero() && - account.assets.amount1.isZero() && - account.assets.uniswapPositions.length === 0; - if (hasNoCollateral) return null; - - const isBorrowingToken0 = account.liabilities.amount0 > 0; - const liability = isBorrowingToken0 ? account.token0 : account.token1; - const liabilityAmount = isBorrowingToken0 - ? account.liabilities.amount0 - : account.liabilities.amount1; - const liabilityColor = tokenColors.get(liability.address); - const lendingPair = lendingPairs.find( - (pair) => pair.uniswapPool === account.uniswapPool.toLowerCase() - ); - const apr = - (lendingPair?.[isBorrowingToken0 ? 'kitty0Info' : 'kitty1Info'].borrowAPR || 0) * 100; - const roundedApr = Math.round(apr * 100) / 100; - return ( - { - setHoveredBorrower(account); - }} - onMouseLeave={() => { - setHoveredBorrower(null); - }} - onClick={() => { - setSelectedBorrower({ - borrower: account, - type: 'borrow', - }); - }} - className={account === hoveredBorrower ? 'active' : ''} - > - {roundedApr}%  APR -
- - {formatTokenAmount(liabilityAmount)}  {liability.symbol} - - -
-
- ); - })} + {filteredBorrowers?.map((account) => { + const isBorrowingToken0 = account.liabilities.amount0 > 0; + const liability = isBorrowingToken0 ? account.token0 : account.token1; + const liabilityAmount = isBorrowingToken0 + ? account.liabilities.amount0 + : account.liabilities.amount1; + const liabilityColor = tokenColors.get(liability.address); + const lendingPair = lendingPairs.find( + (pair) => pair.uniswapPool === account.uniswapPool.toLowerCase() + ); + const apr = (lendingPair?.[isBorrowingToken0 ? 'kitty0Info' : 'kitty1Info'].borrowAPR || 0) * 100; + const roundedApr = Math.round(apr * 100) / 100; + return ( + { + setHoveredBorrower(account); + }} + onMouseLeave={() => { + setHoveredBorrower(null); + }} + onClick={() => { + setSelectedBorrower({ + borrower: account, + type: 'borrow', + }); + }} + className={account === hoveredBorrower ? 'active' : ''} + > + {roundedApr}%  APR +
+ + {formatTokenAmount(liabilityAmount)}  {liability.symbol} + + +
+
+ ); + })}