From 329d5d184a292763fabb64a7395bdbca67d58d87 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 9 Mar 2018 18:06:21 -0300 Subject: [PATCH 1/7] Add Web3Provider --- package-lock.json | 30 +++++++++++----------- package.json | 1 + src/App.js | 45 +++++++++++++++++++-------------- src/components/Common/NoWeb3.js | 20 +++++++++++++++ src/index.js | 6 +++++ src/react-web3/Web3Provider.js | 24 ++++++++++++++++++ src/react-web3/index.js | 3 +++ 7 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 src/components/Common/NoWeb3.js create mode 100644 src/react-web3/Web3Provider.js create mode 100644 src/react-web3/index.js diff --git a/package-lock.json b/package-lock.json index 16b91ffc0..d28ab357e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3827,7 +3827,7 @@ "lodash": "4.17.4", "object.assign": "4.1.0", "object.values": "1.0.4", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "enzyme-adapter-utils": { @@ -3838,7 +3838,7 @@ "requires": { "lodash": "4.17.4", "object.assign": "4.1.0", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "errno": { @@ -6283,7 +6283,7 @@ "fbjs": "0.8.16", "inline-style-prefixer": "3.0.8", "object-assign": "4.1.1", - "prop-types": "15.6.0", + "prop-types": "15.6.1", "through": "2.3.8" } }, @@ -12229,9 +12229,9 @@ } }, "prop-types": { - "version": "15.6.0", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.0.tgz", - "integrity": "sha1-zq8IMCL8RrSjX2nhPvda7Q1jmFY=", + "version": "15.6.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz", + "integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==", "requires": { "fbjs": "0.8.16", "loose-envify": "1.3.1", @@ -12289,7 +12289,7 @@ "resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-0.7.2.tgz", "integrity": "sha512-s1x+E3bsp0ojI8cHQ+czr+aG3huLZegH+tqAuRsXh6oXvzNfC+9L2PeFRBBu8eRBiejMRrRzSH7iwi5LDyWfRg==", "requires": { - "prop-types": "15.6.0", + "prop-types": "15.6.1", "qr.js": "0.0.0" } }, @@ -12445,7 +12445,7 @@ "fbjs": "0.8.16", "loose-envify": "1.3.1", "object-assign": "4.1.1", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "react-alert": { @@ -12465,7 +12465,7 @@ "integrity": "sha512-ELKq31/E3zjFs5rDWNCfFL4NvNFQvGRoJdAKReD/rUPA+xxiLPQmZBZBvy2vgH7V0GE9isIQpT9WXbwIVErYdA==", "requires": { "copy-to-clipboard": "3.0.8", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "react-countdown-clock": { @@ -12475,7 +12475,7 @@ "requires": { "coffeescript": "2.2.0", "create-react-class": "15.6.3", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "react-dev-utils": { @@ -12658,7 +12658,7 @@ "fbjs": "0.8.16", "loose-envify": "1.3.1", "object-assign": "4.1.1", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "react-dropzone": { @@ -12667,7 +12667,7 @@ "integrity": "sha512-L/q6ySfhdG9Md3P21jFumzlm92TxRT0FtYX6G793Nf8bt7Fzpwx6gJsPk0idV094koj/Y5vRpp0q9+e0bdsjxw==", "requires": { "attr-accept": "1.1.2", - "prop-types": "15.6.0" + "prop-types": "15.6.1" } }, "react-error-overlay": { @@ -12718,7 +12718,7 @@ "invariant": "2.2.2", "loose-envify": "1.3.1", "path-to-regexp": "1.7.0", - "prop-types": "15.6.0", + "prop-types": "15.6.1", "warning": "3.0.0" } }, @@ -12730,7 +12730,7 @@ "history": "4.7.2", "invariant": "2.2.2", "loose-envify": "1.3.1", - "prop-types": "15.6.0", + "prop-types": "15.6.1", "react-router": "4.2.0", "warning": "3.0.0" } @@ -12753,7 +12753,7 @@ "chain-function": "1.0.0", "dom-helpers": "3.3.1", "loose-envify": "1.3.1", - "prop-types": "15.6.0", + "prop-types": "15.6.1", "warning": "3.0.0" } }, diff --git a/package.json b/package.json index 932537b6f..e88f80509 100755 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "postcss-flexbugs-fixes": "3.0.0", "postcss-loader": "2.0.6", "promise": "7.1.1", + "prop-types": "^15.6.1", "qrcode.react": "^0.7.2", "query-string": "^5.0.1", "react": "^15.6.1", diff --git a/src/App.js b/src/App.js index 5b24cf63b..c51aff383 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { inject, observer } from 'mobx-react' import './assets/stylesheets/application.css'; import { Header, Footer, Home, Manage, stepOne, stepTwo, stepThree, stepFour, Crowdsale, Invest } from './components/index' +import NoWeb3 from './components/Common/NoWeb3' import IncompleteDeploy from './components/IncompleteDeploy' import { getQueryVariable } from './utils/utils' import { @@ -12,6 +13,7 @@ import { import AlertContainer from 'react-alert' import { TOAST } from './utils/constants' import { toast } from './utils/utils' +import { Web3Provider } from './react-web3' @inject('deploymentStore') @observer @@ -25,26 +27,31 @@ class App extends Component {
- - {/* The route to /4 must be first for the incomplete deploy redirect to work */} - + + + {/* The route to /4 must be first for the incomplete deploy redirect to work */} + - { - deploymentStore.deploymentStep !== null ? ( - - ) : ( - - - - - - - - - - ) - } - + { + deploymentStore.deploymentStep !== null ? ( + + ) : ( + + + + + + + + + + ) + } + +
toast.msg = a} {...TOAST.DEFAULT_OPTIONS} /> diff --git a/src/components/Common/NoWeb3.js b/src/components/Common/NoWeb3.js new file mode 100644 index 000000000..1cc4724f4 --- /dev/null +++ b/src/components/Common/NoWeb3.js @@ -0,0 +1,20 @@ +import React, { Component } from 'react'; + +export default class NoWeb3 extends Component { + render () { + return ( +
+
+
+
+

MetaMask Not Found

+

+ You don't have MetaMask installed. Check Token Wizard GitHub for the instruction. +

+
+
+
+
+ ); + } +} diff --git a/src/index.js b/src/index.js index c3196ee30..9479d16d3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import Web3 from 'web3' import App from './App'; import registerServiceWorker from './registerServiceWorker'; import { useStrict } from 'mobx'; @@ -13,6 +14,11 @@ if (!process.env['REACT_APP_REGISTRY_ADDRESS']) { throw new Error('REACT_APP_REGISTRY_ADDRESS env variable is not present') } +const devEnvironment = process.env.NODE_ENV === 'development'; +if (devEnvironment) { + window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); +} + ReactDOM.render( diff --git a/src/react-web3/Web3Provider.js b/src/react-web3/Web3Provider.js new file mode 100644 index 000000000..16f4ec9fe --- /dev/null +++ b/src/react-web3/Web3Provider.js @@ -0,0 +1,24 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types' + +class Web3Provider extends Component { + render() { + if (window.web3) { + return this.props.children + } + + return + } + + getChildContext() { + return { + web3: window.web3 + } + } +} + +Web3Provider.childContextTypes = { + web3: PropTypes.object +} + +export default Web3Provider; diff --git a/src/react-web3/index.js b/src/react-web3/index.js new file mode 100644 index 000000000..a69bdb015 --- /dev/null +++ b/src/react-web3/index.js @@ -0,0 +1,3 @@ +import Web3Provider from './Web3Provider' + +export { Web3Provider } From 9eb190f80faceee9a431925207049fcbc5cf0a38 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 12 Mar 2018 15:33:18 -0300 Subject: [PATCH 2/7] Add onChangeAccount callback and selectedAccount context variable --- src/react-web3/Web3Provider.js | 72 ++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/src/react-web3/Web3Provider.js b/src/react-web3/Web3Provider.js index 16f4ec9fe..496bb1499 100644 --- a/src/react-web3/Web3Provider.js +++ b/src/react-web3/Web3Provider.js @@ -1,24 +1,88 @@ -import React, { Component } from 'react'; +import React, { Component } from 'react' import PropTypes from 'prop-types' +import Web3 from 'web3' + +const ONE_SECOND = 1000; class Web3Provider extends Component { + constructor(props, context) { + super(props, context) + + this.state = { + selectedAccount: null + } + + this.web3 = null + this.interval = null + + } render() { + const { web3UnavailableScreen: Web3UnavailableScreen } = this.props + if (window.web3) { + if (!this.web3) { + this.web3 = new Web3(window.web3.currentProvider); + this.fetchAccounts() + } + return this.props.children } - return + return + } + + componentDidMount() { + this.initPoll(); + } + + initPoll = () => { + if (!this.interval) { + this.interval = setInterval(this.fetchAccounts, ONE_SECOND) + } + } + + fetchAccounts = () => { + const { web3 } = this + const { onChangeAccount } = this.props + + if (!web3 || !web3.eth) { + return + } + + return web3.eth.getAccounts() + .then(accounts => { + if (!accounts || !accounts.length) { + return + } + + let curr = this.state.selectedAccount + let next = accounts[0] + curr = curr && curr.toLowerCase() + next = next && next.toLowerCase() + + const didChange = curr && next && (curr !== next) + + if (didChange && typeof onChangeAccount === 'function') { + onChangeAccount(next) + } + + this.setState({ + selectedAccount: next || null + }) + }) } getChildContext() { return { - web3: window.web3 + web3: this.web3, + selectedAccount: this.state.selectedAccount } } } Web3Provider.childContextTypes = { - web3: PropTypes.object + web3: PropTypes.object, + selectedAccount: PropTypes.string } export default Web3Provider; From 7ac61e366ca6212c327e920d3af70a5bce11ba5c Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 12 Mar 2018 15:42:08 -0300 Subject: [PATCH 3/7] Replace some usages web3Store with injected web3 --- src/components/stepFour/index.js | 11 +++++++++-- src/components/stepFour/utils.js | 20 ++++++++++---------- src/utils/microservices.js | 9 +++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/components/stepFour/index.js b/src/components/stepFour/index.js index 81f739225..3d4dad687 100644 --- a/src/components/stepFour/index.js +++ b/src/components/stepFour/index.js @@ -31,6 +31,7 @@ import { isObservableArray } from 'mobx' import JSZip from 'jszip' import executeSequentially from '../../utils/executeSequentially' import { PreventRefresh } from '../Common/PreventRefresh' +import PropTypes from 'prop-types' const { PUBLISH } = NAVIGATION_STEPS @@ -46,6 +47,10 @@ export class stepFour extends React.Component { } } + static contextTypes = { + web3: PropTypes.object + } + contractDownloadSuccess = options => { this.setState({ contractDownloaded: true }) toast.showToaster({ message: TOAST.MESSAGE.CONTRACT_DOWNLOAD_SUCCESS, options }) @@ -63,12 +68,13 @@ export class stepFour extends React.Component { deployCrowdsale = () => { const { contractStore, deploymentStore } = this.props + const { web3 } = this.context const isWhitelistWithCap = contractStore.contractType === CONTRACT_TYPES.whitelistwithcap const firstRun = deploymentStore.deploymentStep === null if (isWhitelistWithCap) { if (firstRun) { - setupContractDeployment() + setupContractDeployment(web3) .then(this.resumeContractDeployment) } else { this.resumeContractDeployment() @@ -78,8 +84,9 @@ export class stepFour extends React.Component { resumeContractDeployment = () => { const { deploymentStore } = this.props + const { web3 } = this.context const startAt = deploymentStore.deploymentStep ? deploymentStore.deploymentStep : 0 - const deploymentSteps = buildDeploymentSteps() + const deploymentSteps = buildDeploymentSteps(web3) executeSequentially(deploymentSteps, startAt, (index) => { deploymentStore.setDeploymentStep(index) diff --git a/src/components/stepFour/utils.js b/src/components/stepFour/utils.js index 85743f3e2..c02e571f3 100644 --- a/src/components/stepFour/utils.js +++ b/src/components/stepFour/utils.js @@ -22,7 +22,7 @@ import { } from '../../stores' import { getEncodedABIClientSide } from '../../utils/microservices' -export const setupContractDeployment = () => { +export const setupContractDeployment = (web3) => { if (!contractStore.safeMathLib) { noContractDataAlert() return Promise.reject('no contract data') @@ -35,7 +35,7 @@ export const setupContractDeployment = () => { const whenTokenABIConstructor = Promise.resolve(tokenAddr) .then(tokenAddr => { if (!tokenAddr) { - return getEncodedABIClientSide(tokenABI, [], 0) + return getEncodedABIClientSide(web3, tokenABI, [], 0) .then(ABIEncoded => { console.log('token ABI Encoded params constructor:', ABIEncoded) contractStore.setContractProperty('token', 'abiConstructor', ABIEncoded) @@ -44,7 +44,7 @@ export const setupContractDeployment = () => { }) const whenPricingStrategyContract = tierStore.tiers.map((value, index) => { - return getEncodedABIClientSide(pricingStrategyABI, [], index) + return getEncodedABIClientSide(web3, pricingStrategyABI, [], index) .then(ABIEncoded => { console.log('pricingStrategy ABI Encoded params constructor:', ABIEncoded) const newContract = contractStore.pricingStrategy.abiConstructor.concat(ABIEncoded) @@ -55,14 +55,14 @@ export const setupContractDeployment = () => { return Promise.all([whenTokenABIConstructor, ...whenPricingStrategyContract]) } -export const buildDeploymentSteps = () => { +export const buildDeploymentSteps = (web3) => { const stepFnCorrelation = { safeMathLibrary: deploySafeMathLibrary, token: deployToken, - pricingStrategy: deployPricingStrategy, + pricingStrategy: deployPricingStrategy(web3), crowdsale: deployCrowdsale, registerCrowdsaleAddress: registerCrowdsaleAddress, - finalizeAgent: deployFinalizeAgent, + finalizeAgent: deployFinalizeAgent(web3), tier: setTier, setReservedTokens: setReservedTokensListMultiple, updateJoinedCrowdsales: updateJoinedCrowdsales, @@ -154,7 +154,7 @@ const getPricingStrategyParams = tier => { ] } -export const deployPricingStrategy = () => { +export const deployPricingStrategy = (web3) => () => { return tierStore.tiers.map((tier, index) => { return () => { const abiPricingStrategy = contractStore.pricingStrategy.abi || [] @@ -166,7 +166,7 @@ export const deployPricingStrategy = () => { return deployContract(abiPricingStrategy, binPricingStrategy, paramsPricingStrategy) .then(pricingStrategyAddr => contractStore.pricingStrategy.addr.concat(pricingStrategyAddr)) .then(newPricingStrategy => contractStore.setContractProperty('pricingStrategy', 'addr', newPricingStrategy)) - .then(() => getEncodedABIClientSide(abiCrowdsale, [], index, true)) + .then(() => getEncodedABIClientSide(web3, abiCrowdsale, [], index, true)) .then(ABIEncoded => contractStore.crowdsale.abiConstructor.concat(ABIEncoded)) .then(newContract => contractStore.setContractProperty('crowdsale', 'abiConstructor', newContract)) .then(() => deploymentStore.setAsSuccessful('pricingStrategy')) @@ -264,7 +264,7 @@ const getFinalizeAgentParams = index => { ] } -export const deployFinalizeAgent = () => { +export const deployFinalizeAgent = (web3) => () => { return tierStore.tiers.map((tier, index, tiers) => { return () => { let abi, bin, paramsFinalizeAgent @@ -279,7 +279,7 @@ export const deployFinalizeAgent = () => { bin = contractStore.nullFinalizeAgent.bin || '' } - return getEncodedABIClientSide(abi, [], index) + return getEncodedABIClientSide(web3, abi, [], index) .then(ABIEncoded => { console.log('finalizeAgent ABI encoded params constructor:', ABIEncoded) diff --git a/src/utils/microservices.js b/src/utils/microservices.js index 2178366ce..a404c5baa 100644 --- a/src/utils/microservices.js +++ b/src/utils/microservices.js @@ -1,17 +1,14 @@ import { findConstructor, toFixed } from '../utils/utils' import { getconstructorParams } from '../stores/utils' -import { web3Store } from '../stores' -export const getEncodedABIClientSide = (abi, vals, crowdsaleNum, isCrowdsale) => { +export const getEncodedABIClientSide = (web3, abi, vals, crowdsaleNum, isCrowdsale) => { const abiConstructor = findConstructor(abi) let params = getconstructorParams(abiConstructor, vals, crowdsaleNum, isCrowdsale) - return getABIEncoded(params.types, params.vals) + return getABIEncoded(web3, params.types, params.vals) } -const getABIEncoded = (types, vals) => { - const { web3 } = web3Store - +const getABIEncoded = (web3, types, vals) => { return new Promise((resolve, reject) => { if (vals) { for (let i = 0; i < vals.length; i++) { From 352dbf15e0ed91a78519d6f37c5678492b6988d5 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 13 Mar 2018 13:22:16 -0300 Subject: [PATCH 4/7] Fix dev environment web3 loading --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9479d16d3..d3de6c2a4 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ if (!process.env['REACT_APP_REGISTRY_ADDRESS']) { } const devEnvironment = process.env.NODE_ENV === 'development'; -if (devEnvironment) { +if (devEnvironment && !window.web3) { window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); } From fa169a660a0d73a30b4a7a07ccbf6e9af94e32d8 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 13 Mar 2018 16:03:45 -0300 Subject: [PATCH 5/7] Move deploy cancellation to its own file --- src/components/IncompleteDeploy.js | 10 ++-------- src/utils/cancelDeploy.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 src/utils/cancelDeploy.js diff --git a/src/components/IncompleteDeploy.js b/src/components/IncompleteDeploy.js index 90110b420..3c0c9cad6 100644 --- a/src/components/IncompleteDeploy.js +++ b/src/components/IncompleteDeploy.js @@ -1,16 +1,10 @@ import React, { Component } from 'react'; import { Link } from 'react-router-dom' -import { cancellingIncompleteDeploy } from '../utils/alerts' +import cancelDeploy from '../utils/cancelDeploy' class CheckIncompleteDeploy extends Component { cancel() { - return cancellingIncompleteDeploy() - .then(result => { - if (result.value) { - localStorage.clear() - window.location.reload() - } - }) + cancelDeploy() } render() { diff --git a/src/utils/cancelDeploy.js b/src/utils/cancelDeploy.js new file mode 100644 index 000000000..3c4601187 --- /dev/null +++ b/src/utils/cancelDeploy.js @@ -0,0 +1,13 @@ +import { cancellingIncompleteDeploy } from './alerts' + +const cancelDeploy = () => { + return cancellingIncompleteDeploy() + .then(result => { + if (result.value) { + localStorage.clear() + window.location = '/' // go to home + } + }) +} + +export default cancelDeploy From 839e952e0ae12fe6e6674d44512b1840b5c6e6a9 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 13 Mar 2018 16:05:46 -0300 Subject: [PATCH 6/7] Add computed variable for deploy in progress --- src/App.js | 2 +- src/stores/DeploymentStore.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index c51aff383..2a7ed578b 100644 --- a/src/App.js +++ b/src/App.js @@ -36,7 +36,7 @@ class App extends Component { { - deploymentStore.deploymentStep !== null ? ( + deploymentStore.deployInProgress ? ( ) : ( diff --git a/src/stores/DeploymentStore.js b/src/stores/DeploymentStore.js index be0ce377d..20d95fdc1 100644 --- a/src/stores/DeploymentStore.js +++ b/src/stores/DeploymentStore.js @@ -105,6 +105,11 @@ class DeploymentStore { if (txStatuses.some(status => !status)) return tx } } + + @computed + get deployInProgress () { + return this.deploymentStep !== null + } } export default DeploymentStore From 8e4dd7847599085380a6ddf7804ac26458070c2c Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 13 Mar 2018 16:46:08 -0300 Subject: [PATCH 7/7] Show warning when switching accounts during deploy --- src/App.js | 2 +- src/components/stepFour/index.js | 56 +++++++++++++++++++++++++++----- src/stores/DeploymentStore.js | 17 ++++++++++ src/stores/index.js | 19 +++++++++++ src/utils/cancelDeploy.js | 2 ++ 5 files changed, 87 insertions(+), 9 deletions(-) diff --git a/src/App.js b/src/App.js index 2a7ed578b..aa9268e5e 100644 --- a/src/App.js +++ b/src/App.js @@ -28,7 +28,7 @@ class App extends Component {
diff --git a/src/components/stepFour/index.js b/src/components/stepFour/index.js index 3d4dad687..a9bfd27d5 100644 --- a/src/components/stepFour/index.js +++ b/src/components/stepFour/index.js @@ -31,6 +31,7 @@ import { isObservableArray } from 'mobx' import JSZip from 'jszip' import executeSequentially from '../../utils/executeSequentially' import { PreventRefresh } from '../Common/PreventRefresh' +import cancelDeploy from '../../utils/cancelDeploy' import PropTypes from 'prop-types' const { PUBLISH } = NAVIGATION_STEPS @@ -38,17 +39,21 @@ const { PUBLISH } = NAVIGATION_STEPS @inject('contractStore', 'reservedTokenStore', 'tierStore', 'tokenStore', 'web3Store', 'deploymentStore') @observer export class stepFour extends React.Component { - constructor (props) { + constructor (props, context) { super(props) this.state = { contractDownloaded: false, modal: false, + preventRefresh: true, transactionFailed: false } + + this.props.deploymentStore.setDeployerAccount(context.selectedAccount) } static contextTypes = { - web3: PropTypes.object + web3: PropTypes.object, + selectedAccount: PropTypes.string } contractDownloadSuccess = options => { @@ -245,6 +250,30 @@ export class stepFour extends React.Component { this.props.history.push(newHistory) } + cancelDeploy = (e) => { + e.preventDefault(); + + this.hideModal(); // hide modal, otherwise the warning doesn't show up + + // avoid the beforeunload alert when user cancels the deploy + this.setState({ + preventRefresh: false + }) + + cancelDeploy() + .then( + (cancelled) => { + if (!cancelled) { + this.setState({ + preventRefresh: true + }) + this.showModal() + } + }, + () => this.showModal() + ) + } + render() { const { tierStore, contractStore, tokenStore, deploymentStore } = this.props const crowdsaleSetups = tierStore.tiers.map((tier, index) => { @@ -397,6 +426,21 @@ export class stepFour extends React.Component { />
) + + const modalContent = deploymentStore.invalidAccount ? ( +
+ This deploy was started with account {deploymentStore.deployerAccount} but the current account is {this.context.selectedAccount}. + Please select the original account to continue with the deploy. + If you don't want to continue with that deploy, click here. +
+ ) : ( + + ) + return (
@@ -497,13 +541,9 @@ export class stepFour extends React.Component { title={'Tx Status'} showModal={this.state.modal} > - + { modalContent } - + { this.state.preventRefresh ? : null }
)} } diff --git a/src/stores/DeploymentStore.js b/src/stores/DeploymentStore.js index 20d95fdc1..6a55794c5 100644 --- a/src/stores/DeploymentStore.js +++ b/src/stores/DeploymentStore.js @@ -5,6 +5,8 @@ class DeploymentStore { @observable txMap = new Map() @observable deploymentStep = null @observable hasEnded = false + @observable deployerAccount = null + @observable invalidAccount = false constructor() { autosave(this, 'DeploymentStore', (store) => { @@ -72,6 +74,21 @@ class DeploymentStore { this.deploymentStep = index } + @action setDeployerAccount = (account) => { + if (!this.deployInProgress) { + this.deployerAccount = account + } + } + + @action handleAccountChange = (account) => { + if (!this.deployerAccount) { + // If there is no deployment in progress, do nothing + return + } + + this.invalidAccount = account !== this.deployerAccount + } + @action resetDeploymentStep = () => { this.deploymentStep = null } diff --git a/src/stores/index.js b/src/stores/index.js index 9b1ebd596..b00133074 100644 --- a/src/stores/index.js +++ b/src/stores/index.js @@ -38,6 +38,25 @@ const crowdsaleStore = new CrowdsaleStore() const gasPriceStore = new GasPriceStore() const deploymentStore = new DeploymentStore() +window.stores = { + generalStore, + crowdsalePageStore, + tierCrowdsaleListStore, + crowdsaleBlockListStore, + contractStore, + pricingStrategyStore, + reservedTokenStore, + stepThreeValidationStore, + stepTwoValidationStore, + tierStore, + tokenStore, + web3Store, + investStore, + crowdsaleStore, + gasPriceStore, + deploymentStore +}; + export { generalStore, crowdsalePageStore, diff --git a/src/utils/cancelDeploy.js b/src/utils/cancelDeploy.js index 3c4601187..917e3dae1 100644 --- a/src/utils/cancelDeploy.js +++ b/src/utils/cancelDeploy.js @@ -7,6 +7,8 @@ const cancelDeploy = () => { localStorage.clear() window.location = '/' // go to home } + + return result.value }) }