Refactoring
This commit is contained in:
parent
b72164f5a8
commit
eb88e99620
|
@ -7,7 +7,7 @@
|
|||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicons/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css?family=Nunito:300,400,700" rel="stylesheet">
|
||||
<title>POA Network Governance DApp</title>
|
||||
<title>POA Governance DApp</title>
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD97qDOBYZ2fH86Wq1vzhDOiSUsZGVqbVQ&libraries=places"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
30
src/App.js
30
src/App.js
|
@ -47,7 +47,6 @@ class App extends Component {
|
|||
swal({
|
||||
title: 'Error',
|
||||
html: messages.NO_METAMASK_MSG,
|
||||
icon: 'error',
|
||||
type: 'error'
|
||||
})
|
||||
} else if (!contractsStore.networkMatch) {
|
||||
|
@ -55,7 +54,6 @@ class App extends Component {
|
|||
swal({
|
||||
title: 'Warning!',
|
||||
html: messages.networkMatchError(contractsStore.netId),
|
||||
icon: 'warning',
|
||||
type: 'warning'
|
||||
})
|
||||
} else if (contractsStore.votingKey && !contractsStore.isValidVotingKey) {
|
||||
|
@ -63,7 +61,6 @@ class App extends Component {
|
|||
swal({
|
||||
title: 'Warning!',
|
||||
html: messages.invalidVotingKeyMsg(contractsStore.votingKey),
|
||||
icon: 'warning',
|
||||
type: 'warning'
|
||||
})
|
||||
}
|
||||
|
@ -76,8 +73,7 @@ class App extends Component {
|
|||
}
|
||||
|
||||
onSearch = e => {
|
||||
const { commonStore } = this.props
|
||||
commonStore.setSearchTerm(e.target.value.toLowerCase())
|
||||
this.setSearchTerm(e.target.value)
|
||||
}
|
||||
|
||||
hideSearch = () => {
|
||||
|
@ -101,6 +97,19 @@ class App extends Component {
|
|||
return 'All'
|
||||
}
|
||||
|
||||
setSearchTerm = term => {
|
||||
const { commonStore } = this.props
|
||||
commonStore.setSearchTerm(term.toLowerCase())
|
||||
if (this.refs.searchBar) {
|
||||
this.refs.searchBar.setSearchTerm(term)
|
||||
}
|
||||
}
|
||||
|
||||
onNetworkChange = e => {
|
||||
this.setSearchTerm('')
|
||||
this.props.onNetworkChange(e)
|
||||
}
|
||||
|
||||
isNewBallotPage() {
|
||||
return `${constants.rootPath}/new` === this.props.location.pathname
|
||||
}
|
||||
|
@ -122,11 +131,18 @@ class App extends Component {
|
|||
baseRootPath={commonStore.rootPath}
|
||||
netId={contractsStore.netId}
|
||||
networkBranch={networkBranch}
|
||||
onChange={this.props.onNetworkChange}
|
||||
onChange={this.onNetworkChange}
|
||||
onMenuToggle={this.toggleMobileMenu}
|
||||
showMobileMenu={this.state.showMobileMenu}
|
||||
/>
|
||||
{this.hideSearch() ? null : <SearchBar networkBranch={networkBranch} onSearch={this.onSearch} />}
|
||||
{this.hideSearch() ? null : (
|
||||
<SearchBar
|
||||
networkBranch={networkBranch}
|
||||
onSearch={this.onSearch}
|
||||
searchTerm={commonStore.searchTerm}
|
||||
ref="searchBar"
|
||||
/>
|
||||
)}
|
||||
<MainTitle text={this.getTitle()} />
|
||||
<section
|
||||
className={`lo-App_Content lo-App_Content-${networkBranch} ${
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
display: none;
|
||||
}
|
||||
}
|
||||
a {
|
||||
button {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
|
@ -85,6 +85,9 @@
|
|||
color: #fff;
|
||||
transition: .15s ease-in;
|
||||
height: 50px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
@media (min-width: $breakpoint-md) {
|
||||
padding: 8px 18px;
|
||||
height: auto;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -44,9 +44,7 @@ export default class NetworkSelect extends Component {
|
|||
}
|
||||
return (
|
||||
<li key={name.toString()} className={className}>
|
||||
<a href="#" onClick={e => this.changeNetworkRPC(e)}>
|
||||
{name}
|
||||
</a>
|
||||
<button onClick={e => this.changeNetworkRPC(e)}>{name}</button>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
import React from 'react'
|
||||
import { inject, observer } from 'mobx-react'
|
||||
|
||||
@inject('commonStore')
|
||||
@observer
|
||||
export class SearchBar extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = { searchTerm: '' }
|
||||
}
|
||||
|
||||
setSearchTerm(searchTerm) {
|
||||
this.setState({ searchTerm })
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { searchTerm } = this.props
|
||||
if (searchTerm !== undefined) {
|
||||
this.setSearchTerm(searchTerm)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { commonStore, networkBranch, onSearch } = this.props
|
||||
const { networkBranch, onSearch } = this.props
|
||||
return (
|
||||
<div className={`sw-SearchBar sw-SearchBar-${networkBranch}`}>
|
||||
<div className="sw-SearchBar_Content">
|
||||
|
@ -14,7 +27,7 @@ export class SearchBar extends React.Component {
|
|||
onChange={onSearch}
|
||||
placeholder="Search..."
|
||||
type="search"
|
||||
value={commonStore.searchTerm}
|
||||
value={this.state.searchTerm}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -49,7 +49,6 @@ class AppMainRouter extends Component {
|
|||
swal({
|
||||
title: 'Error',
|
||||
html: generateElement(error.message),
|
||||
icon: 'error',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
|
@ -106,7 +105,6 @@ class AppMainRouter extends Component {
|
|||
window.localStorage.netId = e.value
|
||||
contractsStore.resetContracts()
|
||||
ballotsStore.reset()
|
||||
commonStore.setSearchTerm('')
|
||||
this.initChain()
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'Kovan Testnet',
|
||||
RPC: 'https://kovan.infura.io/v3/1125fe73d87c4e5396678f4e3089b3dd',
|
||||
BRANCH: constants.KOVAN,
|
||||
TESTNET: true,
|
||||
SORTORDER: 3
|
||||
},
|
||||
'77': {
|
||||
|
@ -70,7 +69,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'Sokol Testnet',
|
||||
RPC: 'https://sokol.poa.network',
|
||||
BRANCH: constants.SOKOL,
|
||||
TESTNET: true,
|
||||
SORTORDER: 4
|
||||
},
|
||||
'99': {
|
||||
|
@ -78,7 +76,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'POA Core',
|
||||
RPC: 'https://core.poa.network',
|
||||
BRANCH: constants.CORE,
|
||||
TESTNET: false,
|
||||
SORTORDER: 1
|
||||
},
|
||||
'100': {
|
||||
|
@ -86,7 +83,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'xDai Stable Chain',
|
||||
RPC: 'https://dai.poa.network',
|
||||
BRANCH: constants.DAI,
|
||||
TESTNET: false,
|
||||
SORTORDER: 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
|||
} catch (e) {
|
||||
throw Error('You have denied access to your accounts')
|
||||
}
|
||||
window.ethereum.autoRefreshOnNetworkChange = true
|
||||
} else if (window.web3) {
|
||||
web3 = new Web3(window.web3.currentProvider)
|
||||
console.log('Injected web3 detected.')
|
||||
|
|
|
@ -48,7 +48,7 @@ messages.wrongRepo = repo => {
|
|||
}
|
||||
messages.networkMatchError = function(netId) {
|
||||
const networkName = getNetworkFullName(Number(netId))
|
||||
return `Networks in DApp and MetaMask do not match. Switch MetaMask to ${networkName} or change the network in DApp.`
|
||||
return `Networks in DApp and MetaMask do not match. Switch MetaMask to <b>${networkName}</b> or change the network in DApp.`
|
||||
}
|
||||
|
||||
export default messages
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
import { constants } from './constants'
|
||||
|
||||
export const isTestnet = netId => {
|
||||
return netId in constants.NETWORKS && constants.NETWORKS[netId].TESTNET
|
||||
}
|
||||
|
||||
export const isValidNetwork = netId => {
|
||||
return netId in constants.NETWORKS
|
||||
}
|
||||
|
||||
export const getNetworkBranch = netId => {
|
||||
return constants.NETWORKS[netId].BRANCH
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue