Skip to content

Commit

Permalink
Fix: prevent one unknown token from hiding borrowers on Liquidate tab
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed May 31, 2024
1 parent 4271192 commit 2b6b96c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion earn/src/components/common/HealthGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function HealthSVG(props: HealthGaugeProps) {
export default function HealthGauge(props: HealthGaugeProps) {
const [isHovering, setIsHovering] = useState(false);

// TODO: Ideally we'd show things like auctionState / liquidation time as well, not just health.
return (
<TooltipParent onMouseEnter={() => setIsHovering(true)} onMouseLeave={() => setIsHovering(false)}>
<HealthSVG {...props} />
Expand Down
26 changes: 11 additions & 15 deletions earn/src/components/markets/liquidate/LiquidateTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,22 @@ export default function LiquidateTab(props: LiquidateTabProps) {
query: { enabled: createBorrowerEvents.length > 0 },
});

const lendingPairsForEvents = useMemo(() => {
let missing = false;
const res = createBorrowerEvents.map((ev) => {
const pair = lendingPairs.find((pair) => pair.uniswapPool.toLowerCase() === ev.args.pool!.toLowerCase());
if (pair === undefined) missing = true;
return pair;
});

// TODO: This causes *all* borrowers to disappear if we're missing Token data for a certain pool
if (missing) return undefined;
return res as LendingPair[];
}, [createBorrowerEvents, lendingPairs]);
const lendingPairsForEvents = useMemo(
() =>
createBorrowerEvents.map((ev) =>
lendingPairs.find((pair) => pair.uniswapPool.toLowerCase() === ev.args.pool!.toLowerCase())
),
[createBorrowerEvents, lendingPairs]
);

const borrowers = useMemo(() => {
if (summaryData === undefined || lendingPairsForEvents === undefined) return undefined;
if (summaryData === undefined) return undefined;
return createBorrowerEvents.map((ev, i) => {
const { pool: uniswapPool, owner, account: address } = ev.args;
const [balanceEth, balance0, balance1, liabilities0, liabilities1, slot0, liquidity] = summaryData[i];

const pair = lendingPairsForEvents[i];
if (pair === undefined) return undefined;

const positionTicks: { lower: number; upper: number }[] = [];
for (let i = 0; i < 3; i++) {
Expand Down Expand Up @@ -122,8 +118,8 @@ export default function LiquidateTab(props: LiquidateTabProps) {
if (borrowers === undefined) return [];
return borrowers
.map((borrower, i) => {
if (borrower.ethBalance.isZero()) return undefined;
const pair = lendingPairsForEvents![i];
if (borrower === undefined || borrower.ethBalance.isZero()) return undefined;
const pair = lendingPairsForEvents[i]!;
const { health } = borrower.health(
new Big(pair.oracleData.sqrtPriceX96.toString(GNFormat.INT)),
pair.iv,
Expand Down
1 change: 0 additions & 1 deletion earn/src/components/portfolio/modal/SendCryptoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ function SendCryptoConfirmButton(props: SendCryptoConfirmButtonProps) {
const confirmButton = getConfirmButton(confirmButtonState, token);

function handleClickConfirm() {
// TODO: Do not use setStates in async functions outside of useEffect
if (confirmButtonState === ConfirmButtonState.READY && sendCryptoConfig !== undefined) {
setIsPending(true);
contractWrite(sendCryptoConfig.request);
Expand Down

0 comments on commit 2b6b96c

Please sign in to comment.