diff --git a/packages/react-app/.sample-env b/packages/react-app/.sample-env index b73a3612..a7cd3284 100644 --- a/packages/react-app/.sample-env +++ b/packages/react-app/.sample-env @@ -73,3 +73,11 @@ REACT_APP_UI_STATUS_UPDATE_INTERVAL=1000 # if unset default => false ###################################################### REACT_APP_DEBUG_LOGS=false + +###################################################### +# if unset default => +# UPDATE_INTERVAL => 15000 +# THRESHOLD_BLOCKS => 10 +###################################################### +REACT_APP_GRAPH_HEALTH_UPDATE_INTERVAL=15000 +REACT_APP_GRAPH_HEALTH_THRESHOLD_BLOCKS=10 diff --git a/packages/react-app/package.json b/packages/react-app/package.json index bb9fc6f0..629a2fde 100644 --- a/packages/react-app/package.json +++ b/packages/react-app/package.json @@ -43,6 +43,7 @@ "react-dom": "16.12.0", "react-router-dom": "^5.2.0", "react-scripts": "3.4.1", + "rxjs": "^6.6.3", "web3": "^1.3.1", "web3modal": "^1.9.2" }, diff --git a/packages/react-app/src/components/BridgeHistory.jsx b/packages/react-app/src/components/BridgeHistory.jsx index a9d498fc..1a8ae836 100644 --- a/packages/react-app/src/components/BridgeHistory.jsx +++ b/packages/react-app/src/components/BridgeHistory.jsx @@ -2,6 +2,7 @@ import { Checkbox, Flex, Grid, Text } from '@chakra-ui/react'; import React, { useState } from 'react'; import { Redirect } from 'react-router-dom'; +import { useGraphHealth } from '../hooks/useGraphHealth'; import { useUserHistory } from '../lib/history'; import { HistoryItem } from './HistoryItem'; import { HistoryPagination } from './HistoryPagination'; @@ -14,6 +15,9 @@ export const BridgeHistory = ({ page }) => { const [onlyUnReceived, setOnlyUnReceived] = useState(false); const { transfers, loading } = useUserHistory(); + useGraphHealth( + 'Cannot access history data. Wait for a few minutes and reload the application', + ); if (loading) { return ( diff --git a/packages/react-app/src/components/BridgeLoadingModal.jsx b/packages/react-app/src/components/BridgeLoadingModal.jsx index 493e609a..d506017b 100644 --- a/packages/react-app/src/components/BridgeLoadingModal.jsx +++ b/packages/react-app/src/components/BridgeLoadingModal.jsx @@ -13,6 +13,7 @@ import React, { useContext } from 'react'; import BlueTickImage from '../assets/blue-tick.svg'; import LoadingImage from '../assets/loading.svg'; import { BridgeContext } from '../contexts/BridgeContext'; +import { useGraphHealth } from '../hooks/useGraphHealth'; import { useTransactionStatus } from '../hooks/useTransactionStatus'; import { getMonitorUrl } from '../lib/helpers'; import { NeedsConfirmationModal } from './NeedsConfirmationModal'; @@ -28,6 +29,9 @@ export const BridgeLoadingModal = () => { const { loading, fromToken, txHash, totalConfirms } = useContext( BridgeContext, ); + useGraphHealth( + 'Cannot collect data to finalize the transfer. Wait for a few minutes, reload the application and look for your unclaimed transactions in the History tab', + ); const { loadingText, needsConfirmation, diff --git a/packages/react-app/src/components/ConfirmTransferModal.jsx b/packages/react-app/src/components/ConfirmTransferModal.jsx index e3bbe373..2de1613e 100644 --- a/packages/react-app/src/components/ConfirmTransferModal.jsx +++ b/packages/react-app/src/components/ConfirmTransferModal.jsx @@ -65,15 +65,22 @@ export const ConfirmTransferModal = ({ isOpen, onClose }) => { }; const onClick = () => { transfer().catch(error => { - if ( - error && - error.message && - !error.message.includes('User denied transaction signature') - ) { + if (error && error.message) { + showError(error.message); + } else { showError( 'Impossible to perform the operation. Reload the application and try again.', ); } + // if ( + // error && + // error.message && + // !error.message.includes('User denied transaction signature') + // ) { + // showError( + // 'Impossible to perform the operation. Reload the application and try again.', + // ); + // } }); onClose(); }; diff --git a/packages/react-app/src/components/ConnectWeb3.jsx b/packages/react-app/src/components/ConnectWeb3.jsx index 094ccafa..73e390fd 100644 --- a/packages/react-app/src/components/ConnectWeb3.jsx +++ b/packages/react-app/src/components/ConnectWeb3.jsx @@ -5,7 +5,6 @@ import { Web3Context } from '../contexts/Web3Context'; import { WalletFilledIcon } from '../icons/WalletFilledIcon'; import { HOME_NETWORK } from '../lib/constants'; import { getBridgeNetwork, getNetworkName } from '../lib/helpers'; -import { TermsOfServiceModal } from './TermsOfServiceModal'; export const ConnectWeb3 = () => { const { connectWeb3, loading, account, disconnect } = useContext(Web3Context); @@ -65,7 +64,6 @@ export const ConnectWeb3 = () => { Connect )} - ); }; diff --git a/packages/react-app/src/components/FromToken.jsx b/packages/react-app/src/components/FromToken.jsx index f9f013a0..d404479e 100644 --- a/packages/react-app/src/components/FromToken.jsx +++ b/packages/react-app/src/components/FromToken.jsx @@ -10,6 +10,7 @@ import { } from '@chakra-ui/react'; import { BigNumber, utils } from 'ethers'; import React, { useContext, useEffect, useState } from 'react'; +import { defer } from 'rxjs'; import DropDown from '../assets/drop-down.svg'; import { BridgeContext } from '../contexts/BridgeContext'; @@ -20,7 +21,7 @@ import { Logo } from './Logo'; import { SelectTokenModal } from './SelectTokenModal'; export const FromToken = () => { - const { account } = useContext(Web3Context); + const { account, providerChainId: chainId } = useContext(Web3Context); const { updateBalance, fromToken: token, @@ -36,23 +37,28 @@ export const FromToken = () => { const [balanceLoading, setBalanceLoading] = useState(false); useEffect(() => { - if (token && account) { + let subscription; + if (token && account && chainId === token.chainId) { setBalanceLoading(true); - setBalance(BigNumber.from(0)); - fetchTokenBalance(token, account) - .then(b => { - setBalance(b); - setBalanceLoading(false); - }) - .catch(contractError => { - logError({ contractError }); + subscription = defer(() => + fetchTokenBalance(token, account).catch(fromBalanceError => { + logError({ fromBalanceError }); setBalance(BigNumber.from(0)); setBalanceLoading(false); - }); + }), + ).subscribe(b => { + setBalance(b); + setBalanceLoading(false); + }); } else { setBalance(BigNumber.from(0)); } - }, [updateBalance, token, account, setBalance, setBalanceLoading]); + return () => { + if (subscription) { + subscription.unsubscribe(); + } + }; + }, [updateBalance, token, account, setBalance, setBalanceLoading, chainId]); return ( { mb={2} direction={{ base: 'column', sm: 'row' }} > - + { const { account, providerChainId } = useContext(Web3Context); @@ -58,6 +59,7 @@ export const Layout = ({ children }) => { {valid ? children : }