From c0bdc8cd727dab26258c282e695cd964cd0408de Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 14 Oct 2018 18:33:46 +0200 Subject: [PATCH] fix no account message, alerts refactor --- src/components/Web3Donation/Alerts.jsx | 114 +++++++++++++------------ 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/src/components/Web3Donation/Alerts.jsx b/src/components/Web3Donation/Alerts.jsx index 84ffd6f6..edcb4308 100644 --- a/src/components/Web3Donation/Alerts.jsx +++ b/src/components/Web3Donation/Alerts.jsx @@ -1,62 +1,68 @@ -import React, { Fragment } from 'react' +import React, { Fragment, PureComponent } from 'react' import PropTypes from 'prop-types' import styles from './Alerts.module.scss' -const alertMessages = (networkName, transactionHash) => ({ - noAccount: - 'Web3 detected, but no account. Are you logged into your MetaMask account?', - noCorrectNetwork: `Please connect to Main network. You are on ${networkName} right now.`, - noWeb3: - 'No Web3 detected. Install MetaMask, Brave, or Mist.', - success: `You are awesome, thanks!
- - See your transaction on etherscan.io. - ` -}) +const Message = ({ message, ...props }) => ( +
+) -const Alerts = ({ - hasCorrectNetwork, - hasAccount, - networkName, - error, - transactionHash, - web3Connected -}) => { - return !web3Connected ? ( - - ) : ( - +export default class Alerts extends PureComponent { + static propTypes = { + hasCorrectNetwork: PropTypes.bool, + hasAccount: PropTypes.bool, + networkName: PropTypes.string, + error: PropTypes.object, + transactionHash: PropTypes.string, + web3Connected: PropTypes.bool + } + + alertMessages = (networkName, transactionHash) => ({ + noAccount: + 'Web3 detected, but no account. Are you logged into your MetaMask account?', + noCorrectNetwork: `Please connect to Main network. You are on ${networkName} right now.`, + noWeb3: + 'No Web3 detected. Install MetaMask, Brave, or Mist.', + success: `You are awesome, thanks!
+ + See your transaction on etherscan.io. + ` + }) + + render() { + const { + hasCorrectNetwork, + hasAccount, + networkName, + error, + transactionHash, + web3Connected + } = this.props + + return (
- {!hasAccount &&
{alertMessages().noaccount}
} - {!hasCorrectNetwork && ( -
+ {!web3Connected ? ( + + ) : ( + + {!hasAccount && ( + + )} + {!hasCorrectNetwork && ( + + )} + {error && } + + {transactionHash && ( + + )} + )} - {error &&
{error.message}
}
- - {transactionHash && ( -
- )} - - ) + ) + } } - -Alerts.propTypes = { - hasCorrectNetwork: PropTypes.bool, - hasAccount: PropTypes.bool, - networkName: PropTypes.string, - error: PropTypes.object, - transactionHash: PropTypes.string, - web3Connected: PropTypes.bool -} - -export default Alerts