diff --git a/src/bootstrap/app.js b/src/bootstrap/app.js index b5fd8a9..290e804 100755 --- a/src/bootstrap/app.js +++ b/src/bootstrap/app.js @@ -9,7 +9,7 @@ import NavBar from '../components/nav-bar' import Home from '../containers/home' import SimpleBid from '../containers/simple-bid' import IICO from '../containers/iico' -import PageNotFound from '../components/page-not-found' +import PageNotFound from '../containers/page-not-found' import Initializer from './initializer' import GlobalComponents from './global-components' @@ -75,7 +75,11 @@ const App = ({ store, history, testElement }) => ( path={`/interactive/:address${ETHAddressRegExpCaptureGroup}`} component={IICO} /> - + {testElement} diff --git a/src/bootstrap/initializer.js b/src/bootstrap/initializer.js index 3827b15..80c1aaf 100755 --- a/src/bootstrap/initializer.js +++ b/src/bootstrap/initializer.js @@ -47,41 +47,44 @@ class Initializer extends PureComponent { } pathAddressCheck = async () => { - this.setState({ pathAddress: undefined }) - // Get possible address from path let address = window.location.pathname.match(ETHAddressRegExp) address = address && address[0] - // There is an address - if (address) { - // Check that it has code - try { - const code = await eth.getCode(address) - if (code === '0x') throw new Error() - } catch (err) { - console.error(err) - return window.location.replace('/404') - } - - // Is it checksummed? - const checksumAddress = getChecksumAddress(address) - if (address !== checksumAddress) - return window.location.replace( - window.location.pathname.replace(address, checksumAddress) - ) // No, replace it - } - - // Block all other sales for now to avoid phishing + // Block all other sales for now in the master branch to avoid phishing if ( process.env.REACT_APP_BRANCH === 'master' && - address !== '0xac43300F2D0c345B716F36853eCeb497576E0F67' + (!address || address !== '0xac43300F2D0c345B716F36853eCeb497576E0F67') ) return window.location.replace( '/0xac43300F2D0c345B716F36853eCeb497576E0F67' ) - this.setState({ pathAddress: address || null }) + if (!address) return this.setState({ pathAddress: null }) // No address, stop loading indicator + + // Check that it has code + const checksumAddress = getChecksumAddress(address) + const is404 = window.location.pathname.slice(0, 4) === '/404' + try { + const code = await eth.getCode(address) + if (code === '0x') throw new Error() + // Has code + if (is404) return window.location.replace(`/${checksumAddress}`) // If in 404, we can go back to home + } catch (err) { + console.error(err) + return is404 // No code + ? this.setState({ pathAddress: null }) // Already in 404, do nothing + : window.location.replace(`/404/${checksumAddress}`) // Go to 404 + } + + // It has code and we are not in 404, is it checksummed? + if (address !== checksumAddress) + return window.location.replace( + window.location.pathname.replace(address, checksumAddress) + ) // No, replace it + + // All good, set address + return this.setState({ pathAddress: address }) } render() { diff --git a/src/components/__snapshots__/storyshots.test.js.snap b/src/components/__snapshots__/storyshots.test.js.snap index 7827624..c3b5533 100755 --- a/src/components/__snapshots__/storyshots.test.js.snap +++ b/src/components/__snapshots__/storyshots.test.js.snap @@ -3838,316 +3838,6 @@ exports[`Storyshots Nav Bar with routes 1`] = ` `; -exports[`Storyshots Page Not Found default 1`] = ` -
-
-
-

- OpenIICO UI-Kit -

-
-
-
-
-
-
-
- 404 -
- This is not the page you are looking for. -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
-
-
- - -
- -
-
-
-`; - exports[`Storyshots Pie Chart activated 1`] = `
( -
-
-
404
- This is not the page you are looking for. -
-
-) diff --git a/src/containers/page-not-found/index.js b/src/containers/page-not-found/index.js new file mode 100755 index 0000000..21e20d9 --- /dev/null +++ b/src/containers/page-not-found/index.js @@ -0,0 +1,28 @@ +import React from 'react' +import PropTypes from 'prop-types' + +import './page-not-found.css' + +const PageNotFound = ({ match: { params: { address } } }) => ( +
+
+
404
+ This is not the page you are looking for. + {address && ( +

+ Are you sure {address} is a valid contract address and that you are on + the correct network? +

+ )} +
+
+) + +PageNotFound.propTypes = { + // React Router + match: PropTypes.shape({ + params: PropTypes.shape({ address: PropTypes.string }).isRequired + }).isRequired +} + +export default PageNotFound diff --git a/src/components/page-not-found/page-not-found.scss b/src/containers/page-not-found/page-not-found.scss similarity index 100% rename from src/components/page-not-found/page-not-found.scss rename to src/containers/page-not-found/page-not-found.scss diff --git a/stories/index.js b/stories/index.js index 2a50504..b889406 100755 --- a/stories/index.js +++ b/stories/index.js @@ -7,7 +7,6 @@ import './eth-qr' import './form' import './identicon' import './nav-bar' -import './page-not-found' import './pie-chart' import './requires-meta-mask' import './slider' diff --git a/stories/page-not-found.js b/stories/page-not-found.js deleted file mode 100755 index 0410e79..0000000 --- a/stories/page-not-found.js +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react' -import { storiesOf } from '@storybook/react' - -import PageNotFound from '../src/components/page-not-found' - -storiesOf('Page Not Found', module).add('default', () => )