From c28d30791696854699472a6635d392ff83b71cef Mon Sep 17 00:00:00 2001 From: Vadim Arasev Date: Tue, 2 Oct 2018 14:07:57 +0300 Subject: [PATCH] Show alert on clicking `New Ballot` button if MetaMask is locked --- src/App.js | 23 +++++++++++++++++-- src/Loading.js | 9 ++++---- .../BallotEmissionFundsMetadata.jsx | 2 +- src/components/Footer.jsx | 3 ++- src/components/Header.jsx | 3 ++- src/constants.js | 4 ++++ src/contracts/addresses.js | 11 +++++---- src/contracts/helpers.js | 8 +++---- src/getWeb3.js | 9 ++++---- src/index.js | 3 ++- 10 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/App.js b/src/App.js index 9314590..1472081 100644 --- a/src/App.js +++ b/src/App.js @@ -5,6 +5,9 @@ import React, { Component } from 'react' import { Header, Ballots, NewBallot, Settings, Footer } from './components' import { Route } from 'react-router-dom' import { inject, observer } from 'mobx-react' +import swal from 'sweetalert2' +import { messages } from './messages' +import { constants } from './constants' @inject('commonStore', 'contractsStore') @observer @@ -64,6 +67,18 @@ class App extends Component { } onNewBallotRender = () => { + const { commonStore, contractsStore } = this.props + if (!contractsStore.web3Instance) { + if (!commonStore.loading) { + swal({ + title: 'Error', + html: messages.NO_METAMASK_MSG, + icon: 'error', + type: 'error' + }) + } + return null + } return } @@ -111,7 +126,8 @@ class App extends Component { getNetIdClass() { const { contractsStore } = this.props const netId = contractsStore.netId - return netId === '77' || netId === '79' ? 'sokol' : '' + const isTestnet = netId === constants.NETID_SOKOL || netId === constants.NETID_DAI_TEST + return isTestnet ? 'sokol' : '' } render() { @@ -128,6 +144,9 @@ class App extends Component { '' ) + const netId = contractsStore.netId + const isTestnet = netId === constants.NETID_SOKOL || netId === constants.NETID_DAI_TEST + return (
{loading} @@ -141,7 +160,7 @@ class App extends Component { {search}
diff --git a/src/Loading.js b/src/Loading.js index 02d11be..11ea1c1 100644 --- a/src/Loading.js +++ b/src/Loading.js @@ -1,4 +1,5 @@ import React from 'react' +import { constants } from './constants' const styles = netId => { const core = { @@ -9,11 +10,11 @@ const styles = netId => { } switch (netId) { - case '77': - case '79': + case constants.NETID_SOKOL: + case constants.NETID_DAI_TEST: return sokol - case '99': - case '100': + case constants.NETID_CORE: + case constants.NETID_DAI: return core default: return {} diff --git a/src/components/BallotEmissionFundsMetadata.jsx b/src/components/BallotEmissionFundsMetadata.jsx index dabe3c1..163e512 100644 --- a/src/components/BallotEmissionFundsMetadata.jsx +++ b/src/components/BallotEmissionFundsMetadata.jsx @@ -82,7 +82,7 @@ export class BallotEmissionFundsMetadata extends React.Component { } else if (this.noActiveBallotExists !== true) { note =

To be able to create a new ballot, the previous ballot of this type must be finalized.

} - if (contractsStore.netId === '77') { + if (contractsStore.netId === constants.NETID_SOKOL) { explorerLink = `https://sokol.poaexplorer.com/address/search/${contractsStore.emissionFunds.address}` } else { explorerLink = `https://poaexplorer.com/address/${contractsStore.emissionFunds.address}` diff --git a/src/components/Footer.jsx b/src/components/Footer.jsx index 9324354..577f2c7 100644 --- a/src/components/Footer.jsx +++ b/src/components/Footer.jsx @@ -2,9 +2,10 @@ import React from 'react' import moment from 'moment' import { Link } from 'react-router-dom' import Socials from './Socials.jsx' +import { constants } from '../constants' export const Footer = ({ netId }) => { - const isTestnet = netId === '77' || netId === '79' + const isTestnet = netId === constants.NETID_SOKOL || netId === constants.NETID_DAI_TEST const footerClassName = isTestnet ? 'sokol' : '' return ( diff --git a/src/components/Header.jsx b/src/components/Header.jsx index 0804a28..1f52dd0 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -7,9 +7,10 @@ import menuOpenIconBase from '../assets/images/icons/icon-close.svg' import menuOpenIconSokol from '../assets/images/icons/icon-close-sokol.svg' import NavigationLinks from './NavigationLinks.jsx' import MobileMenuLinks from './MobileMenuLinks.jsx' +import { constants } from '../constants' export const Header = ({ netId, baseRootPath, navigationData, showMobileMenu, onMenuToggle }) => { - const isTestnet = netId === '77' || netId === '79' + const isTestnet = netId === constants.NETID_SOKOL || netId === constants.NETID_DAI_TEST const headerClassName = isTestnet ? 'sokol' : '' const logoImageName = isTestnet ? logoSokol : logoBase const menuIcon = isTestnet ? menuIconSokol : menuIconBase diff --git a/src/constants.js b/src/constants.js index 8f7a7b1..56399ff 100644 --- a/src/constants.js +++ b/src/constants.js @@ -24,6 +24,10 @@ constants.minBallotDurationInDays = 2 constants.startTimeOffsetInMinutes = 5 constants.endTimeDefaultInMinutes = 2890 constants.getTransactionReceiptInterval = 5000 +constants.NETID_SOKOL = '77' +constants.NETID_CORE = '99' +constants.NETID_DAI_TEST = '79' +constants.NETID_DAI = '100' module.exports = { constants } diff --git a/src/contracts/addresses.js b/src/contracts/addresses.js index 288dfc6..8ecbe66 100644 --- a/src/contracts/addresses.js +++ b/src/contracts/addresses.js @@ -1,3 +1,4 @@ +import { constants } from '../constants' import { addressesURL, wrongRepoAlert } from './helpers' // const local = { // VOTING_TO_CHANGE_KEYS_ADDRESS: '0xecdbe3937cf6ff27f70480855cfe03254f915b48', @@ -45,13 +46,13 @@ async function getContractsAddresses(branch) { function getAddresses(netId) { switch (netId) { - case '77': + case constants.NETID_SOKOL: return SOKOL_ADDRESSES - case '79': + case constants.NETID_DAI_TEST: return DAI_TEST_ADDRESSES - case '99': + case constants.NETID_CORE: return CORE_ADDRESSES - case '100': + case constants.NETID_DAI: return DAI_ADDRESSES default: return CORE_ADDRESSES @@ -59,6 +60,6 @@ function getAddresses(netId) { } module.exports = { - getContractsAddresses: getContractsAddresses, + getContractsAddresses, networkAddresses: getAddresses } diff --git a/src/contracts/helpers.js b/src/contracts/helpers.js index 5fd7423..8900b41 100644 --- a/src/contracts/helpers.js +++ b/src/contracts/helpers.js @@ -29,13 +29,13 @@ function wrongRepoAlert(addr) { function getBranch(netId) { switch (netId) { - case '77': + case constants.NETID_SOKOL: return 'sokol' - case '79': + case constants.NETID_DAI_TEST: return 'dai-test' - case '99': + case constants.NETID_CORE: return 'core' - case '100': + case constants.NETID_DAI: return 'dai' default: return 'core' diff --git a/src/getWeb3.js b/src/getWeb3.js index 718ec4a..b84c67d 100644 --- a/src/getWeb3.js +++ b/src/getWeb3.js @@ -1,4 +1,5 @@ import { messages } from './messages' +import { constants } from './constants' let getWeb3 = () => { return new Promise((resolve, reject) => { @@ -16,19 +17,19 @@ let getWeb3 = () => { let netIdName console.log('netId', netId) switch (netId) { - case '100': + case constants.NETID_DAI: netIdName = 'Dai' console.log('This is Dai', netId) break - case '99': + case constants.NETID_CORE: netIdName = 'Core' console.log('This is Core', netId) break - case '79': + case constants.NETID_DAI_TEST: netIdName = 'Dai-Test' console.log('This is Dai-Test', netId) break - case '77': + case constants.NETID_SOKOL: netIdName = 'Sokol' console.log('This is Sokol', netId) break diff --git a/src/index.js b/src/index.js index 55b18e2..9a8ebf3 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ import swal from 'sweetalert2' import getWeb3 from './getWeb3' import 'babel-polyfill' import createBrowserHistory from 'history/createBrowserHistory' +import { constants } from './constants' const browserHistory = createBrowserHistory() const routingStore = new RouterStore() @@ -60,7 +61,7 @@ class AppMainRouter extends Component { setValidatorMetadata ] - if (web3Config.netId === '77') { + if (web3Config.netId === constants.NETID_SOKOL) { // if we're in Sokol promises.push(contractsStore.setEmissionFunds(web3Config)) promises.push(contractsStore.setVotingToManageEmissionFunds(web3Config))