diff --git a/src/App.js b/src/App.js index 2eb9ad7..a0b4694 100644 --- a/src/App.js +++ b/src/App.js @@ -43,14 +43,10 @@ class App extends Component { this.setIsValidVotingKey.call(this) } async setMetadata() { - const currentData = await this.getMetadataContract().getValidatorData({ - votingKey: this.getVotingKey() - }) + const currentData = await this.getMetadataContract().getValidatorData(this.getMiningKey()) const hasData = currentData.postal_code ? true : false this.defaultValues = currentData - const pendingChange = await this.getMetadataContract().getPendingChange({ - votingKey: this.getVotingKey() - }) + const pendingChange = await this.getMetadataContract().getPendingChange(this.getMiningKey()) if (Number(pendingChange.minThreshold) > 0) { var msg = ` First Name: ${pendingChange.firstName}
@@ -91,6 +87,9 @@ class App extends Component { getVotingKey() { return this.props.web3Config.votingKey } + getMiningKey() { + return this.props.web3Config.miningKey + } checkValidation() { const isAfter = moment(this.state.form.expirationDate).isAfter(moment()) let keys = Object.keys(this.state.form) diff --git a/src/contracts/KeysManager.contract.js b/src/contracts/KeysManager.contract.js index 2cf45ba..32d2674 100644 --- a/src/contracts/KeysManager.contract.js +++ b/src/contracts/KeysManager.contract.js @@ -15,4 +15,7 @@ export default class KeysManager { async isVotingActive(votingKey) { return await this.keysInstance.methods.isVotingActive(votingKey).call() } + async miningKeyByVoting(votingKey) { + return await this.keysInstance.methods.miningKeyByVoting(votingKey).call() + } } diff --git a/src/contracts/Metadata.contract.js b/src/contracts/Metadata.contract.js index 8388316..ef42b16 100644 --- a/src/contracts/Metadata.contract.js +++ b/src/contracts/Metadata.contract.js @@ -77,8 +77,7 @@ export default class Metadata { } } - async getValidatorData({ votingKey, miningKey }) { - miningKey = miningKey || (await this.getMiningByVoting(votingKey)) + async getValidatorData(miningKey) { if (!miningKey) { helpersGlobal.generateAlert('warning', 'Warning!', messages.invalidaVotingKey) return {} @@ -102,16 +101,6 @@ export default class Metadata { } } - async getMiningByVoting(votingKey) { - let miningKey - try { - miningKey = await this.metadataInstance.methods.getMiningByVotingKey(votingKey).call() - } catch (e) { - console.log(e.message) - } - return miningKey - } - async getAllValidatorsData(netId) { let all = [] return new Promise(async (resolve, reject) => { @@ -125,7 +114,7 @@ export default class Metadata { } data = this.getMocData() } else { - data = await this.getValidatorData({ miningKey: key }) + data = await this.getValidatorData(key) } data.address = key all.push(data) @@ -134,8 +123,7 @@ export default class Metadata { }) } - async getPendingChange({ votingKey, miningKey }) { - miningKey = miningKey || (await this.getMiningByVoting(votingKey)) + async getPendingChange(miningKey) { if (!miningKey) { helpersGlobal.generateAlert('warning', 'Warning!', messages.invalidaVotingKey) return {} @@ -163,7 +151,7 @@ export default class Metadata { async getAllPendingChanges() { let pendingChanges = [] for (let key of this.miningKeys) { - let pendingChange = await this.getPendingChange({ miningKey: key }) + let pendingChange = await this.getPendingChange(key) pendingChange.address = key if (pendingChange.postal_code) { pendingChanges.push(pendingChange) @@ -172,18 +160,24 @@ export default class Metadata { return pendingChanges } - async confirmPendingChange({ miningKeyToConfirm, senderVotingKey }) { - let alreadyConfirmed = await this.metadataInstance.methods - .isAddressAlreadyVoted(miningKeyToConfirm, senderVotingKey) - .call() + async confirmPendingChange({ miningKeyToConfirm, senderVotingKey, senderMiningKey }) { + let alreadyConfirmed + if (this.metadataInstance.methods.isValidatorAlreadyVoted) { + alreadyConfirmed = await this.metadataInstance.methods + .isValidatorAlreadyVoted(miningKeyToConfirm, senderMiningKey) + .call() + } else { + alreadyConfirmed = await this.metadataInstance.methods + .isAddressAlreadyVoted(miningKeyToConfirm, senderVotingKey) + .call() + } console.log(alreadyConfirmed) if (alreadyConfirmed) { throw { message: `You already confirmed this change.` } } - const miningKeySender = await this.getMiningByVoting(senderVotingKey) - if (miningKeySender === miningKeyToConfirm) { + if (senderMiningKey === miningKeyToConfirm) { throw { message: `You cannot confirm your own changes.\n Please ask other validators to verify your new information.` diff --git a/src/index.js b/src/index.js index 06a81a2..f3126b0 100644 --- a/src/index.js +++ b/src/index.js @@ -58,6 +58,7 @@ class AppMainRouter extends Component { metadataContract: null, poaConsensus: null, votingKey: null, + miningKey: null, loading: true, searchTerm: '', injectedWeb3: true, @@ -86,6 +87,7 @@ class AppMainRouter extends Component { }) this.setState({ votingKey: web3Config.defaultAccount, + miningKey: await keysManager.miningKeyByVoting(web3Config.defaultAccount), keysManager, metadataContract, loading: false, @@ -139,7 +141,8 @@ class AppMainRouter extends Component { try { let result = await this.state.metadataContract[methodToCall]({ miningKeyToConfirm: miningKey, - senderVotingKey: this.state.votingKey + senderVotingKey: this.state.votingKey, + senderMiningKey: this.state.miningKey }) console.log(result) this.setState({ loading: false })