Skip to content

Commit

Permalink
Merge pull request #1592 from QuickSwap/dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
sameepsi authored Oct 25, 2024
2 parents 73e6f4d + 40f88ed commit 89c0440
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/hooks/bond/useFetchBonds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const useFetchBonds = () => {
return bonds
.map((bond) => bond.lpToken)
.filter(
(token) => token?.liquidityDex?.[chainId] !== LiquidityDex.External,
(token) =>
token?.liquidityDex?.[chainId] !== LiquidityDex.External &&
token.lpToken,
)
.reduce((acc: BondToken[], token) => {
const itemIsExisting = !!acc.find((item) => {
Expand All @@ -89,6 +91,9 @@ export const useFetchBonds = () => {
if (!bonds) return [];
return bonds
.map((bond) => bond.earnToken)
.concat(
bonds.map((bond) => bond.lpToken).filter((token) => !token.lpToken),
)
.filter(
(token) => token.liquidityDex?.[chainId] !== LiquidityDex.External,
)
Expand Down Expand Up @@ -116,6 +121,9 @@ export const useFetchBonds = () => {
if (!bonds) return [];
return bonds
.map((bond) => bond.earnToken)
.concat(
bonds.map((bond) => bond.lpToken).filter((token) => !token.lpToken),
)
.filter(
(token) => token.liquidityDex?.[chainId] === LiquidityDex.External,
)
Expand All @@ -141,7 +149,9 @@ export const useFetchBonds = () => {
return bonds
.map((bond) => bond.lpToken)
.filter(
(token) => token?.liquidityDex?.[chainId] === LiquidityDex.External,
(token) =>
token?.liquidityDex?.[chainId] === LiquidityDex.External &&
token.lpToken,
)
.reduce((acc: BondToken[], token) => {
const itemIsExisting = !!acc.find((item) => {
Expand Down Expand Up @@ -393,7 +403,7 @@ export const useFetchBonds = () => {
address &&
item.address.toLowerCase() === address.toLowerCase(),
);
const lpPrice = lpPrices.find((item) => {
const lpPrice = lpPrices.concat(bondTokenPrices).find((item) => {
const lpTokenAddress = item.token.address[chainId];
const bondLPTokenAddress = bond.lpToken.address[chainId];
return (
Expand All @@ -402,15 +412,17 @@ export const useFetchBonds = () => {
lpTokenAddress.toLowerCase() === bondLPTokenAddress.toLowerCase()
);
});
const dexScreenerLpPrice = (dexScreenerLPPrices ?? []).find((item) => {
const lpTokenAddress = item.token.address[chainId];
const bondLPTokenAddress = bond.lpToken.address[chainId];
return (
lpTokenAddress &&
bondLPTokenAddress &&
lpTokenAddress.toLowerCase() === bondLPTokenAddress.toLowerCase()
);
})?.price;
const dexScreenerLpPrice = (dexScreenerLPPrices ?? [])
.concat(dexScreenerPrices ?? [])
.find((item) => {
const lpTokenAddress = item.token.address[chainId];
const bondLPTokenAddress = bond.lpToken.address[chainId];
return (
lpTokenAddress &&
bondLPTokenAddress &&
lpTokenAddress.toLowerCase() === bondLPTokenAddress.toLowerCase()
);
})?.price;
const lpPriceNumber =
lpPrice && lpPrice.price
? Number(formatUnits(lpPrice.price))
Expand Down

0 comments on commit 89c0440

Please sign in to comment.