Skip to content

Commit

Permalink
chore: fetch default hermes endpoint if service provider throws error
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Nov 23, 2024
1 parent b904616 commit f69d021
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions apps/frontend/src/hooks/usePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export const usePrice = (marketParam?: string) => {
const [hermesClient, _] = useState(
() =>
new HermesClient(
process.env.NEXT_PUBLIC_HERMES_API ?? 'https://hermes.pyth.network'
process.env.NEXT_PUBLIC_HERMES_API ?? 'https://hermes.pyth.network',
{
httpRetries: 1,
timeout: 3000,
}
)
);

const { provider } = useProvider();

const storeMarket = useMarketStore(selectMarket);
Expand Down Expand Up @@ -74,8 +79,14 @@ export const usePrice = (marketParam?: string) => {
const priceFeedIds = Array.from(priceFeedIdToAssetId.keys());

// Fetch price updates from Hermes client
const priceUpdates =
await hermesClient.getLatestPriceUpdates(priceFeedIds);
let priceUpdates;
try {
priceUpdates = await hermesClient.getLatestPriceUpdates(priceFeedIds);
} catch (error) {
const client = new HermesClient('https://hermes.pyth.network');

priceUpdates = await client.getLatestPriceUpdates(priceFeedIds);
}

if (
!priceUpdates ||
Expand Down

0 comments on commit f69d021

Please sign in to comment.