Merge branch 'core' into enable-wallet-only-when-needed
This commit is contained in:
commit
557bc54778
|
@ -60,6 +60,7 @@ export class BallotCard extends React.Component {
|
||||||
@observable memo
|
@observable memo
|
||||||
@observable quorumState
|
@observable quorumState
|
||||||
@observable minBallotDuration
|
@observable minBallotDuration
|
||||||
|
@observable minThreshold
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
get cancelOrFinalizeButtonDisplayName() {
|
get cancelOrFinalizeButtonDisplayName() {
|
||||||
|
@ -303,6 +304,9 @@ export class BallotCard extends React.Component {
|
||||||
this.getHasAlreadyVoted()
|
this.getHasAlreadyVoted()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// minThreshold
|
||||||
|
this.getMinThreshold()
|
||||||
|
|
||||||
if (votingType === 'votingToManageEmissionFunds') {
|
if (votingType === 'votingToManageEmissionFunds') {
|
||||||
this.getQuorumState()
|
this.getQuorumState()
|
||||||
}
|
}
|
||||||
|
@ -318,6 +322,12 @@ export class BallotCard extends React.Component {
|
||||||
return formattedMs
|
return formattedMs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action('ballot min threshold of voters')
|
||||||
|
getMinThreshold = async () => {
|
||||||
|
const { contractsStore, id, votingType } = this.props
|
||||||
|
this.minThreshold = await this.getContract(contractsStore, votingType).getMinThresholdOfVoters(id)
|
||||||
|
}
|
||||||
|
|
||||||
@action('validator has already voted')
|
@action('validator has already voted')
|
||||||
getHasAlreadyVoted = async () => {
|
getHasAlreadyVoted = async () => {
|
||||||
const { contractsStore, id, votingType } = this.props
|
const { contractsStore, id, votingType } = this.props
|
||||||
|
@ -647,21 +657,6 @@ export class BallotCard extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getThreshold(contractsStore, votingType) {
|
|
||||||
switch (votingType) {
|
|
||||||
case 'votingToChangeKeys':
|
|
||||||
return contractsStore.keysBallotThreshold
|
|
||||||
case 'votingToChangeMinThreshold':
|
|
||||||
return contractsStore.minThresholdBallotThreshold
|
|
||||||
case 'votingToChangeProxy':
|
|
||||||
return contractsStore.proxyBallotThreshold
|
|
||||||
case 'votingToManageEmissionFunds':
|
|
||||||
return contractsStore.emissionFundsBallotThreshold
|
|
||||||
default:
|
|
||||||
return contractsStore.keysBallotThreshold
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getMinBallotDuration(contractsStore, votingType) {
|
getMinBallotDuration(contractsStore, votingType) {
|
||||||
switch (votingType) {
|
switch (votingType) {
|
||||||
case 'votingToChangeKeys':
|
case 'votingToChangeKeys':
|
||||||
|
@ -719,10 +714,9 @@ export class BallotCard extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { contractsStore, votingType, children } = this.props
|
let { votingType, children } = this.props
|
||||||
let votes
|
let votes
|
||||||
|
|
||||||
const threshold = this.getThreshold(contractsStore, votingType)
|
|
||||||
const networkBranch = this.getVotingNetworkBranch()
|
const networkBranch = this.getVotingNetworkBranch()
|
||||||
|
|
||||||
if (votingType === 'votingToManageEmissionFunds') {
|
if (votingType === 'votingToManageEmissionFunds') {
|
||||||
|
@ -781,12 +775,7 @@ export class BallotCard extends React.Component {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Votes networkBranch={networkBranch} votes={votes} />
|
<Votes networkBranch={networkBranch} votes={votes} />
|
||||||
<BallotInfoContainer
|
<BallotInfoContainer memo={this.memo} networkBranch={networkBranch} threshold={this.minThreshold} />
|
||||||
memo={this.memo}
|
|
||||||
networkBranch={networkBranch}
|
|
||||||
threshold={threshold}
|
|
||||||
validatorsLength={contractsStore.validatorsLength}
|
|
||||||
/>
|
|
||||||
<BallotFooter
|
<BallotFooter
|
||||||
buttonState={this.cancelOrFinalizeButtonState}
|
buttonState={this.cancelOrFinalizeButtonState}
|
||||||
buttonText={this.cancelOrFinalizeButtonDisplayName}
|
buttonText={this.cancelOrFinalizeButtonDisplayName}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export class BallotInfoContainer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { memo = '', threshold, validatorsLength, networkBranch } = this.props
|
let { memo = '', threshold, networkBranch } = this.props
|
||||||
let toggleShowMore =
|
let toggleShowMore =
|
||||||
memo.length > MAX_DETAILS_LENGTH ? (
|
memo.length > MAX_DETAILS_LENGTH ? (
|
||||||
<span
|
<span
|
||||||
|
@ -34,7 +34,7 @@ export class BallotInfoContainer extends React.Component {
|
||||||
return (
|
return (
|
||||||
<div className="bc-BallotInfoContainer">
|
<div className="bc-BallotInfoContainer">
|
||||||
<div className="bc-BallotInfoContainer_Info bc-BallotInfoContainer_Info-minimum">
|
<div className="bc-BallotInfoContainer_Info bc-BallotInfoContainer_Info-minimum">
|
||||||
Minimum {threshold} from {validatorsLength} validators are required to pass the proposal
|
Minimum {threshold} validators are required to pass the proposal
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`bc-BallotInfoContainer_Info bc-BallotInfoContainer_Info-details ${
|
className={`bc-BallotInfoContainer_Info bc-BallotInfoContainer_Info-details ${
|
||||||
|
|
|
@ -62,6 +62,10 @@ export default class VotingToChangeKeys {
|
||||||
return this.instance.methods.votingState(_id).call()
|
return this.instance.methods.votingState(_id).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMinThresholdOfVoters(_id) {
|
||||||
|
return this.instance.methods.getMinThresholdOfVoters(_id).call()
|
||||||
|
}
|
||||||
|
|
||||||
hasAlreadyVoted(_id, votingKey) {
|
hasAlreadyVoted(_id, votingKey) {
|
||||||
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,10 @@ export default class VotingToChangeMinThreshold {
|
||||||
return this.instance.methods.votingState(_id).call()
|
return this.instance.methods.votingState(_id).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMinThresholdOfVoters(_id) {
|
||||||
|
return this.instance.methods.getMinThresholdOfVoters(_id).call()
|
||||||
|
}
|
||||||
|
|
||||||
hasAlreadyVoted(_id, votingKey) {
|
hasAlreadyVoted(_id, votingKey) {
|
||||||
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,10 @@ export default class VotingToChangeProxy {
|
||||||
return this.instance.methods.votingState(_id).call()
|
return this.instance.methods.votingState(_id).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMinThresholdOfVoters(_id) {
|
||||||
|
return this.instance.methods.getMinThresholdOfVoters(_id).call()
|
||||||
|
}
|
||||||
|
|
||||||
hasAlreadyVoted(_id, votingKey) {
|
hasAlreadyVoted(_id, votingKey) {
|
||||||
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
return this.instance.methods.hasAlreadyVoted(_id, votingKey).call()
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,10 @@ export default class VotingToManageEmissionFunds {
|
||||||
return this.instance.methods.getBallotInfo(_id).call()
|
return this.instance.methods.getBallotInfo(_id).call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMinThresholdOfVoters(_id) {
|
||||||
|
return this.instance.methods.getMinThresholdOfVoters(_id).call()
|
||||||
|
}
|
||||||
|
|
||||||
getQuorumState(_id) {
|
getQuorumState(_id) {
|
||||||
return this.instance.methods.getQuorumState(_id).call()
|
return this.instance.methods.getQuorumState(_id).call()
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class AppMainRouter extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
initChain = () => {
|
initChain = () => {
|
||||||
const netId = window.localStorage.netId
|
const netId = window.sessionStorage.netId
|
||||||
getWeb3(netId, contractsStore.updateKeys)
|
getWeb3(netId, contractsStore.updateKeys)
|
||||||
.then(async web3Config => {
|
.then(async web3Config => {
|
||||||
await this.initialize(web3Config)
|
await this.initialize(web3Config)
|
||||||
|
@ -103,6 +103,7 @@ class AppMainRouter extends Component {
|
||||||
onNetworkChange = e => {
|
onNetworkChange = e => {
|
||||||
commonStore.showLoading(getNetworkBranch(e.value))
|
commonStore.showLoading(getNetworkBranch(e.value))
|
||||||
window.localStorage.netId = e.value
|
window.localStorage.netId = e.value
|
||||||
|
window.sessionStorage.netId = e.value
|
||||||
contractsStore.resetContracts()
|
contractsStore.resetContracts()
|
||||||
ballotsStore.reset()
|
ballotsStore.reset()
|
||||||
this.initChain()
|
this.initChain()
|
||||||
|
|
|
@ -22,9 +22,8 @@ export async function enableWallet(updateKeys) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function getWeb3(netId = defaultNetId, updateKeys) {
|
export default async function getWeb3(netId, updateKeys) {
|
||||||
let web3 = null
|
let web3 = null
|
||||||
netId = Number(netId)
|
|
||||||
|
|
||||||
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
|
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
|
||||||
if (window.ethereum) {
|
if (window.ethereum) {
|
||||||
|
@ -36,6 +35,32 @@ export default async function getWeb3(netId = defaultNetId, updateKeys) {
|
||||||
console.log('Injected web3 detected.')
|
console.log('Injected web3 detected.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!netId) {
|
||||||
|
// Load for the first time in the current browser's session
|
||||||
|
if (web3) {
|
||||||
|
// MetaMask (or another plugin) is injected
|
||||||
|
netId = await web3.eth.net.getId()
|
||||||
|
if (!(netId in constants.NETWORKS)) {
|
||||||
|
// If plugin's netId is unsupported, try to use
|
||||||
|
// the previously chosen netId
|
||||||
|
netId = window.localStorage.netId
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// MetaMask (or another plugin) is not injected,
|
||||||
|
// so try to use the previously chosen netId
|
||||||
|
netId = window.localStorage.netId
|
||||||
|
}
|
||||||
|
if (!(netId in constants.NETWORKS)) {
|
||||||
|
// If plugin's netId and/or previously chosen netId are not supported,
|
||||||
|
// fallback to default netId
|
||||||
|
netId = defaultNetId
|
||||||
|
}
|
||||||
|
window.localStorage.netId = netId
|
||||||
|
window.sessionStorage.netId = netId
|
||||||
|
}
|
||||||
|
|
||||||
|
netId = Number(netId)
|
||||||
|
|
||||||
const network = constants.NETWORKS[netId]
|
const network = constants.NETWORKS[netId]
|
||||||
const injectedWeb3 = web3 !== null
|
const injectedWeb3 = web3 !== null
|
||||||
let netIdName = network.NAME
|
let netIdName = network.NAME
|
||||||
|
@ -50,14 +75,16 @@ export default async function getWeb3(netId = defaultNetId, updateKeys) {
|
||||||
console.error('Unlock your wallet')
|
console.error('Unlock your wallet')
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentAccount = defaultAccount ? defaultAccount.toLowerCase() : ''
|
if (web3.currentProvider.publicConfigStore) {
|
||||||
web3.currentProvider.publicConfigStore.on('update', function(obj) {
|
let currentAccount = defaultAccount ? defaultAccount.toLowerCase() : ''
|
||||||
const account = obj.selectedAddress
|
web3.currentProvider.publicConfigStore.on('update', function(obj) {
|
||||||
if (account && account !== currentAccount) {
|
const account = obj.selectedAddress
|
||||||
currentAccount = account
|
if (account && account !== currentAccount) {
|
||||||
updateKeys(account)
|
currentAccount = account
|
||||||
}
|
updateKeys(account)
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const web3NetId = await web3.eth.net.getId()
|
const web3NetId = await web3.eth.net.getId()
|
||||||
if (web3NetId === netId) {
|
if (web3NetId === netId) {
|
||||||
|
|
Loading…
Reference in New Issue