Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable sending bridge transactions when Gelato API is down #1194

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/bridge/ethereum/L1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:set-right-ui="setRightUi"
:bridge-amt="String(bridgeAmt)"
:err-msg="errMsg"
:is-disabled-bridge="isDisabledBridge"
:is-disabled-bridge="isDisabledBridge || !isGelatoApiConnected"
:from-bridge-balance="fromBridgeBalance"
:to-bridge-balance="toBridgeBalance"
:from-chain-name="fromChainName"
Expand Down Expand Up @@ -111,6 +111,7 @@ export default defineComponent({
l1Network,
l2Network,
isActionRequired,
isGelatoApiConnected,
fetchUserHistory,
handleClaim,
} = useL1History();
Expand Down Expand Up @@ -224,6 +225,7 @@ export default defineComponent({
isApproved,
isApproving,
isApproveMaxAmount,
isGelatoApiConnected,
inputImportTokenHandler,
cancelHighlight,
handleSetToken,
Expand Down
25 changes: 25 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 All @@ -19,8 +20,14 @@ import { useEthProvider } from '../custom-signature/useEthProvider';
import { astarNativeTokenErcAddr } from 'src/modules/xcm';
import { AbiItem } from 'web3-utils';
import ERC20_ABI from 'src/config/abi/ERC20.json';
import { useStore } from 'src/store';
import { useI18n } from 'vue-i18n';

export const useL1History = () => {
const { t } = useI18n();
const store = useStore();
const isGelatoApiConnected = ref<boolean>(false);

const l1Network = computed<string>(() => {
const networkIdxStore = String(localStorage.getItem(LOCAL_STORAGE.NETWORK_IDX));
return networkIdxStore === String(endpointKey.ASTAR_ZKEVM)
Expand Down Expand Up @@ -68,9 +75,16 @@ export const useL1History = () => {
};

const fetchUserHistory = async (): Promise<void> => {
if (!currentAccount.value) return;
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]);
const l2Web3 = buildWeb3Instance(EthBridgeChainId[l2Network.value as EthBridgeNetworkName]);

Expand Down Expand Up @@ -121,6 +135,16 @@ export const useL1History = () => {
isFetchAutomatically.value = numberInProgress > 0;
histories.value = formattedResult.sort((a, b) => Number(b.timestamp) - Number(a.timestamp));
} catch (error) {
// Memo: disable sending bridge transactions from UI
store.dispatch(
'general/showAlertMsg',
{
msg: t('bridge.gelatoApiError'),
alertType: 'error',
},
{ root: true }
);
isGelatoApiConnected.value = false;
console.error(error);
isFetchAutomatically.value = false;
} finally {
Expand All @@ -146,6 +170,7 @@ export const useL1History = () => {
histories,
isLoadingHistories,
isActionRequired,
isGelatoApiConnected,
handleClaim,
fetchUserHistory,
};
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export const useGasPrice = (isFetch = false) => {
watch(
[network],
async () => {
if (isFetch && network.value && !gas.value && isEnableSpeedConfiguration.value) {
if (
isFetch &&
network.value &&
!gas.value &&
isEnableSpeedConfiguration.value &&
!isZkEvm.value
) {
// console.info('gas price', network.value, gas.value);
await dispatchGasPrice(network.value);
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ export default {
warning32blocks: 'It could take around 10~20mins or more to finalize',
warning2steps:
'Bridging to L1 (Ethereum) involves 2 steps, and it requires users to make a claim on the L1 network (available in Recent History)',
gelatoApiError: 'Bridge UI is not available, please try again later',
tokenInfo: {
invalidTokenAddress: 'Invalid token address',
tokenAddress: '{network} token address',
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
Loading