diff --git a/README.md b/README.md index 749b88b0..e3b8dd4c 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ As a fallback, QR codes are generated with [react-qr-svg](https://github.com/no2 If you want to know how this works, have a look at the respective components under -- [`src/components/atoms/Web3Donation.jsx`](src/components/atoms/Web3Donation.jsx) +- [`src/components/Web3Donation/index.jsx`](src/components/Web3Donation/index.jsx) - [`src/components/atoms/Qr.jsx`](src/components/atoms/Qr.jsx) ### 🕸 Related Posts diff --git a/src/components/Web3Donation/Alerts.jsx b/src/components/Web3Donation/Alerts.jsx new file mode 100644 index 00000000..70212f4a --- /dev/null +++ b/src/components/Web3Donation/Alerts.jsx @@ -0,0 +1,52 @@ +import React from 'react' +import PropTypes from 'prop-types' +import styles from './Alerts.module.scss' + +const Alerts = ({ + accounts, + networkId, + networkName, + error, + transactionHash +}) => { + const isCorrectNetwork = networkId === '1' + const hasAccount = accounts.length !== 0 + + if (error || hasAccount || isCorrectNetwork) +
+ {!hasAccount && ( +
+ Web3 detected, but no account. Are you logged into your MetaMask + account? +
+ )} + {!isCorrectNetwork && ( +
+ Please connect to Main network. You are on{' '} + {networkName} right now. +
+ )} + {error &&
{error.message}
} +
+ + if (transactionHash) +
+ You are awesome, thanks! +
+ + See your transaction on etherscan.io. + +
+ + return null +} + +Alerts.propTypes = { + accounts: PropTypes.array, + networkId: PropTypes.string, + networkName: PropTypes.string, + error: PropTypes.object, + transactionHash: PropTypes.string +} + +export default Alerts diff --git a/src/components/Web3Donation/Alerts.module.scss b/src/components/Web3Donation/Alerts.module.scss new file mode 100644 index 00000000..f5b301e9 --- /dev/null +++ b/src/components/Web3Donation/Alerts.module.scss @@ -0,0 +1,13 @@ +@import 'variables'; +@import 'mixins'; + +.alert { + margin-top: $spacer / 2; + font-size: $font-size-small; + color: darken($alert-error, 60%); +} + +.success { + composes: alert; + color: darken($alert-success, 60%); +} diff --git a/src/components/Web3Donation/InputGroup.jsx b/src/components/Web3Donation/InputGroup.jsx new file mode 100644 index 00000000..92db2eb4 --- /dev/null +++ b/src/components/Web3Donation/InputGroup.jsx @@ -0,0 +1,49 @@ +import React, { PureComponent } from 'react' +import PropTypes from 'prop-types' +import Input from '../atoms/Input' +import styles from './InputGroup.module.scss' + +export default class InputGroup extends PureComponent { + static propTypes = { + networkId: PropTypes.string, + selectedAccount: PropTypes.string, + amount: PropTypes.number, + onAmountChange: PropTypes.func, + handleWeb3Button: PropTypes.func + } + + render() { + const { + networkId, + selectedAccount, + amount, + onAmountChange, + handleWeb3Button + } = this.props + + return ( +
+
+ +
+ ETH +
+
+ +
+ ) + } +} diff --git a/src/components/atoms/Web3Donation.module.scss b/src/components/Web3Donation/InputGroup.module.scss similarity index 77% rename from src/components/atoms/Web3Donation.module.scss rename to src/components/Web3Donation/InputGroup.module.scss index dcf801d6..e273de90 100644 --- a/src/components/atoms/Web3Donation.module.scss +++ b/src/components/Web3Donation/InputGroup.module.scss @@ -1,26 +1,6 @@ @import 'variables'; @import 'mixins'; -.web3 { - @include divider; - - width: 100%; - text-align: center; - margin-top: $spacer / 2; - margin-bottom: $spacer; - padding-bottom: $spacer * 1.5; - - small { - color: darken($alert-info, 60%); - margin-top: -($spacer / 2); - display: block; - } -} - -.web3Row { - min-height: 58px; -} - .inputGroup { max-width: 17rem; margin: auto; @@ -92,14 +72,3 @@ display: flex; align-items: center; } - -.alert { - margin-top: $spacer / 2; - font-size: $font-size-small; - color: darken($alert-error, 60%); -} - -.success { - composes: alert; - color: darken($alert-success, 60%); -} diff --git a/src/components/atoms/Web3Donation.jsx b/src/components/Web3Donation/index.jsx similarity index 73% rename from src/components/atoms/Web3Donation.jsx rename to src/components/Web3Donation/index.jsx index f20e6d88..4d5cb130 100644 --- a/src/components/atoms/Web3Donation.jsx +++ b/src/components/Web3Donation/index.jsx @@ -1,98 +1,13 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import Web3 from 'web3' -import Input from '../atoms/Input' -import styles from './Web3Donation.module.scss' +import InputGroup from './InputGroup' +import Alerts from './Alerts' +import styles from './index.module.scss' const ONE_SECOND = 1000 const ONE_MINUTE = ONE_SECOND * 60 -const InputGroup = ({ - networkId, - selectedAccount, - amount, - onAmountChange, - handleWeb3Button -}) => ( -
-
- -
- ETH -
-
- -
-) - -InputGroup.propTypes = { - networkId: PropTypes.string, - selectedAccount: PropTypes.string, - amount: PropTypes.number, - onAmountChange: PropTypes.func, - handleWeb3Button: PropTypes.func -} - -const Alerts = ({ - accounts, - networkId, - networkName, - error, - transactionHash -}) => { - const isCorrectNetwork = networkId === '1' - const hasAccount = accounts.length !== 0 - - if (error || hasAccount || isCorrectNetwork) -
- {!hasAccount && ( -
- Web3 detected, but no account. Are you logged into your MetaMask - account? -
- )} - {!isCorrectNetwork && ( -
- Please connect to Main network. You are on{' '} - {networkName} right now. -
- )} - {error &&
{error.message}
} -
- - if (transactionHash) -
- You are awesome, thanks! -
- - See your transaction on etherscan.io. - -
- - return null -} - -Alerts.propTypes = { - accounts: PropTypes.array, - networkId: PropTypes.string, - networkName: PropTypes.string, - error: PropTypes.object, - transactionHash: PropTypes.string -} - export default class Web3Donation extends PureComponent { state = { web3Connected: false, diff --git a/src/components/Web3Donation/index.module.scss b/src/components/Web3Donation/index.module.scss new file mode 100644 index 00000000..5796a2e1 --- /dev/null +++ b/src/components/Web3Donation/index.module.scss @@ -0,0 +1,22 @@ +@import 'variables'; +@import 'mixins'; + +.web3 { + @include divider; + + width: 100%; + text-align: center; + margin-top: $spacer / 2; + margin-bottom: $spacer; + padding-bottom: $spacer * 1.5; + + small { + color: darken($alert-info, 60%); + margin-top: -($spacer / 2); + display: block; + } +} + +.web3Row { + min-height: 58px; +} diff --git a/src/components/atoms/Modal.module.scss b/src/components/atoms/Modal.module.scss index cfade373..28ae690b 100644 --- a/src/components/atoms/Modal.module.scss +++ b/src/components/atoms/Modal.module.scss @@ -52,6 +52,7 @@ right: ($spacer/4); color: $brand-grey-light; font-weight: 500; + outline: 0; &:hover, &:focus { diff --git a/src/components/molecules/ModalThanks.jsx b/src/components/molecules/ModalThanks.jsx index d035be71..118156be 100644 --- a/src/components/molecules/ModalThanks.jsx +++ b/src/components/molecules/ModalThanks.jsx @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react' import { StaticQuery, graphql } from 'gatsby' -import Web3Donation from '../atoms/Web3Donation' +import Web3Donation from '../Web3Donation' import Qr from '../atoms/Qr' import Modal from '../atoms/Modal' import styles from './ModalThanks.module.scss'