Skip to content

Commit

Permalink
Adding a proper fix to the updating of tokenPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
IanWoodard committed Oct 30, 2023
1 parent 4caa12c commit 392bc0e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
20 changes: 20 additions & 0 deletions earn/src/data/Uniboost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ export class BoostCardInfo {
);
}

static withNftTokenPtr(boostCardInfo: BoostCardInfo, nftTokenPtr: number): BoostCardInfo {
return new BoostCardInfo(
boostCardInfo.cardType,
boostCardInfo.owner,
boostCardInfo.nftTokenId,
nftTokenPtr,
boostCardInfo.uniswapPool,
boostCardInfo.currentTick,
boostCardInfo.token0,
boostCardInfo.token1,
boostCardInfo.lender0,
boostCardInfo.lender1,
boostCardInfo.color0,
boostCardInfo.color1,
boostCardInfo.position,
boostCardInfo.feesEarned,
boostCardInfo.borrower
);
}

boostFactor() {
if (this.borrower === null || JSBI.equal(this.position.liquidity, JSBI.BigInt(0))) return null;
// Compute total value in the Uniswap position
Expand Down
13 changes: 10 additions & 3 deletions earn/src/pages/boost/ManageBoostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ export default function ManageBoostPage() {
useEffect(() => {
if (!cardInfo || !colors?.token0 || !colors?.token1) return;
if (cardInfo.color0 === colors.token0 || cardInfo.color1 === colors.token1) return;
// Only update the card info if the tokenPtr matches
if (cardInfo.nftTokenPtr !== tokenPtr) return;
const boostCardWithColors = BoostCardInfo.withColors(cardInfo, colors.token0, colors.token1);
setCardInfo(boostCardWithColors);
}, [cardInfo, tokenPtr, colors?.token0, colors?.token1, setCardInfo]);
}, [cardInfo, colors?.token0, colors?.token1, setCardInfo]);

// Handle when the tokenPtr changes
useEffect(() => {
// Careful not to use a bang operator here, as we want to allow the tokenPtr to be 0
if (cardInfo == null || tokenPtr == null) return;
if (cardInfo.nftTokenPtr === tokenPtr) return;
const boostCardWithTokenPtr = BoostCardInfo.withNftTokenPtr(cardInfo, tokenPtr);
setCardInfo(boostCardWithTokenPtr);
}, [cardInfo, tokenPtr, setCardInfo]);

const isLoading = !cardInfo || !nftTokenId;
return (
Expand Down

0 comments on commit 392bc0e

Please sign in to comment.