Skip to content

Commit 4bddb97

Browse files
Merge pull request #66 from useLiquidOps/feat/position-summary-improvements
Position summary component improvements
2 parents 528560b + d720a18 commit 4bddb97

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

src/app/[ticker]/PositionSummary/PositionSummary.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ const PositionSummary: React.FC<{
2424

2525
const denomination = 12n; // USD denomination
2626
const maxBorrow = useMemo(
27-
() =>
28-
!globalPosition
29-
? new Quantity(0n, 12n)
30-
: new Quantity(
31-
globalPosition.borrowCapacityUSD || 0,
32-
denomination,
33-
).fromNumber(4),
27+
() => new Quantity(
28+
globalPosition?.borrowCapacityUSD || 0,
29+
denomination,
30+
),
3431
[globalPosition],
3532
);
3633

@@ -54,6 +51,25 @@ const PositionSummary: React.FC<{
5451
return `${Number(formatPercent).toFixed(3)}%`;
5552
}, [maxBorrow, globalPosition]);
5653

54+
const handleMouseMoveCollateral = (ticker: string, e: React.MouseEvent) => {
55+
const pos = globalPosition?.tokenPositions?.[ticker];
56+
if (!pos) return;
57+
58+
if (Quantity.le(new Quantity(0, pos.collateralization.denomination).fromNumber(0.0001), pos.collateralization)) {
59+
let maximumFractionDigits = Quantity.le(Quantity.__one(), pos.collateralization) ? 2 : 4;
60+
setTooltipContent(
61+
// @ts-expect-error
62+
pos.collateralization.toLocaleString(undefined, { maximumFractionDigits })
63+
+ " " + ticker
64+
);
65+
} else {
66+
setTooltipContent(">0.0001 " + ticker);
67+
}
68+
69+
setTooltipPosition({ x: e.clientX, y: e.clientY });
70+
setShowTooltip(true);
71+
};
72+
5773
const handleMouseMove = (e: React.MouseEvent) => {
5874
const rect = e.currentTarget.getBoundingClientRect();
5975
const x = e.clientX - rect.left;
@@ -169,15 +185,17 @@ const PositionSummary: React.FC<{
169185
<div className={styles.tokens}>
170186
{!isLoadingPosition &&
171187
globalPosition &&
172-
globalPosition.collateralLogos.map((logo, i) => (
188+
globalPosition.collateralLogos.map((collateral, i) => (
173189
<img
174190
key={i}
175-
src={`https://arweave.net/${logo}`}
191+
src={`https://arweave.net/${collateral.logo}`}
176192
alt="collateral logo"
177193
className={styles.token}
178194
style={{
179195
zIndex: globalPosition.collateralLogos.length - i,
180196
}}
197+
onMouseMove={(e) => handleMouseMoveCollateral(collateral.ticker, e)}
198+
onMouseLeave={handleMouseLeave}
181199
/>
182200
))}
183201
{isLoadingPosition && (

src/hooks/LiquidOpsData/useGlobalPosition.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export interface TokenPositionCache {
2525
}
2626

2727
export interface GlobalPositionCache {
28-
collateralLogos: string[];
28+
collateralLogos: {
29+
ticker: string;
30+
logo: string;
31+
}[];
2932
collateralValueUSD: WrappedQuantity;
3033
borrowCapacityUSD: WrappedQuantity;
3134
borrowBalanceUSD: WrappedQuantity;
@@ -45,7 +48,10 @@ export interface TokenPositionResult {
4548
}
4649

4750
export interface GlobalPositionResult {
48-
collateralLogos: string[];
51+
collateralLogos: {
52+
ticker: string;
53+
logo: string;
54+
}[];
4955
collateralValueUSD: Quantity;
5056
borrowCapacityUSD: Quantity;
5157
borrowBalanceUSD: Quantity;
@@ -84,9 +90,9 @@ export function useGlobalPosition(overrideCache?: boolean) {
8490
info.ticker.toUpperCase() === ticker.toUpperCase() ||
8591
info.cleanTicker.toUpperCase() === ticker.toUpperCase(),
8692
);
87-
return foundToken?.icon;
93+
return { ticker, logo: foundToken?.icon };
8894
})
89-
.filter((icon): icon is string => !!icon);
95+
.filter((collateral) => !!collateral.logo) as GlobalPositionResult["collateralLogos"];
9096

9197
// turn Bigints to Quantities
9298
const formattedTokenResult: { [token: string]: TokenPositionResult } = {};

0 commit comments

Comments
 (0)