Skip to content

Commit

Permalink
Ensure to execute initial fetch only when base contracts are loaded (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
smitch88 authored Aug 31, 2023
1 parent ca37d90 commit 781c089
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions dapp-oeth/src/hooks/useTokenPrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ const stakedFraxPrice = (contract) =>
contract.previewRedeem(utils.parseEther('1'))

const oraclePrices = async (tokens, contracts) => {
if (
!contracts.chainlinkEthAggregator ||
!contracts.oethOracleRouter ||
!contracts.sfrxeth
) {
return {}
}

// Fetch baseline ETH price for conversion
const feed = await contracts.chainlinkEthAggregator.latestRoundData()
const ethPrice = Number(utils.formatUnits(feed?.answer, 8))
Expand Down Expand Up @@ -155,7 +147,10 @@ const useTokenPrices = ({ tokens = [] } = {}) => {
}

return useQuery(queryTokens, fetchTokenPrices, {
enabled: contracts !== null,
enabled:
!!contracts?.chainlinkEthAggregator &&
!!contracts?.oethOracleRouter &&
!!contracts?.sfrxeth,
})
}

Expand Down

0 comments on commit 781c089

Please sign in to comment.