Skip to content

Commit

Permalink
Merge recent changes (703508b) from RaidGuild repo
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov authored Feb 10, 2021
2 parents 6b4d01f + 26655f0 commit 7696fc2
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 59 deletions.
8 changes: 8 additions & 0 deletions packages/react-app/.sample-env
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/react-app/src/components/BridgeHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions packages/react-app/src/components/BridgeLoadingModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions packages/react-app/src/components/ConfirmTransferModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
2 changes: 0 additions & 2 deletions packages/react-app/src/components/ConnectWeb3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -65,7 +64,6 @@ export const ConnectWeb3 = () => {
Connect
</Button>
)}
<TermsOfServiceModal />
</Flex>
);
};
38 changes: 25 additions & 13 deletions packages/react-app/src/components/FromToken.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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 (
<Flex
Expand Down Expand Up @@ -91,7 +97,13 @@ export const FromToken = () => {
mb={2}
direction={{ base: 'column', sm: 'row' }}
>
<Flex align="center" cursor="pointer" onClick={onOpen}>
<Flex
align="center"
cursor="pointer"
onClick={onOpen}
zIndex={1}
background="white"
>
<Flex
justify="center"
align="center"
Expand Down
2 changes: 2 additions & 0 deletions packages/react-app/src/components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getBridgeNetwork } from '../lib/helpers';
import { ConnectWeb3 } from './ConnectWeb3';
import { Footer } from './Footer';
import { Header } from './Header';
import { TermsOfServiceModal } from './TermsOfServiceModal';

export const Layout = ({ children }) => {
const { account, providerChainId } = useContext(Web3Context);
Expand Down Expand Up @@ -58,6 +59,7 @@ export const Layout = ({ children }) => {
{valid ? children : <ConnectWeb3 />}
</Flex>
<Footer />
<TermsOfServiceModal />
</Flex>
);
};
33 changes: 20 additions & 13 deletions packages/react-app/src/components/ToToken.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Flex, Spinner, Text, useBreakpointValue } from '@chakra-ui/react';
import { BigNumber, utils } from 'ethers';
import React, { useContext, useEffect, useState } from 'react';
import { defer } from 'rxjs';

import { BridgeContext } from '../contexts/BridgeContext';
import { Web3Context } from '../contexts/Web3Context';
import { formatValue, logError } from '../lib/helpers';
import { formatValue, getBridgeNetwork, logError } from '../lib/helpers';
import { fetchTokenBalance } from '../lib/token';
import { Logo } from './Logo';

export const ToToken = () => {
const { account } = useContext(Web3Context);
const { account, providerChainId } = useContext(Web3Context);
const {
updateBalance,
toToken: token,
Expand All @@ -18,28 +19,34 @@ export const ToToken = () => {
toBalance: balance,
setToBalance: setBalance,
} = useContext(BridgeContext);
const chainId = getBridgeNetwork(providerChainId);

const smallScreen = useBreakpointValue({ base: true, lg: false });
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(toBalanceError => {
logError({ toBalanceError });
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 (
<Flex
Expand Down
10 changes: 7 additions & 3 deletions packages/react-app/src/contexts/Web3Context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import Web3 from 'web3';
import Web3Modal from 'web3modal';

import { INFURA_ID } from '../lib/constants';
import { getNetworkName, logError } from '../lib/helpers';
import { getNetworkName, getRPCUrl, logError } from '../lib/helpers';

export const Web3Context = React.createContext({});

Expand All @@ -30,7 +29,12 @@ const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: INFURA_ID,
rpc: {
1: getRPCUrl(1),
42: getRPCUrl(42),
100: getRPCUrl(100),
77: getRPCUrl(77),
},
},
},
};
Expand Down
Loading

0 comments on commit 7696fc2

Please sign in to comment.