Merge pull request #157 from poanetwork/prettier-config

(Refactor) Prettier config was added
This commit is contained in:
Vadim Arasev 2018-07-17 15:36:36 +03:00
parent 7eaaa67081
commit 4f001fe53c
36 changed files with 4879 additions and 4698 deletions

View File

@ -1,15 +1,26 @@
{
"extends": "react-app",
"rules": {
"no-unused-vars": "error",
"no-trailing-spaces": "error",
"no-mixed-spaces-and-tabs": "error",
"no-whitespace-before-property": "error",
"comma-spacing": "error",
"brace-style": "error",
"func-names": "error",
"no-duplicate-imports": "error",
"no-dupe-class-members": "error",
"arrow-spacing": "error"
}
"extends": [
"react-app",
"plugin:prettier/recommended"
],
"plugins": [
"dependencies"
],
"rules": {
"no-control-regex": 0,
"dependencies/no-cycles": "error",
"dependencies/no-unresolved": ["error", {
"ignore": ["web3"]
}]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx"
]
}
}
}
}

8
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,8 @@
- (Mandatory) Description
a human-readable description of changes
a human-readable description of the purpose of the PR
- (Mandatory) What is it: (Fix), (Feature), or (Refactor) in Title, e.g., "(Fix) price of 1 token in Wei > 18 decimals"
- (Mandatory) Developers: Each completed PR should be updated in the Wiki Documentation.
(Recommended) Each PR should have one commit message and therefore should only contain one specific fix or feature. Otherwise, multiple PRs should be made
- Did you check that your PR is chain agnostic? It shouldn't depend on any hardcoded chainIds, URLs.
- (Optional) Any additional concerns or comments

2
.nvmrc
View File

@ -1 +1 @@
v8.3.0
v8.11.3

5
.prettierignore Normal file
View File

@ -0,0 +1,5 @@
assets
config
public
scripts
*.js

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120
}

7011
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,10 @@
"chalk": "2.4.1",
"css-loader": "0.28.11",
"dotenv": "4.0.0",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "1.9.0",
"eslint-plugin-dependencies": "^2.4.0",
"eslint-plugin-prettier": "^2.6.2",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.5",
"fs-extra": "3.0.1",
@ -38,6 +41,7 @@
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.8",
"prettier": "^1.13.7",
"promise": "8.0.1",
"raf": "3.4.0",
"randomhex": "^0.1.5",
@ -66,7 +70,8 @@
"start": "npm-run-all -p watch-css start-js",
"build-js": "node scripts/build.js",
"build": "npm-run-all build-css build-js",
"test": "node scripts/test.js --env=jsdom"
"test": "node scripts/test.js --env=jsdom",
"lint": "./node_modules/.bin/eslint src"
},
"jest": {
"collectCoverageFrom": [
@ -108,7 +113,30 @@
]
},
"eslintConfig": {
"extends": "react-app"
"extends": [
"react-app",
"plugin:prettier/recommended"
],
"plugins": [
"dependencies"
],
"rules": {
"no-control-regex": 0,
"dependencies/no-cycles": "error",
"dependencies/no-unresolved": ["error", {
"ignore": ["web3"]
}]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx"
]
}
}
}
},
"devDependencies": {
"babel-eslint": "^7.2.3",

View File

@ -1,79 +1,87 @@
import React, { Component } from 'react';
import { Route, NavLink } from 'react-router-dom';
import { Header, Ballots, NewBallot, Settings, Footer } from './components';
import './assets/App.css';
import React, { Component } from 'react'
import { Route, NavLink } from 'react-router-dom'
import { Header, Ballots, NewBallot, Settings, Footer } from './components'
import './assets/App.css'
//import DevTools from 'mobx-react-devtools'
import Loading from './Loading';
import { inject, observer } from 'mobx-react';
import Loading from './Loading'
import { inject, observer } from 'mobx-react'
@inject("commonStore", "contractsStore")
@inject('commonStore', 'contractsStore')
@observer
class App extends Component {
onBallotsRender = () => {
return <Ballots isActiveFilter={false}/>;
return <Ballots isActiveFilter={false} />
}
onActiveBallotsRender = () => {
return <Ballots isActiveFilter={true}/>;
return <Ballots isActiveFilter={true} />
}
onToFinalizeBallotsRender = () => {
return <Ballots isToFinalizeFilter={true}/>;
return <Ballots isToFinalizeFilter={true} />
}
onNewBallotRender = () => {
return <NewBallot/>;
return <NewBallot />
}
onSettingsRender = () => {
return <Settings/>;
return <Settings />
}
onSearch = (e) => {
const { commonStore } = this.props;
commonStore.setSearchTerm(e.target.value.toLowerCase());
onSearch = e => {
const { commonStore } = this.props
commonStore.setSearchTerm(e.target.value.toLowerCase())
}
shouldShowNavPan = () => {
const { commonStore } = this.props;
const currentPath = this.props.location.pathname;
const { commonStore } = this.props
const currentPath = this.props.location.pathname
let showNavPan =
currentPath === `${commonStore.rootPath}`
|| currentPath === "/"
|| currentPath === `${commonStore.rootPath}/`
|| currentPath === `${commonStore.rootPath}/active`
|| currentPath === `${commonStore.rootPath}/tofinalize`;
return showNavPan;
currentPath === `${commonStore.rootPath}` ||
currentPath === '/' ||
currentPath === `${commonStore.rootPath}/` ||
currentPath === `${commonStore.rootPath}/active` ||
currentPath === `${commonStore.rootPath}/tofinalize`
return showNavPan
}
render() {
const { commonStore, contractsStore } = this.props;
const { commonStore, contractsStore } = this.props
const loading = commonStore.loading ? <Loading netId={contractsStore.netId} /> : ''
const nav = this.shouldShowNavPan() ? <div className="search">
<div className="container flex-container">
<div className="nav">
<NavLink className="nav-i" exact activeClassName="nav-i_active" to={`${commonStore.rootPath}/`}>All</NavLink>
<NavLink className="nav-i" activeClassName="nav-i_active" to={`${commonStore.rootPath}/active`}>Active</NavLink>
<NavLink className="nav-i" activeClassName="nav-i_active" to={`${commonStore.rootPath}/tofinalize`}>To finalize</NavLink>
const nav = this.shouldShowNavPan() ? (
<div className="search">
<div className="container flex-container">
<div className="nav">
<NavLink className="nav-i" exact activeClassName="nav-i_active" to={`${commonStore.rootPath}/`}>
All
</NavLink>
<NavLink className="nav-i" activeClassName="nav-i_active" to={`${commonStore.rootPath}/active`}>
Active
</NavLink>
<NavLink className="nav-i" activeClassName="nav-i_active" to={`${commonStore.rootPath}/tofinalize`}>
To finalize
</NavLink>
</div>
<input type="search" className="search-input" onChange={this.onSearch} />
</div>
<input type="search" className="search-input" onChange={this.onSearch}/>
</div>
</div> : null;
) : null
return (
<div>
{loading}
<Header netId={contractsStore.netId} />
{nav}
<Route exact path={`/`} render={this.onBallotsRender}/>
<Route exact path={`${commonStore.rootPath}/`} render={this.onBallotsRender}/>
<Route exact path={`${commonStore.rootPath}/active`} render={this.onActiveBallotsRender}/>
<Route exact path={`${commonStore.rootPath}/tofinalize`} render={this.onToFinalizeBallotsRender}/>
<Route path={`${commonStore.rootPath}/new`} render={this.onNewBallotRender}/>
<Route exact path={`/`} render={this.onBallotsRender} />
<Route exact path={`${commonStore.rootPath}/`} render={this.onBallotsRender} />
<Route exact path={`${commonStore.rootPath}/active`} render={this.onActiveBallotsRender} />
<Route exact path={`${commonStore.rootPath}/tofinalize`} render={this.onToFinalizeBallotsRender} />
<Route path={`${commonStore.rootPath}/new`} render={this.onNewBallotRender} />
{/*<Route path={`${commonStore.rootPath}/settings`} render={this.onSettingsRender}/>*/}
<Footer netId={contractsStore.netId} />
</div>
);
)
}
}
export default App;
export default App

View File

@ -1,30 +1,30 @@
import React from 'react';
const styles = (netId) => {
import React from 'react'
const styles = netId => {
const core = {
backgroundColor: 'rgba(35, 29, 115, 0.8)'
};
}
const sokol = {
backgroundColor: 'rgba(47, 109, 99, 0.8)'
}
switch(netId) {
switch (netId) {
case '77':
return sokol;
return sokol
case '99':
return core;
return core
default:
return {};
return {}
}
}
const Loading = ({netId}) => (
const Loading = ({ netId }) => (
<div className="loading-container" style={styles(netId)}>
<div className="loading">
<div className="loading-i"></div>
<div className="loading-i"></div>
<div className="loading-i"></div>
<div className="loading-i"></div>
<div className="loading-i"></div>
<div className="loading-i"></div>
<div className="loading-i" />
<div className="loading-i" />
<div className="loading-i" />
<div className="loading-i" />
<div className="loading-i" />
<div className="loading-i" />
</div>
</div>
)
export default Loading;
export default Loading

View File

@ -1,35 +1,37 @@
import React from "react";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
import React from 'react'
import { inject, observer } from 'mobx-react'
import { BallotCard } from './BallotCard.jsx'
@inject("commonStore", "routing")
@inject('commonStore', 'routing')
@observer
export class BallotKeysCard extends React.Component {
render () {
let { id, votingState, pos } = this.props;
render() {
let { id, votingState, pos } = this.props
let affectedKeyClassName;
let affectedKey = <p>{votingState.affectedKey}</p>;
let newVotingKey;
let newPayoutKey;
let miningKeyDiv;
let affectedKeyClassName
let affectedKey = <p>{votingState.affectedKey}</p>
let newVotingKey
let newPayoutKey
let miningKeyDiv
if (votingState.isAddMining) {
affectedKeyClassName = 'ballots-about-i_key_wide';
affectedKeyClassName = 'ballots-about-i_key_wide'
if (votingState.newVotingKey || votingState.newPayoutKey) {
affectedKey = <p>Mining: {votingState.affectedKey}</p>;
if (votingState.newVotingKey) newVotingKey = <p>Voting: {votingState.newVotingKey}</p>;
if (votingState.newPayoutKey) newPayoutKey = <p>Payout: {votingState.newPayoutKey}</p>;
affectedKey = <p>Mining: {votingState.affectedKey}</p>
if (votingState.newVotingKey) newVotingKey = <p>Voting: {votingState.newVotingKey}</p>
if (votingState.newPayoutKey) newPayoutKey = <p>Payout: {votingState.newPayoutKey}</p>
}
} else {
affectedKeyClassName = 'ballots-about-i_key';
miningKeyDiv = <div className="ballots-about-i ballots-about-i_key">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Validator key</p>
affectedKeyClassName = 'ballots-about-i_key'
miningKeyDiv = (
<div className="ballots-about-i ballots-about-i_key">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Validator key</p>
</div>
<div className="ballots-about-td">
<p>{votingState.miningKey}</p>
</div>
</div>
<div className="ballots-about-td">
<p>{votingState.miningKey}</p>
</div>
</div>;
)
}
return (
@ -62,6 +64,6 @@ export class BallotKeysCard extends React.Component {
</div>
{miningKeyDiv}
</BallotCard>
);
)
}
}

View File

@ -1,47 +1,57 @@
import React from "react";
import { inject, observer } from "mobx-react";
import Select from "react-select";
import "react-select/dist/react-select.css";
import React from 'react'
import { inject, observer } from 'mobx-react'
import Select from 'react-select'
import 'react-select/dist/react-select.css'
@inject("ballotStore", "contractsStore")
@inject('ballotStore', 'contractsStore')
@observer
export class BallotKeysMetadata extends React.Component {
render() {
const { ballotStore, contractsStore } = this.props;
let options = [];
const { ballotStore, contractsStore } = this.props
let options = []
for (var key in contractsStore.validatorsMetadata) {
if (contractsStore.validatorsMetadata.hasOwnProperty(key)) {
options.push(contractsStore.validatorsMetadata[key]);
options.push(contractsStore.validatorsMetadata[key])
}
}
let newVotingPayoutKeys = '';
if (ballotStore.isNewValidatorPersonalData && contractsStore.votingToChangeKeys && contractsStore.votingToChangeKeys.doesMethodExist('createBallotToAddNewValidator')) {
newVotingPayoutKeys = <div>
<div className="left">
<div className="form-el">
<label htmlFor="new-voting-key">New Voting Key</label>
<input type="text" id="new-voting-key"
value={ballotStore.ballotKeys.newVotingKey}
onChange={e => ballotStore.changeBallotMetadata(e, "newVotingKey", "ballotKeys")}
/>
<p className="hint">
Voting key address of new validator.<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
</p>
let newVotingPayoutKeys = ''
if (
ballotStore.isNewValidatorPersonalData &&
contractsStore.votingToChangeKeys &&
contractsStore.votingToChangeKeys.doesMethodExist('createBallotToAddNewValidator')
) {
newVotingPayoutKeys = (
<div>
<div className="left">
<div className="form-el">
<label htmlFor="new-voting-key">New Voting Key</label>
<input
type="text"
id="new-voting-key"
value={ballotStore.ballotKeys.newVotingKey}
onChange={e => ballotStore.changeBallotMetadata(e, 'newVotingKey', 'ballotKeys')}
/>
<p className="hint">
Voting key address of new validator.<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="new-payout-key">New Payout Key</label>
<input
type="text"
id="new-payout-key"
value={ballotStore.ballotKeys.newPayoutKey}
onChange={e => ballotStore.changeBallotMetadata(e, 'newPayoutKey', 'ballotKeys')}
/>
<p className="hint">
Payout key address of new validator.<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
</p>
</div>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="new-payout-key">New Payout Key</label>
<input type="text" id="new-payout-key"
value={ballotStore.ballotKeys.newPayoutKey}
onChange={e => ballotStore.changeBallotMetadata(e, "newPayoutKey", "ballotKeys")}
/>
<p className="hint">
Payout key address of new validator.<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
</p>
</div>
</div>
</div>;
)
}
return (
<div>
@ -49,12 +59,17 @@ export class BallotKeysMetadata extends React.Component {
<div className="left">
<div className="form-el">
<label htmlFor="key">{ballotStore.isNewValidatorPersonalData ? 'New Mining Key' : 'Affected Key'}</label>
<input type="text" id="key"
<input
type="text"
id="key"
value={ballotStore.ballotKeys.affectedKey}
onChange={e => ballotStore.changeBallotMetadata(e, "affectedKey", "ballotKeys")}
onChange={e => ballotStore.changeBallotMetadata(e, 'affectedKey', 'ballotKeys')}
/>
<p className="hint">
{ballotStore.isNewValidatorPersonalData ? 'Mining key address of new validator.' : 'Affected key address of validator to vote for.'}<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
{ballotStore.isNewValidatorPersonalData
? 'Mining key address of new validator.'
: 'Affected key address of validator to vote for.'}
<br />Example: 0xc70760D23557A4FDE612C0bE63b26EBD023C51Ee.
</p>
</div>
</div>
@ -78,19 +93,19 @@ export class BallotKeysMetadata extends React.Component {
<div className="left">
<div className="form-el">
<label htmlFor="datetime-local">Ballot End</label>
<input type="datetime-local" id="datetime-local"
<input
type="datetime-local"
id="datetime-local"
value={ballotStore.endTime}
min={ballotStore.endTime}
onChange={e => ballotStore.changeBallotMetadata(e, "endTime")}
onChange={e => ballotStore.changeBallotMetadata(e, 'endTime')}
/>
<p className="hint">
Ballot's end time.
</p>
<p className="hint">Ballot's end time.</p>
</div>
</div>
</div>
<hr />
</div>
);
)
}
}

View File

@ -1,12 +1,12 @@
import React from "react";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
import React from 'react'
import { inject, observer } from 'mobx-react'
import { BallotCard } from './BallotCard.jsx'
@inject("commonStore", "routing")
@inject('commonStore', 'routing')
@observer
export class BallotMinThresholdCard extends React.Component {
render () {
let { id, votingState, pos } = this.props;
render() {
let { id, votingState, pos } = this.props
return (
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_proposed-min-threshold">
@ -18,6 +18,6 @@ export class BallotMinThresholdCard extends React.Component {
</div>
</div>
</BallotCard>
);
)
}
}

View File

@ -1,41 +1,41 @@
import React from 'react';
import { inject, observer } from "mobx-react";
import React from 'react'
import { inject, observer } from 'mobx-react'
@inject("ballotStore")
@inject('ballotStore')
@observer
export class BallotMinThresholdMetadata extends React.Component {
render() {
const { ballotStore } = this.props;
const { ballotStore } = this.props
return (
<div>
<div className="hidden">
<div className="left">
<div className="form-el">
<label htmlFor="key">Proposed Value</label>
<input type="number" id="key"
<input
type="number"
id="key"
value={ballotStore.ballotMinThreshold.proposedValue}
onChange={e => ballotStore.changeBallotMetadata(e, "proposedValue", "ballotMinThreshold")}
onChange={e => ballotStore.changeBallotMetadata(e, 'proposedValue', 'ballotMinThreshold')}
/>
<p className="hint">
Proposed value of the minimum threshold for keys ballot consensus.
</p>
<p className="hint">Proposed value of the minimum threshold for keys ballot consensus.</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="datetime-local">Ballot End</label>
<input type="datetime-local" id="datetime-local"
<input
type="datetime-local"
id="datetime-local"
value={ballotStore.endTime}
onChange={e => ballotStore.changeBallotMetadata(e, "endTime")}
onChange={e => ballotStore.changeBallotMetadata(e, 'endTime')}
/>
<p className="hint">
Ballot's end time.
</p>
<p className="hint">Ballot's end time.</p>
</div>
</div>
</div>
<hr />
</div>
);
)
}
}

View File

@ -1,31 +1,31 @@
import React from "react";
import { inject, observer } from "mobx-react";
import { BallotCard } from "./BallotCard";
import React from 'react'
import { inject, observer } from 'mobx-react'
import { BallotCard } from './BallotCard.jsx'
@inject("commonStore", "ballotStore", "routing")
@inject('commonStore', 'ballotStore', 'routing')
@observer
export class BallotProxyCard extends React.Component {
render () {
const { id, votingState, pos } = this.props;
render() {
const { id, votingState, pos } = this.props
return (
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_contract-type">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Contract type</p>
</div>
<div className="ballots-about-td">
<p>{votingState.contractTypeDisplayName}</p>
</div>
<div className="ballots-about-td">
<p className="ballots-about-i--title">Contract type</p>
</div>
<div className="ballots-about-i ballots-about-i_proposed-address">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Proposed contract address</p>
</div>
<div className="ballots-about-td">
<p>{votingState.proposedValue}</p>
</div>
<div className="ballots-about-td">
<p>{votingState.contractTypeDisplayName}</p>
</div>
</div>
<div className="ballots-about-i ballots-about-i_proposed-address">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Proposed contract address</p>
</div>
<div className="ballots-about-td">
<p>{votingState.proposedValue}</p>
</div>
</div>
</BallotCard>
);
)
}
}

View File

@ -1,12 +1,12 @@
import React from 'react';
import { inject, observer } from "mobx-react";
import Select from 'react-select';
import React from 'react'
import { inject, observer } from 'mobx-react'
import Select from 'react-select'
@inject("ballotStore", "contractsStore")
@inject('ballotStore', 'contractsStore')
@observer
export class BallotProxyMetadata extends React.Component {
render() {
const { ballotStore, contractsStore } = this.props;
const { ballotStore, contractsStore } = this.props
let options = [
/*0*/ { value: '', label: '' },
/*1*/ { value: '1', label: ballotStore.ProxyBallotType[1] }, // KeysManager
@ -15,11 +15,11 @@ export class BallotProxyMetadata extends React.Component {
/*4*/ { value: '4', label: ballotStore.ProxyBallotType[4] }, // VotingToChangeProxy
/*5*/ { value: '5', label: ballotStore.ProxyBallotType[5] }, // BallotsStorage
/*6*/ { value: '7', label: ballotStore.ProxyBallotType[7] }, // ValidatorMetadata
/*7*/ { value: '8', label: ballotStore.ProxyBallotType[8] }, // ProxyStorage
];
/*7*/ { value: '8', label: ballotStore.ProxyBallotType[8] } // ProxyStorage
]
if (!contractsStore.proxyStorage || !contractsStore.proxyStorage.doesMethodExist('getValidatorMetadata')) {
options.splice(6); // keep 0-5 and remove 6-... items if ProxyStorage is old
options.splice(6) // keep 0-5 and remove 6-... items if ProxyStorage is old
}
return (
@ -28,44 +28,42 @@ export class BallotProxyMetadata extends React.Component {
<div className="left">
<div className="form-el">
<label htmlFor="key">Proposed Address</label>
<input type="text" id="key"
<input
type="text"
id="key"
value={ballotStore.ballotProxy.proposedAddress}
onChange={e => ballotStore.changeBallotMetadata(e, "proposedAddress", "ballotProxy")}
onChange={e => ballotStore.changeBallotMetadata(e, 'proposedAddress', 'ballotProxy')}
/>
<p className="hint">
Proposed address of a new proxy contract.
</p>
<p className="hint">Proposed address of a new proxy contract.</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="contract-type">Contract Type</label>
<Select id="contract-type"
<Select
id="contract-type"
value={ballotStore.ballotProxy.contractType}
onChange={e => ballotStore.changeBallotMetadata(e, "contractType", "ballotProxy")}
onChange={e => ballotStore.changeBallotMetadata(e, 'contractType', 'ballotProxy')}
options={options}
>
</Select>
<p className="hint">
Choose proxy contract type.
</p>
/>
<p className="hint">Choose proxy contract type.</p>
</div>
</div>
<div className="left">
<div className="form-el">
<label htmlFor="datetime-local">Ballot End</label>
<input type="datetime-local" id="datetime-local"
<input
type="datetime-local"
id="datetime-local"
value={ballotStore.endTime}
onChange={e => ballotStore.changeBallotMetadata(e, "endTime")}
onChange={e => ballotStore.changeBallotMetadata(e, 'endTime')}
/>
<p className="hint">
Ballot's end time.
</p>
<p className="hint">Ballot's end time.</p>
</div>
</div>
</div>
<hr />
</div>
);
)
}
}

View File

@ -1,102 +1,154 @@
import React from 'react';
import { observable } from "mobx";
import { inject, observer } from "mobx-react";
import "babel-polyfill";
import React from 'react'
import { observable } from 'mobx'
import { inject, observer } from 'mobx-react'
import 'babel-polyfill'
@inject("commonStore", "ballotsStore", "ballotStore", "contractsStore")
@inject('commonStore', 'ballotsStore', 'ballotStore', 'contractsStore')
@observer
export class Ballots extends React.Component {
@observable limit;
@observable limit
constructor(props) {
super(props);
this.limit = this.props.commonStore.loadMoreLimit;
this.step = this.limit;
this.onClick = this.onClick.bind(this);
super(props)
this.limit = this.props.commonStore.loadMoreLimit
this.step = this.limit
this.onClick = this.onClick.bind(this)
}
onClick = async () => {
const { commonStore } = this.props;
this.limit += this.step;
commonStore.loadMoreLimit = this.limit;
const { commonStore } = this.props
this.limit += this.step
commonStore.loadMoreLimit = this.limit
}
filterBySearchTerm = (searchTerm, ballotCards) => {
const { ballotStore } = this.props;
searchTerm = searchTerm.toLowerCase();
const { ballotStore } = this.props
searchTerm = searchTerm.toLowerCase()
for (let i = 0; i < ballotCards.length; i++) {
const votingState = ballotCards[i].props.votingState;
const contractType = ballotCards[i].props.type;
const votingState = ballotCards[i].props.votingState
const contractType = ballotCards[i].props.type
if (String(votingState.creator).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.creator)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.creatorMiningKey).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.creatorMiningKey)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.memo).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.memo)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (contractType === ballotStore.BallotType.keys) {
if (String(votingState.miningKey).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.miningKey)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.affectedKey).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.affectedKey)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.newVotingKey).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.newVotingKey)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.newPayoutKey).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.newPayoutKey)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.affectedKeyTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.affectedKeyTypeDisplayName)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.ballotTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.ballotTypeDisplayName)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
} else if (contractType === ballotStore.BallotType.minThreshold) {
if (String(votingState.proposedValue).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.proposedValue)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
} else if (contractType === ballotStore.BallotType.proxy) {
if (String(votingState.proposedValue).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.proposedValue)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
if (String(votingState.contractTypeDisplayName).toLowerCase().includes(searchTerm)) {
continue;
if (
String(votingState.contractTypeDisplayName)
.toLowerCase()
.includes(searchTerm)
) {
continue
}
}
ballotCards.splice(i--, 1);
ballotCards.splice(i--, 1)
}
return ballotCards;
return ballotCards
}
componentWillMount () {
const { commonStore } = this.props;
commonStore.isActiveFilter = this.props.isActiveFilter;
commonStore.isToFinalizeFilter = this.props.isToFinalizeFilter;
componentWillMount() {
const { commonStore } = this.props
commonStore.isActiveFilter = this.props.isActiveFilter
commonStore.isToFinalizeFilter = this.props.isToFinalizeFilter
}
render () {
const { ballotsStore, commonStore } = this.props;
render() {
const { ballotsStore, commonStore } = this.props
let ballotCards = ballotsStore.ballotCards.toJS().sort((a, b) => {
return b.props.votingState.startTime - a.props.votingState.startTime;
});
return b.props.votingState.startTime - a.props.votingState.startTime
})
if (commonStore.searchTerm) {
ballotCards = this.filterBySearchTerm(commonStore.searchTerm, ballotCards);
ballotCards = this.filterBySearchTerm(commonStore.searchTerm, ballotCards)
}
let loadMoreButton;
let loadMoreButton
if (ballotCards.length > this.limit && !commonStore.isActiveFilter && !commonStore.isToFinalizeFilter) {
loadMoreButton = <div className="center">
<button type="button" className="load-more" onClick={e => this.onClick(e)}>&darr; LOAD MORE BALLOTS &darr;</button>
</div>;
ballotCards.splice(this.limit);
loadMoreButton = (
<div className="center">
<button type="button" className="load-more" onClick={e => this.onClick(e)}>
&darr; LOAD MORE BALLOTS &darr;
</button>
</div>
)
ballotCards.splice(this.limit)
}
return (
<section className="container ballots">
@ -104,6 +156,6 @@ export class Ballots extends React.Component {
{ballotCards}
{loadMoreButton}
</section>
);
)
}
}

View File

@ -1,21 +1,21 @@
import React from "react";
import moment from "moment";
import { Link } from "react-router-dom";
import React from 'react'
import moment from 'moment'
import { Link } from 'react-router-dom'
export const Footer = ({netId}) => {
const footerClassName = netId === '77' ? 'sokol' : '';
export const Footer = ({ netId }) => {
const footerClassName = netId === '77' ? 'sokol' : ''
return (
<footer className={`footer ${footerClassName}`}>
<div className="container">
<p className="footer-rights">{moment().format("YYYY")} POA Network. All rights reserved.</p>
<Link to="/poa-dapps-voting" className="footer-logo"></Link>
<p className="footer-rights">{moment().format('YYYY')} POA Network. All rights reserved.</p>
<Link to="/poa-dapps-voting" className="footer-logo" />
<div className="socials">
<a href="https://twitter.com/poanetwork" className="socials-i socials-i_twitter"></a>
<a href="https://poa.network" className="socials-i socials-i_oracles"></a>
<a href="https://t.me/oraclesnetwork" className="socials-i socials-i_telegram"></a>
<a href="https://github.com/poanetwork/" className="socials-i socials-i_github"></a>
<a href="https://twitter.com/poanetwork" className="socials-i socials-i_twitter" />
<a href="https://poa.network" className="socials-i socials-i_oracles" />
<a href="https://t.me/oraclesnetwork" className="socials-i socials-i_telegram" />
<a href="https://github.com/poanetwork/" className="socials-i socials-i_github" />
</div>
</div>
</footer>
);
)
}

View File

@ -1,16 +1,18 @@
import React from 'react';
import { Link } from 'react-router-dom';
import React from 'react'
import { Link } from 'react-router-dom'
export const Header = ({netId}) => {
let headerClassName = netId === '77' ? 'sokol' : '';
const logoClassName = netId === '77' ? 'header-logo-sokol' : 'header-logo';
return(
<header className={`header ${headerClassName}`}>
<div className="container">
<Link to="/poa-dapps-voting" className={logoClassName}></Link>
<Link to="/poa-dapps-voting/new" className="header-new-ballot">New ballot</Link>
{/*<Link to="/poa-dapps-voting/settings" className="header-settings">Settings</Link>*/}
</div>
</header>
)
};
export const Header = ({ netId }) => {
let headerClassName = netId === '77' ? 'sokol' : ''
const logoClassName = netId === '77' ? 'header-logo-sokol' : 'header-logo'
return (
<header className={`header ${headerClassName}`}>
<div className="container">
<Link to="/poa-dapps-voting" className={logoClassName} />
<Link to="/poa-dapps-voting/new" className="header-new-ballot">
New ballot
</Link>
{/*<Link to="/poa-dapps-voting/settings" className="header-settings">Settings</Link>*/}
</div>
</header>
)
}

View File

@ -1,84 +1,102 @@
import React from 'react';
import { inject, observer } from "mobx-react";
import React from 'react'
import { inject, observer } from 'mobx-react'
@inject("ballotStore")
@inject('ballotStore')
@observer
export class KeysTypes extends React.Component {
render() {
const { ballotStore } = this.props;
const { ballotStore } = this.props
return (
<div className="hidden">
<div className="left">
<div className="radio-container">
<input type="radio" name="key-control" id="add-key"
<input
type="radio"
name="key-control"
id="add-key"
value={ballotStore.KeysBallotType.add}
checked={ballotStore.isAddKeysBallotType}
onChange={e => ballotStore.changeKeysBallotType(e, ballotStore.KeysBallotType.add)}
/>
<label htmlFor="add-key" className="radio radio_icon radio_add">Add key</label>
<p className="hint">
Add new key.
</p>
<label htmlFor="add-key" className="radio radio_icon radio_add">
Add key
</label>
<p className="hint">Add new key.</p>
</div>
<div className="radio-container">
<input type="radio" name="key-control" id="remove-key"
<input
type="radio"
name="key-control"
id="remove-key"
value={ballotStore.KeysBallotType.remove}
checked={ballotStore.isRemoveKeysBallotType}
onChange={e => ballotStore.changeKeysBallotType(e, ballotStore.KeysBallotType.remove)}
/>
<label htmlFor="remove-key" className="radio radio_icon radio_remove">Remove key</label>
<p className="hint">
Remove existing key.
</p>
<label htmlFor="remove-key" className="radio radio_icon radio_remove">
Remove key
</label>
<p className="hint">Remove existing key.</p>
</div>
<div className="radio-container">
<input type="radio" name="key-control" id="swap-key"
<input
type="radio"
name="key-control"
id="swap-key"
value={ballotStore.KeysBallotType.swap}
checked={ballotStore.isSwapKeysBallotType}
onChange={e => ballotStore.changeKeysBallotType(e, ballotStore.KeysBallotType.swap)}
/>
<label htmlFor="swap-key" className="radio radio_icon radio_swap">Swap key</label>
<p className="hint">
Remove existing key and add new key.
</p>
<label htmlFor="swap-key" className="radio radio_icon radio_swap">
Swap key
</label>
<p className="hint">Remove existing key and add new key.</p>
</div>
</div>
<div className="right">
<div className="radio-container">
<input type="radio" name="keys" id="mining-key"
<input
type="radio"
name="keys"
id="mining-key"
value={ballotStore.KeyType.mining}
checked={ballotStore.isMiningKeyType}
onChange={e => ballotStore.changeKeyType(e, ballotStore.KeyType.mining)}
/>
<label htmlFor="mining-key" className="radio">Mining Key</label>
<p className="hint">
Mining key type.
</p>
<label htmlFor="mining-key" className="radio">
Mining Key
</label>
<p className="hint">Mining key type.</p>
</div>
<div className="radio-container">
<input type="radio" name="keys" id="payout-key"
<input
type="radio"
name="keys"
id="payout-key"
value={ballotStore.KeyType.payout}
checked={ballotStore.isPayoutKeyType}
onChange={e => ballotStore.changeKeyType(e, ballotStore.KeyType.payout)}
/>
<label htmlFor="payout-key" className="radio">Payout Key</label>
<p className="hint">
Payout key type.
</p>
<label htmlFor="payout-key" className="radio">
Payout Key
</label>
<p className="hint">Payout key type.</p>
</div>
<div className="radio-container">
<input type="radio" name="keys" id="voting-key"
<input
type="radio"
name="keys"
id="voting-key"
value={ballotStore.KeyType.voting}
checked={ballotStore.isVotingKeyType}
onChange={e => ballotStore.changeKeyType(e, ballotStore.KeyType.voting)}
/>
<label htmlFor="voting-key" className="radio">Voting Key</label>
<p className="hint">
Voting key type.
</p>
<label htmlFor="voting-key" className="radio">
Voting Key
</label>
<p className="hint">Voting key type.</p>
</div>
</div>
</div>
);
)
}
}

View File

@ -1,18 +1,20 @@
import React from 'react';
import { inject, observer } from "mobx-react";
import React from 'react'
import { inject, observer } from 'mobx-react'
@inject("contractsStore")
@inject('contractsStore')
@observer
export class Settings extends React.Component {
render () {
const { contractsStore } = this.props;
render() {
const { contractsStore } = this.props
return (
<section className="container">
<div className="settings">
<p className="settings-title">Select Voting Key</p>
<div className="form-el">
<select id="state">
<option value="" default>{contractsStore.votingKey}</option>
<option value="" default>
{contractsStore.votingKey}
</option>
</select>
<div className="hint">
Please select your voting key from the list. You will be able to change it later in Settings menu.
@ -23,6 +25,6 @@ export class Settings extends React.Component {
</div>
</div>
</section>
);
)
}
}

View File

@ -1,73 +1,74 @@
import React from 'react';
import { inject, observer } from "mobx-react";
import Select from 'react-select';
import PlacesAutocomplete, { geocodeByAddress } from 'react-places-autocomplete';
import { constants } from "../constants";
import React from 'react'
import { inject, observer } from 'mobx-react'
import Select from 'react-select'
import PlacesAutocomplete, { geocodeByAddress } from 'react-places-autocomplete'
import { constants } from '../constants'
@inject("validatorStore", "ballotStore")
@inject('validatorStore', 'ballotStore')
@observer
export class Validator extends React.Component {
onSelectAutocomplete = async (data) => {
const { validatorStore } = this.props;
onSelectAutocomplete = async data => {
const { validatorStore } = this.props
let place = await geocodeByAddress(data)
console.log(place);
console.log(place)
let address_components = {
postal_code: "",
street_number: "",
route: "",
locality: "",
administrative_area_level_1: ""
};
postal_code: '',
street_number: '',
route: '',
locality: '',
administrative_area_level_1: ''
}
for (let i = 0; i < place[0].address_components.length; i++) {
let address_component = place[0].address_components[i];
let addressType = address_component.types[0];
switch(addressType) {
case "postal_code":
address_components.postal_code = address_component.short_name;
break;
case "street_number":
address_components.street_number = address_component.short_name;
break;
case "route":
address_components.route = address_component.short_name;
break;
case "locality":
address_components.locality = address_component.short_name;
break;
case "administrative_area_level_1":
address_components.administrative_area_level_1 = address_component.long_name;
break;
let address_component = place[0].address_components[i]
let addressType = address_component.types[0]
switch (addressType) {
case 'postal_code':
address_components.postal_code = address_component.short_name
break
case 'street_number':
address_components.street_number = address_component.short_name
break
case 'route':
address_components.route = address_component.short_name
break
case 'locality':
address_components.locality = address_component.short_name
break
case 'administrative_area_level_1':
address_components.administrative_area_level_1 = address_component.long_name
break
default:
break;
break
}
validatorStore.address = `${address_components.street_number} ${address_components.route} ${address_components.locality}`;
validatorStore.state = address_components.administrative_area_level_1;
validatorStore.zipCode = address_components.postal_code;
validatorStore.address = `${address_components.street_number} ${address_components.route} ${
address_components.locality
}`
validatorStore.state = address_components.administrative_area_level_1
validatorStore.zipCode = address_components.postal_code
}
}
componentDidMount() {
this.props.ballotStore.ballotKeys.miningKey = constants.NEW_MINING_KEY;
this.props.ballotStore.ballotKeys.miningKey = constants.NEW_MINING_KEY
}
componentWillUnmount() {
const { ballotStore } = this.props;
const { ballotStore } = this.props
if (JSON.stringify(ballotStore.ballotKeys.miningKey) === JSON.stringify(constants.NEW_MINING_KEY)) {
ballotStore.ballotKeys.miningKey = "";
ballotStore.ballotKeys.miningKey = ''
}
}
render() {
const { validatorStore } = this.props;
const { validatorStore } = this.props
const inputProps = {
value: validatorStore.address,
onChange: (e) => validatorStore.changeValidatorMetadata(e, "address"),
onChange: e => validatorStore.changeValidatorMetadata(e, 'address'),
id: 'address'
}
const AutocompleteItem = ({ formattedSuggestion }) => (
<div className="custom-container">
<strong>{ formattedSuggestion.mainText }</strong>{' '}
<small>{ formattedSuggestion.secondaryText }</small>
<strong>{formattedSuggestion.mainText}</strong> <small>{formattedSuggestion.secondaryText}</small>
</div>
)
return (
@ -76,131 +77,129 @@ export class Validator extends React.Component {
<div className="left">
<div className="form-el">
<label htmlFor="full-name">Full Name</label>
<input type="text" id="full-name"
<input
type="text"
id="full-name"
value={validatorStore.fullName}
onChange={e => validatorStore.changeValidatorMetadata(e, "fullName")}
onChange={e => validatorStore.changeValidatorMetadata(e, 'fullName')}
/>
<p className="hint">
Proposed validator's full name. Example: Jefferson L. Flowers.
</p>
<p className="hint">Proposed validator's full name. Example: Jefferson L. Flowers.</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="address">Address</label>
<PlacesAutocomplete
onSelect={this.onSelectAutocomplete} inputProps={inputProps} autocompleteItem={AutocompleteItem}
onSelect={this.onSelectAutocomplete}
inputProps={inputProps}
autocompleteItem={AutocompleteItem}
/>
<p className="hint">
Proposed validator's registration address. Example: 110 Wall St., New York.
</p>
<p className="hint">Proposed validator's registration address. Example: 110 Wall St., New York.</p>
</div>
</div>
<div className="left">
<div className="form-el">
<label htmlFor="us-state">State</label>
<Select id="us-state"
<Select
id="us-state"
value={validatorStore.state}
onChange={e => validatorStore.changeValidatorMetadata(e, "state")}
onChange={e => validatorStore.changeValidatorMetadata(e, 'state')}
options={[
{ value: '', label: '' },
{ value: "Alabama", label: "Alabama" },
{ value: "Alaska", label: "Alaska" },
{ value: "Arizona", label: "Arizona" },
{ value: "Arkanzas", label: "Arkanzas" },
{ value: "California", label: "California" },
{ value: "Colorado", label: "Colorado" },
{ value: "Connecticut", label: "Connecticut" },
{ value: "Delaware", label: "Delaware" },
{ value: "Florida", label: "Florida" },
{ value: "Georgia", label: "Georgia" },
{ value: "Hawaii", label: "Hawaii" },
{ value: "Idaho", label: "Idaho" },
{ value: "Illinois", label: "Illinois" },
{ value: "Indiana", label: "Indiana" },
{ value: "Iowa", label: "Iowa" },
{ value: "Kansas", label: "Kansas" },
{ value: "Kentucky", label: "Kentucky" },
{ value: "Louisianna", label: "Louisianna" },
{ value: "Maine", label: "Maine" },
{ value: "Maryland", label: "Maryland" },
{ value: "Massachusetts", label: "Massachusetts" },
{ value: "Michigan", label: "Michigan" },
{ value: "Minnesota", label: "Minnesota" },
{ value: "Mississippi", label: "Mississippi" },
{ value: "Missouri", label: "Missouri" },
{ value: "Montana", label: "Montana" },
{ value: "Nebraska", label: "Nebraska" },
{ value: "Nevada", label: "Nevada" },
{ value: "New Hampshire", label: "New Hampshire" },
{ value: "New Jersey", label: "New Jersey" },
{ value: "New Mexico", label: "New Mexico" },
{ value: "New York", label: "New York" },
{ value: "North Carolina", label: "North Carolina" },
{ value: "North Dakota", label: "North Dakota" },
{ value: "Ohio", label: "Ohio" },
{ value: "Oklahoma", label: "Oklahoma" },
{ value: "Oregon", label: "Oregon" },
{ value: "Pennsylvania", label: "Pennsylvania" },
{ value: "Rhode Island", label: "Rhode Island" },
{ value: "South California", label: "South California" },
{ value: "South Dakota", label: "South Dakota" },
{ value: "Tennessee", label: "Tennessee" },
{ value: "Texas", label: "Texas" },
{ value: "Utah", label: "Utah" },
{ value: "Vermont", label: "Vermont" },
{ value: "Virginia", label: "Virginia" },
{ value: "Washington", label: "Washington" },
{ value: "West Virginia", label: "West Virginia" },
{ value: "Wisconsin", label: "Wisconsin" },
{ value: "Wyoming", label: "Wyoming" }
{ value: 'Alabama', label: 'Alabama' },
{ value: 'Alaska', label: 'Alaska' },
{ value: 'Arizona', label: 'Arizona' },
{ value: 'Arkanzas', label: 'Arkanzas' },
{ value: 'California', label: 'California' },
{ value: 'Colorado', label: 'Colorado' },
{ value: 'Connecticut', label: 'Connecticut' },
{ value: 'Delaware', label: 'Delaware' },
{ value: 'Florida', label: 'Florida' },
{ value: 'Georgia', label: 'Georgia' },
{ value: 'Hawaii', label: 'Hawaii' },
{ value: 'Idaho', label: 'Idaho' },
{ value: 'Illinois', label: 'Illinois' },
{ value: 'Indiana', label: 'Indiana' },
{ value: 'Iowa', label: 'Iowa' },
{ value: 'Kansas', label: 'Kansas' },
{ value: 'Kentucky', label: 'Kentucky' },
{ value: 'Louisianna', label: 'Louisianna' },
{ value: 'Maine', label: 'Maine' },
{ value: 'Maryland', label: 'Maryland' },
{ value: 'Massachusetts', label: 'Massachusetts' },
{ value: 'Michigan', label: 'Michigan' },
{ value: 'Minnesota', label: 'Minnesota' },
{ value: 'Mississippi', label: 'Mississippi' },
{ value: 'Missouri', label: 'Missouri' },
{ value: 'Montana', label: 'Montana' },
{ value: 'Nebraska', label: 'Nebraska' },
{ value: 'Nevada', label: 'Nevada' },
{ value: 'New Hampshire', label: 'New Hampshire' },
{ value: 'New Jersey', label: 'New Jersey' },
{ value: 'New Mexico', label: 'New Mexico' },
{ value: 'New York', label: 'New York' },
{ value: 'North Carolina', label: 'North Carolina' },
{ value: 'North Dakota', label: 'North Dakota' },
{ value: 'Ohio', label: 'Ohio' },
{ value: 'Oklahoma', label: 'Oklahoma' },
{ value: 'Oregon', label: 'Oregon' },
{ value: 'Pennsylvania', label: 'Pennsylvania' },
{ value: 'Rhode Island', label: 'Rhode Island' },
{ value: 'South California', label: 'South California' },
{ value: 'South Dakota', label: 'South Dakota' },
{ value: 'Tennessee', label: 'Tennessee' },
{ value: 'Texas', label: 'Texas' },
{ value: 'Utah', label: 'Utah' },
{ value: 'Vermont', label: 'Vermont' },
{ value: 'Virginia', label: 'Virginia' },
{ value: 'Washington', label: 'Washington' },
{ value: 'West Virginia', label: 'West Virginia' },
{ value: 'Wisconsin', label: 'Wisconsin' },
{ value: 'Wyoming', label: 'Wyoming' }
]}
>
</Select>
<p className="hint">
Proposed validator's US state. Example: New York.
</p>
/>
<p className="hint">Proposed validator's US state. Example: New York.</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="zip-code">Zip Code</label>
<input type="text" id="zip-code"
<input
type="text"
id="zip-code"
value={validatorStore.zipCode}
onChange={e => validatorStore.changeValidatorMetadata(e, "zipCode")}
onChange={e => validatorStore.changeValidatorMetadata(e, 'zipCode')}
/>
<p className="hint">
Proposed validator's postal code. Example: 10005.
</p>
<p className="hint">Proposed validator's postal code. Example: 10005.</p>
</div>
</div>
<div className="left">
<div className="form-el">
<label htmlFor="license-id">License ID</label>
<input type="text" id="license-id"
<input
type="text"
id="license-id"
value={validatorStore.licenseID}
onChange={e => validatorStore.changeValidatorMetadata(e, "licenseID")}
onChange={e => validatorStore.changeValidatorMetadata(e, 'licenseID')}
/>
<p className="hint">
Proposed validator's notary license ID. Example: 191947.
</p>
<p className="hint">Proposed validator's notary license ID. Example: 191947.</p>
</div>
</div>
<div className="right">
<div className="form-el">
<label htmlFor="license-expiration">License Expiration</label>
<input type="date" id="license-expiration"
<input
type="date"
id="license-expiration"
value={validatorStore.licenseExpiration}
onChange={e => validatorStore.changeValidatorMetadata(e, "licenseExpiration")}
onChange={e => validatorStore.changeValidatorMetadata(e, 'licenseExpiration')}
/>
<p className="hint">
When proposed validator's notary license is expired. Example: 11/10/2021.
</p>
<p className="hint">When proposed validator's notary license is expired. Example: 11/10/2021.</p>
</div>
</div>
</div>
<hr />
</div>
);
)
}
}

View File

@ -1,5 +1,5 @@
export { Ballots } from './Ballots';
export { Header } from './Header';
export { NewBallot } from './NewBallot';
export { Settings } from './Settings';
export { Footer } from './Footer';
export { Ballots } from './Ballots.jsx'
export { Header } from './Header.jsx'
export { NewBallot } from './NewBallot.jsx'
export { Settings } from './Settings.jsx'
export { Footer } from './Footer.jsx'

View File

@ -1,16 +1,16 @@
import Web3 from 'web3';
import { networkAddresses } from './addresses';
import helpers from "./helpers";
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
export default class BallotsStorage {
async init({web3, netId}){
const {BALLOTS_STORAGE_ADDRESS} = networkAddresses(netId);
console.log('Ballots Storage address', BALLOTS_STORAGE_ADDRESS);
let web3_10 = new Web3(web3.currentProvider);
const branch = helpers.getBranch(netId);
async init({ web3, netId }) {
const { BALLOTS_STORAGE_ADDRESS } = networkAddresses(netId)
console.log('Ballots Storage address', BALLOTS_STORAGE_ADDRESS)
let web3_10 = new Web3(web3.currentProvider)
const branch = helpers.getBranch(netId)
let ballotsStorageAbi = await helpers.getABI(branch, 'BallotStorage')
let ballotsStorageAbi = await helpers.getABI(branch, 'BallotStorage')
this.ballotsStorageInstance = new web3_10.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS);
}
}
this.ballotsStorageInstance = new web3_10.eth.Contract(ballotsStorageAbi, BALLOTS_STORAGE_ADDRESS)
}
}

View File

@ -1,22 +1,21 @@
import Web3 from 'web3';
import { networkAddresses } from './addresses';
import helpers from "./helpers";
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
export default class POAConsensus {
async init({web3, netId}) {
const {POA_ADDRESS} = networkAddresses(netId);
async init({ web3, netId }) {
const { POA_ADDRESS } = networkAddresses(netId)
console.log('POA address', POA_ADDRESS)
let web3_10 = new Web3(web3.currentProvider);
let web3_10 = new Web3(web3.currentProvider)
const branch = helpers.getBranch(netId);
const branch = helpers.getBranch(netId)
let poaConsensusAbi = await helpers.getABI(branch, 'PoaNetworkConsensus')
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS);
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS)
}
async getValidators(){
return await this.poaInstance.methods.getValidators().call();
async getValidators() {
return await this.poaInstance.methods.getValidators().call()
}
}
}

View File

@ -1,20 +1,20 @@
import Web3 from 'web3';
import { networkAddresses } from './addresses';
import helpers from "./helpers";
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
export default class ProxyStorage {
async init({web3, netId}){
const {PROXY_ADDRESS} = networkAddresses(netId);
console.log('Proxy Storage address', PROXY_ADDRESS);
let web3_10 = new Web3(web3.currentProvider);
const branch = helpers.getBranch(netId);
async init({ web3, netId }) {
const { PROXY_ADDRESS } = networkAddresses(netId)
console.log('Proxy Storage address', PROXY_ADDRESS)
let web3_10 = new Web3(web3.currentProvider)
const branch = helpers.getBranch(netId)
let proxyStorageAbi = await helpers.getABI(branch, 'ProxyStorage')
let proxyStorageAbi = await helpers.getABI(branch, 'ProxyStorage')
this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS);
}
this.proxyStorageInstance = new web3_10.eth.Contract(proxyStorageAbi, PROXY_ADDRESS)
}
doesMethodExist(methodName) {
return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName];
}
}
doesMethodExist(methodName) {
return this.proxyStorageInstance && this.proxyStorageInstance.methods[methodName]
}
}

View File

@ -1,28 +1,28 @@
import Web3 from 'web3';
import { networkAddresses } from './addresses';
import helpers from "./helpers";
import { toAscii } from "../helpers";
import Web3 from 'web3'
import { networkAddresses } from './addresses'
import helpers from './helpers'
import { toAscii } from '../helpers'
export default class ValidatorMetadata {
async init({web3, netId}) {
const {METADATA_ADDRESS} = networkAddresses(netId);
async init({ web3, netId }) {
const { METADATA_ADDRESS } = networkAddresses(netId)
console.log('Metadata address', METADATA_ADDRESS)
let web3_10 = new Web3(web3.currentProvider);
let web3_10 = new Web3(web3.currentProvider)
const branch = helpers.getBranch(netId);
const branch = helpers.getBranch(netId)
let MetadataAbi = await helpers.getABI(branch, 'ValidatorMetadata')
this.metadataInstance = new web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS);
this.metadataInstance = new web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS)
}
async getValidatorFullName({votingKey, miningKey}){
miningKey = miningKey || await this.getMiningByVoting(votingKey);
let validator;
async getValidatorFullName({ votingKey, miningKey }) {
miningKey = miningKey || (await this.getMiningByVoting(votingKey))
let validator
if (this.metadataInstance.methods.getValidatorName) {
validator = await this.metadataInstance.methods.getValidatorName(miningKey).call();
validator = await this.metadataInstance.methods.getValidatorName(miningKey).call()
} else {
validator = await this.metadataInstance.methods.validators(miningKey).call();
validator = await this.metadataInstance.methods.validators(miningKey).call()
}
return {
firstName: toAscii(validator.firstName),
@ -30,7 +30,7 @@ export default class ValidatorMetadata {
}
}
async getMiningByVoting(votingKey){
return await this.metadataInstance.methods.getMiningByVotingKey(votingKey).call();
async getMiningByVoting(votingKey) {
return await this.metadataInstance.methods.getMiningByVotingKey(votingKey).call()
}
}

View File

@ -1,43 +1,47 @@
import { constants } from "../constants";
import { messages } from "../messages";
import swal from 'sweetalert2';
import { constants } from '../constants'
import { messages } from '../messages'
import swal from 'sweetalert2'
function addressesURL(branch) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/${constants.addressesSourceFile}`;
return URL;
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/${
constants.addressesSourceFile
}`
return URL
}
function ABIURL(branch, contract) {
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/abis/${constants.ABIsSources[contract]}`;
return URL;
const URL = `https://raw.githubusercontent.com/${constants.organization}/${constants.repoName}/${branch}/abis/${
constants.ABIsSources[contract]
}`
return URL
}
function getABI(branch, contract) {
let addr = ABIURL(branch, contract);
return fetch(addr).then((response) => {
return response.json();
})
let addr = ABIURL(branch, contract)
return fetch(addr).then(response => {
return response.json()
})
}
function wrongRepoAlert(addr) {
swal("Error!", messages.wrongRepo(addr), "error");
swal('Error!', messages.wrongRepo(addr), 'error')
}
function getBranch(netId) {
switch (netId) {
case '77':
return 'sokol'
case '99':
return 'core'
default:
return 'core'
}
switch (netId) {
case '77':
return 'sokol'
case '99':
return 'core'
default:
return 'core'
}
}
module.exports = {
addressesURL,
ABIURL,
getABI,
wrongRepoAlert,
getBranch
addressesURL,
ABIURL,
getABI,
wrongRepoAlert,
getBranch
}

View File

@ -1,4 +1,4 @@
import { messages } from "./messages";
import { messages } from './messages'
let getWeb3 = () => {
return new Promise((resolve, reject) => {
@ -10,32 +10,32 @@ let getWeb3 = () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider.
var errorMsg = null;
var errorMsg = null
web3 = new window.Web3(web3.currentProvider)
web3.version.getNetwork((err, netId) => {
let netIdName;
console.log('netId', netId);
let netIdName
console.log('netId', netId)
switch (netId) {
case "99":
case '99':
netIdName = 'Core'
console.log('This is Core', netId)
break;
case "77":
break
case '77':
netIdName = 'Sokol'
console.log('This is Sokol', netId)
break;
break
default:
netIdName = 'ERROR'
errorMsg = messages.WRONG_NETWORK_MSG
console.log('This is an unknown network.', netId)
}
document.title = `${netIdName} - POA Network Governance DApp`
var defaultAccount = web3.eth.defaultAccount || null;
if(defaultAccount === null){
reject({message: messages.NO_METAMASK_MSG})
var defaultAccount = web3.eth.defaultAccount || null
if (defaultAccount === null) {
reject({ message: messages.NO_METAMASK_MSG })
}
if(errorMsg !== null){
reject({message: errorMsg})
if (errorMsg !== null) {
reject({ message: errorMsg })
}
results = {
web3Instance: web3,
@ -47,15 +47,13 @@ let getWeb3 = () => {
resolve(results)
})
console.log('Injected web3 detected.');
console.log('Injected web3 detected.')
} else {
reject({message: messages.NO_METAMASK_MSG})
console.error('Metamask not found');
reject({ message: messages.NO_METAMASK_MSG })
console.error('Metamask not found')
}
})
})
}
export default getWeb3

View File

@ -1,98 +1,98 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { Provider } from 'mobx-react';
import { RouterStore, syncHistoryWithStore } from 'mobx-react-router';
import commonStore from './stores/CommonStore';
import validatorStore from './stores/ValidatorStore';
import ballotStore from './stores/BallotStore';
import ballotsStore from './stores/BallotsStore';
import contractsStore from './stores/ContractsStore';
import { getContractsAddresses } from './contracts/addresses';
import swal from 'sweetalert2';
import getWeb3 from './getWeb3';
import "babel-polyfill";
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { Router, Route } from 'react-router-dom'
import App from './App'
import registerServiceWorker from './registerServiceWorker'
import { Provider } from 'mobx-react'
import { RouterStore, syncHistoryWithStore } from 'mobx-react-router'
import commonStore from './stores/CommonStore'
import validatorStore from './stores/ValidatorStore'
import ballotStore from './stores/BallotStore'
import ballotsStore from './stores/BallotsStore'
import contractsStore from './stores/ContractsStore'
import { getContractsAddresses } from './contracts/addresses'
import swal from 'sweetalert2'
import getWeb3 from './getWeb3'
import 'babel-polyfill'
import createBrowserHistory from 'history/createBrowserHistory'
const browserHistory = createBrowserHistory();
const routingStore = new RouterStore();
const stores = { commonStore, contractsStore, ballotStore, ballotsStore, validatorStore, routing: routingStore };
const history = syncHistoryWithStore(browserHistory, routingStore);
const browserHistory = createBrowserHistory()
const routingStore = new RouterStore()
const stores = { commonStore, contractsStore, ballotStore, ballotsStore, validatorStore, routing: routingStore }
const history = syncHistoryWithStore(browserHistory, routingStore)
function generateElement(msg){
let errorNode = document.createElement("div");
errorNode.innerHTML = `${msg}`;
return errorNode;
function generateElement(msg) {
let errorNode = document.createElement('div')
errorNode.innerHTML = `${msg}`
return errorNode
}
class AppMainRouter extends Component {
constructor(props) {
super(props);
commonStore.showLoading();
super(props)
commonStore.showLoading()
getWeb3().then(async (web3Config) => {
let getSokolContractsAddresses = getContractsAddresses('sokol');
let getCoreContractsAddresses = getContractsAddresses('core');
await Promise.all([getSokolContractsAddresses, getCoreContractsAddresses]);
getWeb3()
.then(async web3Config => {
let getSokolContractsAddresses = getContractsAddresses('sokol')
let getCoreContractsAddresses = getContractsAddresses('core')
await Promise.all([getSokolContractsAddresses, getCoreContractsAddresses])
contractsStore.setWeb3Instance(web3Config);
contractsStore.setWeb3Instance(web3Config)
let setPoaConsensus = contractsStore.setPoaConsensus(web3Config);
let setBallotsStorage = contractsStore.setBallotsStorage(web3Config);
let setProxyStorage = contractsStore.setProxyStorage(web3Config);
let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config);
let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config);
let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config);
let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config);
let setPoaConsensus = contractsStore.setPoaConsensus(web3Config)
let setBallotsStorage = contractsStore.setBallotsStorage(web3Config)
let setProxyStorage = contractsStore.setProxyStorage(web3Config)
let setVotingToChangeKeys = contractsStore.setVotingToChangeKeys(web3Config)
let setVotingToChangeMinThreshold = contractsStore.setVotingToChangeMinThreshold(web3Config)
let setVotingToChangeProxy = contractsStore.setVotingToChangeProxy(web3Config)
let setValidatorMetadata = contractsStore.setValidatorMetadata(web3Config)
await Promise.all([
setPoaConsensus,
setBallotsStorage,
setProxyStorage,
setVotingToChangeKeys,
setVotingToChangeMinThreshold,
setVotingToChangeProxy,
setValidatorMetadata
]);
await Promise.all([
setPoaConsensus,
setBallotsStorage,
setProxyStorage,
setVotingToChangeKeys,
setVotingToChangeMinThreshold,
setVotingToChangeProxy,
setValidatorMetadata
])
await contractsStore.setMiningKey(web3Config);
await contractsStore.setVotingKey(web3Config);
await contractsStore.setMiningKey(web3Config)
await contractsStore.setVotingKey(web3Config)
await contractsStore.getAllValidatorMetadata();
await contractsStore.getAllBallots();
await contractsStore.getAllValidatorMetadata()
await contractsStore.getAllBallots()
contractsStore.getKeysBallotThreshold();
contractsStore.getMinThresholdBallotThreshold();
contractsStore.getProxyBallotThreshold();
contractsStore.getBallotsLimits();
console.log("votingKey", contractsStore.votingKey);
console.log("miningKey", contractsStore.miningKey);
commonStore.hideLoading();
}).catch((error) => {
console.error(error.message);
commonStore.hideLoading();
swal({
title: "Error",
html: generateElement(error.message),
icon: "error",
type: "error"
});
});
contractsStore.getKeysBallotThreshold()
contractsStore.getMinThresholdBallotThreshold()
contractsStore.getProxyBallotThreshold()
contractsStore.getBallotsLimits()
console.log('votingKey', contractsStore.votingKey)
console.log('miningKey', contractsStore.miningKey)
commonStore.hideLoading()
})
.catch(error => {
console.error(error.message)
commonStore.hideLoading()
swal({
title: 'Error',
html: generateElement(error.message),
icon: 'error',
type: 'error'
})
})
}
render(){
render() {
return (
<Provider { ...stores }>
<Provider {...stores}>
<Router history={history}>
<Route component={App} />
</Router>
</Provider>
)
}
}
ReactDOM.render(<AppMainRouter />, document.getElementById('root'));
registerServiceWorker();
ReactDOM.render(<AppMainRouter />, document.getElementById('root'))
registerServiceWorker()

View File

@ -1,34 +1,34 @@
let messages = {};
messages.invalidVotingKeyMsg = (key) => {
return `The key ${key} is not valid voting Key! Please make sure you have loaded correct voting key in Metamask`;
};
messages.VOTED_SUCCESS_MSG = "You successfully voted";
messages.BALLOT_CREATED_SUCCESS_MSG = "You successfully created a new ballot";
messages.FINALIZED_SUCCESS_MSG = "You successfully finalized";
messages.ALREADY_FINALIZED_MSG = "This ballot is already finalized";
messages.INVALID_VOTE_MSG = "You can't vote on this ballot";
messages.INVALID_FINALIZE_MSG = "You can't finalize this ballot";
messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG = "Ballot affectedKey isn't address";
messages.MINING_KEY_IS_NOT_ADDRESS_MSG = "Ballot miningKey isn't address";
messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG = "Ballot proposedAddress isn't address";
messages.END_TIME_SHOULD_BE_GREATER_THAN_NOW_MSG = "Ballot end time should be greater than now";
messages.BALLOT_TYPE_IS_EMPTY_MSG = "Ballot type is empty";
let messages = {}
messages.invalidVotingKeyMsg = key => {
return `The key ${key} is not valid voting Key! Please make sure you have loaded correct voting key in Metamask`
}
messages.VOTED_SUCCESS_MSG = 'You successfully voted'
messages.BALLOT_CREATED_SUCCESS_MSG = 'You successfully created a new ballot'
messages.FINALIZED_SUCCESS_MSG = 'You successfully finalized'
messages.ALREADY_FINALIZED_MSG = 'This ballot is already finalized'
messages.INVALID_VOTE_MSG = "You can't vote on this ballot"
messages.INVALID_FINALIZE_MSG = "You can't finalize this ballot"
messages.AFFECTED_KEY_IS_NOT_ADDRESS_MSG = "Ballot affectedKey isn't address"
messages.MINING_KEY_IS_NOT_ADDRESS_MSG = "Ballot miningKey isn't address"
messages.PROPOSED_ADDRESS_IS_NOT_ADDRESS_MSG = "Ballot proposedAddress isn't address"
messages.END_TIME_SHOULD_BE_GREATER_THAN_NOW_MSG = 'Ballot end time should be greater than now'
messages.BALLOT_TYPE_IS_EMPTY_MSG = 'Ballot type is empty'
messages.NO_METAMASK_MSG = `You haven't chosen any account in MetaMask.
Please, choose your voting key in MetaMask and reload the page.
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`;
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`
messages.WRONG_NETWORK_MSG = `You aren't connected to POA Network.
Please, switch on POA plugin and refresh the page.
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`;
messages.ballotIsNotActiveMsg = (timeToStart) => {
return `The ballot is not active yet. Time to start: ${timeToStart}`;
};
messages.SHOULD_BE_MORE_THAN_MIN_DURATION = (minDuration, duration, neededHours, neededMinutes) => {
return `Ballot end time should be at least ${minDuration} hours from now in UTC time. Current duration is ${duration} hours.
Please add ${neededHours} hours and ${neededMinutes} minutes in order to set correct end time
`;
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`
messages.ballotIsNotActiveMsg = timeToStart => {
return `The ballot is not active yet. Time to start: ${timeToStart}`
}
messages.SHOULD_BE_LESS_OR_EQUAL_14_DAYS = (duration) => {
return `Ballot end time should not be more than 14 days from now in UTC time. Current duration is ${duration} hours.`;
messages.SHOULD_BE_MORE_THAN_MIN_DURATION = (minDuration, duration, neededHours, neededMinutes) => {
return `Ballot end time should be at least ${minDuration} hours from now in UTC time. Current duration is ${duration} hours.
Please add ${neededHours} hours and ${neededMinutes} minutes in order to set correct end time
`
}
messages.SHOULD_BE_LESS_OR_EQUAL_14_DAYS = duration => {
return `Ballot end time should not be more than 14 days from now in UTC time. Current duration is ${duration} hours.`
}
messages.BALLOT_CREATE_FAILED_TX = `Your transaction was failed. Please make sure you set correct parameters for ballot creation.
Make sure you don't have Transaction Error. Exception thrown in contract code message in Metamask before you sign it.`
@ -36,10 +36,10 @@ messages.VOTE_FAILED_TX = `Your transaction was failed. Please make sure you hav
Make sure you don't have Transaction Error. Exception thrown in contract code message in Metamask before you sign it.`
messages.FINALIZE_FAILED_TX = `Your transaction was failed. Make sure you don't have Transaction Error.
Exception thrown in contract code message in Metamask before you sign it.`
messages.DESCRIPTION_IS_EMPTY = "Description cannot be empty";
messages.wrongRepo = (repo) => {
return `There is no contracts.json in configured repo ${repo}`;
};
messages.DESCRIPTION_IS_EMPTY = 'Description cannot be empty'
messages.wrongRepo = repo => {
return `There is no contracts.json in configured repo ${repo}`
}
module.exports = {
messages
};
}

View File

@ -13,33 +13,31 @@ const isLocalhost = Boolean(
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
)
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
const publicUrl = new URL(process.env.PUBLIC_URL, window.location)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return;
return
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);
checkValidServiceWorker(swUrl)
} else {
// Is not local host. Just register service worker
registerValidSW(swUrl);
registerValidSW(swUrl)
}
});
})
}
}
@ -48,7 +46,7 @@ function registerValidSW(swUrl) {
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
const installingWorker = registration.installing
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
@ -56,20 +54,20 @@ function registerValidSW(swUrl) {
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.');
console.log('New content is available; please refresh.')
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log('Content is cached for offline use.')
}
}
};
};
}
}
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
console.error('Error during service worker registration:', error)
})
}
function checkValidServiceWorker(swUrl) {
@ -77,32 +75,27 @@ function checkValidServiceWorker(swUrl) {
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
) {
if (response.status === 404 || response.headers.get('content-type').indexOf('javascript') === -1) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
window.location.reload()
})
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
registerValidSW(swUrl)
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
console.log('No internet connection found. App is running in offline mode.')
})
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
registration.unregister()
})
}
}

View File

@ -1,154 +1,162 @@
import { observable, computed, action, toJS } from 'mobx';
import moment from 'moment';
import { constants } from "../constants";
import { observable, computed, action, toJS } from 'mobx'
import moment from 'moment'
import { constants } from '../constants'
class BallotStore {
BallotType = {
keys: 1,
minThreshold: 2,
proxy: 3
};
KeysBallotType = {
add: 1,
remove: 2,
swap: 3
};
KeyType = {
mining: 1,
voting: 2,
payout: 3
};
ProxyBallotType = {
1: 'KeysManager',
2: 'VotingToChangeKeys',
3: 'VotingToChangeMinThreshold',
4: 'VotingToChangeProxy',
5: 'BallotsStorage',
7: 'ValidatorMetadata',
8: 'ProxyStorage'
}
@observable ballotType;
@observable keysBallotType;
@observable endTime;
BallotType = {
keys: 1,
minThreshold: 2,
proxy: 3
}
KeysBallotType = {
add: 1,
remove: 2,
swap: 3
}
KeyType = {
mining: 1,
voting: 2,
payout: 3
}
ProxyBallotType = {
1: 'KeysManager',
2: 'VotingToChangeKeys',
3: 'VotingToChangeMinThreshold',
4: 'VotingToChangeProxy',
5: 'BallotsStorage',
7: 'ValidatorMetadata',
8: 'ProxyStorage'
}
@observable ballotType
@observable keysBallotType
@observable endTime
@observable ballotKeys;
@observable ballotMinThreshold;
@observable ballotProxy;
@observable memo;
@observable ballotKeys
@observable ballotMinThreshold
@observable ballotProxy
@observable memo
constructor() {
this.ballotType = null
this.endTime = moment()
.add(constants.endTimeDefaultInMinutes, 'minutes')
.format('YYYY-MM-DDTHH:mm')
constructor() {
this.ballotType = null;
this.endTime = moment().add(constants.endTimeDefaultInMinutes, 'minutes').format("YYYY-MM-DDTHH:mm");
this.ballotKeys = {
keyType: null,
keysBallotType: null,
affectedKey: '',
newVotingKey: '',
newPayoutKey: '',
miningKey: ''
}
this.ballotKeys = {
keyType: null,
keysBallotType: null,
affectedKey: "",
newVotingKey: "",
newPayoutKey: "",
miningKey: ""
};
this.ballotMinThreshold = {
proposedValue: ''
}
this.ballotMinThreshold = {
proposedValue: ""
};
this.ballotProxy = {
proposedAddress: '',
contractType: ''
}
this.memo = ''
}
this.ballotProxy = {
proposedAddress: "",
contractType: ""
};
this.memo = "";
}
@computed
get endTimeUnix() {
console.log(this.endTime)
return moment(this.endTime).unix()
}
@computed get endTimeUnix() {
console.log(this.endTime)
return moment(this.endTime).unix();
}
@computed
get isBallotForKey() {
return this.ballotType === this.BallotType.keys
}
@computed get isBallotForKey() {
return this.ballotType === this.BallotType.keys
}
@computed
get isBallotForMinThreshold() {
return this.ballotType === this.BallotType.minThreshold
}
@computed get isBallotForMinThreshold() {
return this.ballotType === this.BallotType.minThreshold
}
@computed
get isBallotForProxy() {
return this.ballotType === this.BallotType.proxy
}
@computed get isBallotForProxy() {
return this.ballotType === this.BallotType.proxy
}
@computed
get isAddKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.add
}
@computed get isAddKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.add
}
@computed
get isRemoveKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.remove
}
@computed get isRemoveKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.remove
}
@computed
get isSwapKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.swap
}
@computed get isSwapKeysBallotType() {
return this.ballotKeys.keysBallotType === this.KeysBallotType.swap
}
@computed
get isMiningKeyType() {
return this.ballotKeys.keyType === this.KeyType.mining
}
@computed get isMiningKeyType() {
return this.ballotKeys.keyType === this.KeyType.mining
}
@computed
get isVotingKeyType() {
return this.ballotKeys.keyType === this.KeyType.voting
}
@computed get isVotingKeyType() {
return this.ballotKeys.keyType === this.KeyType.voting
}
@computed
get isPayoutKeyType() {
return this.ballotKeys.keyType === this.KeyType.payout
}
@computed get isPayoutKeyType() {
return this.ballotKeys.keyType === this.KeyType.payout
}
@computed
get isNewValidatorPersonalData() {
return ballotStore.isBallotForKey && ballotStore.isAddKeysBallotType && ballotStore.isMiningKeyType
}
@computed get isNewValidatorPersonalData() {
return ballotStore.isBallotForKey
&& ballotStore.isAddKeysBallotType
&& ballotStore.isMiningKeyType;
}
@action('change ballot type')
changeBallotType = (e, _ballotType) => {
console.log('change ballot type', _ballotType)
this.ballotType = _ballotType
}
@action("change ballot type")
changeBallotType = (e, _ballotType) => {
console.log("change ballot type", _ballotType);
this.ballotType = _ballotType;
}
@action('change keys ballot type')
changeKeysBallotType = (e, _keysBallotType) => {
console.log('change keys ballot type', _keysBallotType)
this.ballotKeys.keysBallotType = _keysBallotType
}
@action("change keys ballot type")
changeKeysBallotType = (e, _keysBallotType) => {
console.log("change keys ballot type", _keysBallotType);
this.ballotKeys.keysBallotType = _keysBallotType;
}
@action('change affected key type')
changeKeyType = (e, _keyType) => {
console.log('change affected key type', _keyType)
this.ballotKeys.keyType = _keyType
}
@action("change affected key type")
changeKeyType = (e, _keyType) => {
console.log("change affected key type", _keyType);
this.ballotKeys.keyType = _keyType;
}
@action('change ballot metadata')
changeBallotMetadata = (e, field, parent) => {
let newVal = e ? (e.target ? e.target.value : e.value) : ''
if (parent) this[parent][field] = newVal
else this[field] = newVal
console.log('ballot metadata', field, parent ? this[parent][field] : this[field])
}
@action('change ballot metadata')
setMiningKey = value => {
this.ballotKeys.miningKey = value
console.log('ballot mining key', toJS(value))
}
@action("change ballot metadata")
changeBallotMetadata = (e, field, parent) => {
let newVal = e?(e.target?e.target.value:e.value):"";
if (parent)
this[parent][field] = newVal;
else
this[field] = newVal;
console.log("ballot metadata", field, parent?this[parent][field]:this[field]);
}
@action("change ballot metadata")
setMiningKey = (value) => {
this.ballotKeys.miningKey = value;
console.log("ballot mining key", toJS(value));
}
@action("Set ballot memo")
setMemo(e) {
console.log("memo", this.memo);
this.memo = e.target.value;
}
@action('Set ballot memo')
setMemo(e) {
console.log('memo', this.memo)
this.memo = e.target.value
}
}
const ballotStore = new BallotStore();
const ballotStore = new BallotStore()
export default ballotStore;
export { BallotStore };
export default ballotStore
export { BallotStore }

View File

@ -1,26 +1,26 @@
import { observable } from 'mobx';
import { observable } from 'mobx'
class BallotsStore {
@observable activeKeysBallotsLength;
@observable activeMinThresholdBallotsLength;
@observable activeProxyBallotsLength;
@observable ballotCards;
@observable activeKeysBallotsLength
@observable activeMinThresholdBallotsLength
@observable activeProxyBallotsLength
@observable ballotCards
@observable activeMinThresholdBallotsIDs;
@observable activeProxyBallotsIDs;
@observable activeMinThresholdBallotsIDs
@observable activeProxyBallotsIDs
constructor() {
this.activeKeysBallotsLength = 0;
this.activeMinThresholdBallotsLength = 0;
this.activeProxyBallotsLength = 0;
constructor() {
this.activeKeysBallotsLength = 0
this.activeMinThresholdBallotsLength = 0
this.activeProxyBallotsLength = 0
this.activeMinThresholdBallotsIDs = [];
this.activeProxyBallotsIDs = [];
this.ballotCards = [];
}
this.activeMinThresholdBallotsIDs = []
this.activeProxyBallotsIDs = []
this.ballotCards = []
}
}
const ballotsStore = new BallotsStore();
const ballotsStore = new BallotsStore()
export default ballotsStore;
export { BallotsStore };
export default ballotsStore
export { BallotsStore }

View File

@ -1,38 +1,38 @@
import { observable, action } from 'mobx';
import { observable, action } from 'mobx'
class CommonStore {
@observable loading;
@observable rootPath;
@observable isActiveFilter;
@observable isToFinalizeFilter;
@observable searchTerm;
@observable loadMoreLimit;
@observable loading
@observable rootPath
@observable isActiveFilter
@observable isToFinalizeFilter
@observable searchTerm
@observable loadMoreLimit
constructor() {
this.loading = false;
this.isActiveFilter = false;
this.isToFinalizeFilter = false;
this.rootPath = '/poa-dapps-voting'
this.loadMoreLimit = 10;
}
constructor() {
this.loading = false
this.isActiveFilter = false
this.isToFinalizeFilter = false
this.rootPath = '/poa-dapps-voting'
this.loadMoreLimit = 10
}
@action("show loading")
showLoading() {
this.loading = true;
}
@action('show loading')
showLoading() {
this.loading = true
}
@action("hide loading")
hideLoading() {
this.loading = false;
}
@action('hide loading')
hideLoading() {
this.loading = false
}
@action("set search term")
setSearchTerm = (_val) => {
this.searchTerm = _val;
}
@action('set search term')
setSearchTerm = _val => {
this.searchTerm = _val
}
}
const commonStore = new CommonStore();
const commonStore = new CommonStore()
export default commonStore;
export { CommonStore };
export default commonStore
export { CommonStore }

View File

@ -1,5 +1,5 @@
import { observable, computed, action } from 'mobx';
import React from 'react';
import { observable, computed, action } from 'mobx'
import React from 'react'
import PoaConsensus from '../contracts/PoaConsensus.contract'
import BallotsStorage from '../contracts/BallotsStorage.contract'
@ -11,345 +11,367 @@ import ValidatorMetadata from '../contracts/ValidatorMetadata.contract'
import ballotStore from './BallotStore'
import ballotsStore from './BallotsStore'
import commonStore from './CommonStore'
import { BallotKeysCard } from "../components/BallotKeysCard";
import { BallotMinThresholdCard } from "../components/BallotMinThresholdCard";
import { BallotProxyCard } from "../components/BallotProxyCard";
import { constants } from "../constants";
import { BallotKeysCard } from '../components/BallotKeysCard.jsx'
import { BallotMinThresholdCard } from '../components/BallotMinThresholdCard.jsx'
import { BallotProxyCard } from '../components/BallotProxyCard.jsx'
import { constants } from '../constants'
import "babel-polyfill";
import 'babel-polyfill'
class ContractsStore {
@observable poaConsensus;
@observable ballotsStorage;
@observable proxyStorage;
@observable votingToChangeKeys;
@observable votingToChangeMinThreshold;
@observable votingToChangeProxy;
@observable validatorMetadata;
@observable votingKey;
@observable miningKey;
@observable web3Instance;
@observable validatorsLength;
@observable keysBallotThreshold;
@observable minThresholdBallotThreshold;
@observable proxyBallotThreshold;
@observable validatorLimits;
@observable validatorsMetadata;
@observable poaConsensus
@observable ballotsStorage
@observable proxyStorage
@observable votingToChangeKeys
@observable votingToChangeMinThreshold
@observable votingToChangeProxy
@observable validatorMetadata
@observable votingKey
@observable miningKey
@observable web3Instance
@observable validatorsLength
@observable keysBallotThreshold
@observable minThresholdBallotThreshold
@observable proxyBallotThreshold
@observable validatorLimits
@observable validatorsMetadata
constructor() {
this.votingKey = null;
this.miningKey = null;
this.validatorsMetadata = {};
this.validatorLimits = {keys: null, minThreshold: null, proxy: null};
}
constructor() {
this.votingKey = null
this.miningKey = null
this.validatorsMetadata = {}
this.validatorLimits = { keys: null, minThreshold: null, proxy: null }
}
@computed get isValidVotingKey() {
if (this.miningKey && this.miningKey !== "0x0000000000000000000000000000000000000000") return true;
return false
}
@computed
get isValidVotingKey() {
if (this.miningKey && this.miningKey !== '0x0000000000000000000000000000000000000000') return true
return false
}
@action("Get keys ballot threshold")
getKeysBallotThreshold = async () => {
this.keysBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getBallotThreshold(1).call();
}
@action('Get keys ballot threshold')
getKeysBallotThreshold = async () => {
this.keysBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getBallotThreshold(1).call()
}
@action("Get min threshold ballot threshold")
async getMinThresholdBallotThreshold() {
this.minThresholdBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getBallotThreshold(1).call();
}
@action('Get min threshold ballot threshold')
async getMinThresholdBallotThreshold() {
this.minThresholdBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods
.getBallotThreshold(1)
.call()
}
@action("Get proxy ballot threshold")
getProxyBallotThreshold = async () => {
this.proxyBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getProxyThreshold().call();
}
@action('Get proxy ballot threshold')
getProxyBallotThreshold = async () => {
this.proxyBallotThreshold = await this.ballotsStorage.ballotsStorageInstance.methods.getProxyThreshold().call()
}
@action("Set web3Instance")
setWeb3Instance = (web3Config) => {
this.web3Instance = web3Config.web3Instance;
this.netId = web3Config.netId;
}
@action('Set web3Instance')
setWeb3Instance = web3Config => {
this.web3Instance = web3Config.web3Instance
this.netId = web3Config.netId
}
@action("Set PoA Consensus contract")
setPoaConsensus = async (web3Config) => {
this.poaConsensus = new PoaConsensus();
await this.poaConsensus.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set PoA Consensus contract')
setPoaConsensus = async web3Config => {
this.poaConsensus = new PoaConsensus()
await this.poaConsensus.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set Ballots Storage contract")
setBallotsStorage = async (web3Config) => {
this.ballotsStorage = new BallotsStorage();
await this.ballotsStorage.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set Ballots Storage contract')
setBallotsStorage = async web3Config => {
this.ballotsStorage = new BallotsStorage()
await this.ballotsStorage.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set ProxyStorage contract")
setProxyStorage = async (web3Config) => {
this.proxyStorage = new ProxyStorage();
await this.proxyStorage.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set ProxyStorage contract')
setProxyStorage = async web3Config => {
this.proxyStorage = new ProxyStorage()
await this.proxyStorage.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set VotingToChangeKeys contract")
setVotingToChangeKeys = async (web3Config) => {
this.votingToChangeKeys = new VotingToChangeKeys();
await this.votingToChangeKeys.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set VotingToChangeKeys contract')
setVotingToChangeKeys = async web3Config => {
this.votingToChangeKeys = new VotingToChangeKeys()
await this.votingToChangeKeys.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set VotingToChangeMinThreshold contract")
setVotingToChangeMinThreshold = async (web3Config) => {
this.votingToChangeMinThreshold = new VotingToChangeMinThreshold();
await this.votingToChangeMinThreshold.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set VotingToChangeMinThreshold contract')
setVotingToChangeMinThreshold = async web3Config => {
this.votingToChangeMinThreshold = new VotingToChangeMinThreshold()
await this.votingToChangeMinThreshold.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set VotingToChangeProxy contract")
setVotingToChangeProxy = async (web3Config) => {
this.votingToChangeProxy = new VotingToChangeProxy();
await this.votingToChangeProxy.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set VotingToChangeProxy contract')
setVotingToChangeProxy = async web3Config => {
this.votingToChangeProxy = new VotingToChangeProxy()
await this.votingToChangeProxy.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Set ValidatorMetadata contract")
setValidatorMetadata = async (web3Config) => {
this.validatorMetadata = new ValidatorMetadata();
await this.validatorMetadata.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
});
}
@action('Set ValidatorMetadata contract')
setValidatorMetadata = async web3Config => {
this.validatorMetadata = new ValidatorMetadata()
await this.validatorMetadata.init({
web3: web3Config.web3Instance,
netId: web3Config.netId
})
}
@action("Get validators length")
getValidatorsLength = async () => {
this.validatorsLength = await this.poaConsensus.poaInstance.methods.getCurrentValidatorsLength().call();
}
@action('Get validators length')
getValidatorsLength = async () => {
this.validatorsLength = await this.poaConsensus.poaInstance.methods.getCurrentValidatorsLength().call()
}
@action("Set voting key")
setVotingKey = (web3Config) => {
this.votingKey = web3Config.defaultAccount;
}
@action('Set voting key')
setVotingKey = web3Config => {
this.votingKey = web3Config.defaultAccount
}
@action("Set mining key")
setMiningKey = async (web3Config) => {
try {
this.miningKey = await this.votingToChangeKeys.votingToChangeKeysInstance.methods.getMiningByVotingKey(web3Config.defaultAccount).call();
} catch(e) {
console.log(e)
this.miningKey = "0x0000000000000000000000000000000000000000";
}
}
@action('Set mining key')
setMiningKey = async web3Config => {
try {
this.miningKey = await this.votingToChangeKeys.votingToChangeKeysInstance.methods
.getMiningByVotingKey(web3Config.defaultAccount)
.call()
} catch (e) {
console.log(e)
this.miningKey = '0x0000000000000000000000000000000000000000'
}
}
@action("Get all keys ballots")
getAllBallots = async () => {
let keysNextBallotId = 0, minThresholdNextBallotId = 0, proxyNextBallotId = 0;
try {
[keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId] = await this.getAllBallotsNextIDs();
keysNextBallotId = Number(keysNextBallotId);
minThresholdNextBallotId = Number(minThresholdNextBallotId);
proxyNextBallotId = Number(proxyNextBallotId);
} catch (e) {
console.log(e.message);
}
@action('Get all keys ballots')
getAllBallots = async () => {
let keysNextBallotId = 0,
minThresholdNextBallotId = 0,
proxyNextBallotId = 0
try {
;[keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId] = await this.getAllBallotsNextIDs()
keysNextBallotId = Number(keysNextBallotId)
minThresholdNextBallotId = Number(minThresholdNextBallotId)
proxyNextBallotId = Number(proxyNextBallotId)
} catch (e) {
console.log(e.message)
}
const allKeysPromise = this.getCards(keysNextBallotId, "votingToChangeKeys");
const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, "votingToChangeMinThreshold");
const allProxyPromise = this.getCards(proxyNextBallotId, "votingToChangeProxy");
const allKeysPromise = this.getCards(keysNextBallotId, 'votingToChangeKeys')
const allMinThresholdPromise = this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold')
const allProxyPromise = this.getCards(proxyNextBallotId, 'votingToChangeProxy')
await Promise.all([allKeysPromise, allMinThresholdPromise, allProxyPromise]);
await Promise.all([allKeysPromise, allMinThresholdPromise, allProxyPromise])
const allBallotsIDsLength = keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId;
const allBallotsIDsLength = keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId
if (allBallotsIDsLength === 0) {
commonStore.hideLoading();
}
}
if (allBallotsIDsLength === 0) {
commonStore.hideLoading()
}
}
fillCardVotingState = (votingState, contractType) => {
const creatorLowerCase = votingState.creator.toLowerCase();
votingState.creatorMiningKey = votingState.creator;
if (this.validatorsMetadata.hasOwnProperty(creatorLowerCase)) {
const creatorFullName = this.validatorsMetadata[creatorLowerCase].fullName;
if (creatorFullName) {
votingState.creator = creatorFullName;
}
}
fillCardVotingState = (votingState, contractType) => {
const creatorLowerCase = votingState.creator.toLowerCase()
votingState.creatorMiningKey = votingState.creator
if (this.validatorsMetadata.hasOwnProperty(creatorLowerCase)) {
const creatorFullName = this.validatorsMetadata[creatorLowerCase].fullName
if (creatorFullName) {
votingState.creator = creatorFullName
}
}
if (contractType === "votingToChangeKeys") {
votingState.isAddMining = false;
if (contractType === 'votingToChangeKeys') {
votingState.isAddMining = false
switch (Number(votingState.ballotType)) {
case ballotStore.KeysBallotType.add:
votingState.ballotTypeDisplayName = "add";
if (Number(votingState.affectedKeyType) === ballotStore.KeyType.mining) {
votingState.isAddMining = true;
}
break;
case ballotStore.KeysBallotType.remove:
votingState.ballotTypeDisplayName = "remove";
break;
case ballotStore.KeysBallotType.swap:
votingState.ballotTypeDisplayName = "swap";
break;
default:
votingState.ballotTypeDisplayName = "";
break;
}
switch (Number(votingState.ballotType)) {
case ballotStore.KeysBallotType.add:
votingState.ballotTypeDisplayName = 'add'
if (Number(votingState.affectedKeyType) === ballotStore.KeyType.mining) {
votingState.isAddMining = true
}
break
case ballotStore.KeysBallotType.remove:
votingState.ballotTypeDisplayName = 'remove'
break
case ballotStore.KeysBallotType.swap:
votingState.ballotTypeDisplayName = 'swap'
break
default:
votingState.ballotTypeDisplayName = ''
break
}
if (!votingState.hasOwnProperty('newVotingKey')) {
votingState.newVotingKey = "";
}
if (votingState.newVotingKey === "0x0000000000000000000000000000000000000000") {
votingState.newVotingKey = "";
}
if (!votingState.hasOwnProperty('newVotingKey')) {
votingState.newVotingKey = ''
}
if (votingState.newVotingKey === '0x0000000000000000000000000000000000000000') {
votingState.newVotingKey = ''
}
if (!votingState.hasOwnProperty('newPayoutKey')) {
votingState.newPayoutKey = "";
}
if (votingState.newPayoutKey === "0x0000000000000000000000000000000000000000") {
votingState.newPayoutKey = "";
}
if (!votingState.hasOwnProperty('newPayoutKey')) {
votingState.newPayoutKey = ''
}
if (votingState.newPayoutKey === '0x0000000000000000000000000000000000000000') {
votingState.newPayoutKey = ''
}
switch(Number(votingState.affectedKeyType)) {
case ballotStore.KeyType.mining:
votingState.affectedKeyTypeDisplayName = "mining";
break;
case ballotStore.KeyType.voting:
votingState.affectedKeyTypeDisplayName = "voting";
break;
case ballotStore.KeyType.payout:
votingState.affectedKeyTypeDisplayName = "payout";
break;
default:
votingState.affectedKeyTypeDisplayName = "";
break;
}
if (votingState.isAddMining) {
if (votingState.newVotingKey) votingState.affectedKeyTypeDisplayName += ', voting';
if (votingState.newPayoutKey) votingState.affectedKeyTypeDisplayName += ', payout';
}
switch (Number(votingState.affectedKeyType)) {
case ballotStore.KeyType.mining:
votingState.affectedKeyTypeDisplayName = 'mining'
break
case ballotStore.KeyType.voting:
votingState.affectedKeyTypeDisplayName = 'voting'
break
case ballotStore.KeyType.payout:
votingState.affectedKeyTypeDisplayName = 'payout'
break
default:
votingState.affectedKeyTypeDisplayName = ''
break
}
if (votingState.isAddMining) {
if (votingState.newVotingKey) votingState.affectedKeyTypeDisplayName += ', voting'
if (votingState.newPayoutKey) votingState.affectedKeyTypeDisplayName += ', payout'
}
if (votingState.miningKey && votingState.miningKey !== '0x0000000000000000000000000000000000000000') {
const miningKeyLowerCase = votingState.miningKey.toLowerCase();
if (this.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
votingState.miningKey = this.validatorsMetadata[miningKeyLowerCase].lastNameAndKey;
}
}
} else if (contractType === "votingToChangeProxy") {
votingState.contractTypeDisplayName = ballotStore.ProxyBallotType[votingState.contractType];
}
if (votingState.miningKey && votingState.miningKey !== '0x0000000000000000000000000000000000000000') {
const miningKeyLowerCase = votingState.miningKey.toLowerCase()
if (this.validatorsMetadata.hasOwnProperty(miningKeyLowerCase)) {
votingState.miningKey = this.validatorsMetadata[miningKeyLowerCase].lastNameAndKey
}
}
} else if (contractType === 'votingToChangeProxy') {
votingState.contractTypeDisplayName = ballotStore.ProxyBallotType[votingState.contractType]
}
return votingState;
}
return votingState
}
getCard = async (id, contractType) => {
let votingState;
try {
votingState = await this[contractType].getBallotInfo(id, this.votingKey);
votingState = this.fillCardVotingState(votingState, contractType);
} catch(e) {
console.log(e.message);
}
getCard = async (id, contractType) => {
let votingState
try {
votingState = await this[contractType].getBallotInfo(id, this.votingKey)
votingState = this.fillCardVotingState(votingState, contractType)
} catch (e) {
console.log(e.message)
}
let card;
switch(contractType) {
case "votingToChangeKeys":
card = <BallotKeysCard
id={id}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
case "votingToChangeMinThreshold":
card = <BallotMinThresholdCard
id={id}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
case "votingToChangeProxy":
card = <BallotProxyCard
id={id}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
default:
break;
}
let card
switch (contractType) {
case 'votingToChangeKeys':
card = (
<BallotKeysCard
id={id}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}
/>
)
break
case 'votingToChangeMinThreshold':
card = (
<BallotMinThresholdCard
id={id}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}
/>
)
break
case 'votingToChangeProxy':
card = (
<BallotProxyCard
id={id}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}
/>
)
break
default:
break
}
return card;
}
return card
}
getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) {
ballotsStore.ballotCards.push(await this.getCard(id, contractType));
}
}
getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) {
ballotsStore.ballotCards.push(await this.getCard(id, contractType))
}
}
@action("Get all keys next ballot ids")
getAllBallotsNextIDs = async () => {
const keysNextBallotId = this.votingToChangeKeys.nextBallotId();
const minThresholdNextBallotId = this.votingToChangeMinThreshold.nextBallotId();
const proxyNextBallotId = this.votingToChangeProxy.nextBallotId();
return Promise.all([keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId]);
}
@action('Get all keys next ballot ids')
getAllBallotsNextIDs = async () => {
const keysNextBallotId = this.votingToChangeKeys.nextBallotId()
const minThresholdNextBallotId = this.votingToChangeMinThreshold.nextBallotId()
const proxyNextBallotId = this.votingToChangeProxy.nextBallotId()
return Promise.all([keysNextBallotId, minThresholdNextBallotId, proxyNextBallotId])
}
@action
async getBallotsLimits() {
if(this.web3Instance && this.netId){
let setVotingToChangeKeys = this.setVotingToChangeKeys({web3Instance: this.web3Instance, netId: this.netId})
let setVotingToChangeMinThreshold = this.setVotingToChangeMinThreshold({web3Instance: this.web3Instance, netId: this.netId})
let setVotingToChangeProxy = this.setVotingToChangeProxy({web3Instance: this.web3Instance, netId: this.netId})
@action
async getBallotsLimits() {
if (this.web3Instance && this.netId) {
let setVotingToChangeKeys = this.setVotingToChangeKeys({ web3Instance: this.web3Instance, netId: this.netId })
let setVotingToChangeMinThreshold = this.setVotingToChangeMinThreshold({
web3Instance: this.web3Instance,
netId: this.netId
})
let setVotingToChangeProxy = this.setVotingToChangeProxy({ web3Instance: this.web3Instance, netId: this.netId })
await Promise.all([setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy]);
await Promise.all([setVotingToChangeKeys, setVotingToChangeMinThreshold, setVotingToChangeProxy])
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.web3Instance.eth.defaultAccount);
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(this.web3Instance.eth.defaultAccount);
let getProxyLimit = await this.votingToChangeProxy.getBallotLimit(this.web3Instance.eth.defaultAccount);
let getKeysLimit = await this.votingToChangeKeys.getBallotLimit(this.web3Instance.eth.defaultAccount)
let getMinThresholdLimit = await this.votingToChangeMinThreshold.getBallotLimit(
this.web3Instance.eth.defaultAccount
)
let getProxyLimit = await this.votingToChangeProxy.getBallotLimit(this.web3Instance.eth.defaultAccount)
await Promise.all([getKeysLimit, getMinThresholdLimit, getProxyLimit])
.then(([keysLimit, minThresholdLimit, proxyLimit]) => {
this.validatorLimits.keys = keysLimit;
this.validatorLimits.minThreshold = minThresholdLimit;
this.validatorLimits.proxy = proxyLimit;
});
}
}
await Promise.all([getKeysLimit, getMinThresholdLimit, getProxyLimit]).then(
([keysLimit, minThresholdLimit, proxyLimit]) => {
this.validatorLimits.keys = keysLimit
this.validatorLimits.minThreshold = minThresholdLimit
this.validatorLimits.proxy = proxyLimit
}
)
}
}
@action
async getAllValidatorMetadata() {
this.validatorsMetadata[constants.NEW_MINING_KEY.value] = constants.NEW_MINING_KEY;
const keys = await this.poaConsensus.getValidators();
this.validatorsLength = keys.length;
keys.forEach(async (key) => {
const metadata = await this.validatorMetadata.getValidatorFullName({miningKey: key})
this.validatorsMetadata[key.toLowerCase()] = {
label: `${key} ${metadata.lastName}`,
lastNameAndKey: `${metadata.lastName} ${key}`,
fullName: `${metadata.firstName} ${metadata.lastName}`,
value: key
}
})
}
@action
async getAllValidatorMetadata() {
this.validatorsMetadata[constants.NEW_MINING_KEY.value] = constants.NEW_MINING_KEY
const keys = await this.poaConsensus.getValidators()
this.validatorsLength = keys.length
keys.forEach(async key => {
const metadata = await this.validatorMetadata.getValidatorFullName({ miningKey: key })
this.validatorsMetadata[key.toLowerCase()] = {
label: `${key} ${metadata.lastName}`,
lastNameAndKey: `${metadata.lastName} ${key}`,
fullName: `${metadata.firstName} ${metadata.lastName}`,
value: key
}
})
}
}
const contractsStore = new ContractsStore();
const contractsStore = new ContractsStore()
export default contractsStore;
export { ContractsStore };
export default contractsStore
export { ContractsStore }

View File

@ -1,31 +1,30 @@
import { observable, action } from 'mobx';
import { observable, action } from 'mobx'
class ValidatorStore {
@observable fullName
@observable address
@observable state
@observable zipCode
@observable licenseID
@observable licenseExpiration
@observable fullName;
@observable address;
@observable state;
@observable zipCode;
@observable licenseID;
@observable licenseExpiration;
constructor() {
this.fullName = ''
this.address = ''
this.state = ''
this.zipCode = ''
this.licenseID = ''
this.licenseExpiration = ''
}
constructor() {
this.fullName = "";
this.address = "";
this.state = "";
this.zipCode = "";
this.licenseID = "";
this.licenseExpiration = ""
}
@action("change validator metadata")
changeValidatorMetadata = (e, field) => {
this[field] = e ? (e.target ? e.target.value : e.value ? e.value : e) : "";
console.log("validator metadata", field, this[field])
}
@action('change validator metadata')
changeValidatorMetadata = (e, field) => {
this[field] = e ? (e.target ? e.target.value : e.value ? e.value : e) : ''
console.log('validator metadata', field, this[field])
}
}
const validatorStore = new ValidatorStore();
const validatorStore = new ValidatorStore()
export default validatorStore;
export { ValidatorStore };
export default validatorStore
export { ValidatorStore }