Skip to content

Commit

Permalink
Hotfixes (#388)
Browse files Browse the repository at this point in the history
* Account for missing data

* Add missing enabled query check

* Fix collateral prices
  • Loading branch information
noisekit authored Aug 3, 2024
1 parent 4aa966a commit e84b0e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
3 changes: 2 additions & 1 deletion liquidity/lib/useAccounts/useAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export function useAccounts() {
'Accounts',
{ accountAddress: activeWallet?.address, AccountProxy: AccountProxy?.address },
],
enabled: Boolean(AccountProxy && activeWallet?.address),
queryFn: async function () {
if (!AccountProxy || !activeWallet?.address) throw new Error('Should be disabled');
if (!(AccountProxy && activeWallet?.address)) throw new Error('Should be disabled');

const numberOfAccountTokens = await AccountProxy.balanceOf(activeWallet.address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ async function getPythFeedIds(network: Network) {
return getAllPriceIdsEntries(extras).map(([_key, value]) => value);
}

async function getPythFeedIdsFromCollateralList(collateralList: string[]) {
async function getPythFeedIdsFromCollateralList(
collateralList: {
symbol: string;
}[]
) {
const extras = await Promise.all(
networksOffline.map((network) => importExtras(network.id, network.preset))
);
Expand Down Expand Up @@ -56,13 +60,10 @@ async function getPythFeedIdsFromCollateralList(collateralList: string[]) {

// Find the corresponding price feed id for each symbol
return collateralList.map((collateral) => {
let symbol = collateral;
if (collateral === 'WETH') {
symbol = 'ETH';
}
const symbol = collateral.symbol === 'WETH' ? 'ETH' : collateral.symbol;
const id = deduped.find((x) => x.symbol?.toUpperCase() === symbol.toUpperCase());
return {
collateral,
...collateral,
priceId: id?.priceId,
};
});
Expand Down Expand Up @@ -154,23 +155,20 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => {
return returnData;
}

const pythIds = await getPythFeedIdsFromCollateralList(
filteredCollaterals.map((collateral) => collateral.symbol)
);

const collateralsWithPriceId = await getPythFeedIdsFromCollateralList(filteredCollaterals);
const prices = await priceService.getLatestPriceFeeds(
pythIds.map((x) => x.priceId) as string[]
collateralsWithPriceId.map((x) => x.priceId) as string[]
);

prices?.forEach((item, index) => {
prices?.forEach((item) => {
const col = collateralsWithPriceId.find(({ priceId }) => priceId === `0x${item.id}`);
const price = item.getPriceUnchecked();

returnData.push({
symbol: filteredCollaterals[index].symbol,
price: parseUnits(price.price, 18 + price.expo),
});
if (col) {
returnData.push({
symbol: col.symbol,
price: parseUnits(price.price, 18 + price.expo),
});
}
});

return returnData;
},
refetchInterval: 60000,
Expand Down
22 changes: 13 additions & 9 deletions liquidity/ui/src/components/Pools/PoolCards/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export const PoolCard = ({
const { connect } = useWallet();

const vaultTVL = collateralTypes?.reduce((acc, type) => {
const price = wei(collateralPrices?.find((price) => price.symbol === type.symbol)?.price || 0);
const collateralWithPrice = collateralPrices?.find((price) => price.symbol === type.symbol);
const price = collateralWithPrice ? wei(collateralWithPrice.price) : ZEROWEI;
const amount = wei(type.collateralDeposited, Number(type.decimals), true);
const value = price.mul(amount);
return acc.add(value);
Expand Down Expand Up @@ -298,22 +299,25 @@ export const PoolCard = ({
);
})
.map((type, index) => {
const price = wei(
collateralPrices?.find(
(price) => price.symbol.toUpperCase() === type.symbol.toUpperCase()
)?.price
const collateralWithPrice = collateralPrices?.find(
(price) => price.symbol.toUpperCase() === type.symbol.toUpperCase()
);

const price = collateralWithPrice ? wei(collateralWithPrice.price) : ZEROWEI;
const collateralApr = apr.collateralAprs.find(
(apr) => apr.collateralType === type.tokenAddress.toLowerCase()
);
(apr) =>
`${apr.collateralType}`.toLowerCase() === `${type.tokenAddress}`.toLowerCase()
) || {
apr28d: 0,
apr28dRewards: 0,
apr28dPnl: 0,
};

const { apr28d, apr28dRewards, apr28dPnl } = collateralApr;

const onClick = async () => {
try {
if (!currentNetwork) {
connect();
await connect();
return;
}

Expand Down

0 comments on commit e84b0e2

Please sign in to comment.