Skip to content

Commit

Permalink
fix: added fetchIsGelatoApiHealth function
Browse files Browse the repository at this point in the history
  • Loading branch information
impelcrypto committed Feb 27, 2024
1 parent 62f2105 commit c175817
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hooks/bridge/useL1History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ZkChainId,
checkIsL1,
fetchAccountHistory,
fetchIsGelatoApiHealth,
getChainIdFromNetId,
} from 'src/modules/zk-evm-bridge';
import { container } from 'src/v2/common';
Expand Down Expand Up @@ -78,6 +79,10 @@ export const useL1History = () => {
try {
isLoadingHistories.value = true;
const data = await fetchAccountHistory(currentAccount.value);
const isHealth = await fetchIsGelatoApiHealth();
if (!isHealth) {
throw Error('The API is currently in maintenance mode.');
}
isGelatoApiConnected.value = true;

const l1Web3 = buildWeb3Instance(EthBridgeChainId[l1Network.value as EthBridgeNetworkName]);
Expand Down
7 changes: 7 additions & 0 deletions src/modules/zk-evm-bridge/l1-bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ const getApiUrl = (): string => {
return zkEvmApi[network];
};

export const fetchIsGelatoApiHealth = async (): Promise<boolean> => {
const base = getApiUrl();
const url = `${base}/healthz`;
const result = await axios.get<{ status: string }>(url);
return result && result.data.status === 'SERVING';
};

export const fetchAccountHistory = async (address: string): Promise<BridgeHistory[]> => {
const base = getApiUrl();
const limit = 15;
Expand Down

0 comments on commit c175817

Please sign in to comment.