Merge pull request #8 from rstormsf/v2

fix bug in error handling
This commit is contained in:
Victor 2017-12-14 21:49:18 -08:00 committed by GitHub
commit 508d191ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 15 deletions

View File

@ -122,9 +122,20 @@ export default class Metadata {
} }
async confirmPendingChange({miningKeyToConfirm, senderVotingKey}) { async confirmPendingChange({miningKeyToConfirm, senderVotingKey}) {
// you can't confirm your own let alreadyConfirmed = await this.metadataInstance.methods.isAddressAlreadyVoted(miningKeyToConfirm, senderVotingKey).call();
// you can't confirm twice console.log(alreadyConfirmed)
// if(alreadyConfirmed){
throw(
{message:
`You already confirmed this change.`})
}
const miningKeySender = await this.getMiningByVoting(senderVotingKey);
if(miningKeySender === miningKeyToConfirm){
throw(
{message:
`You cannot confirm your own changes.\n
Please ask other validators to verify your new information.`})
}
return await this.metadataInstance.methods.confirmPendingChange(miningKeyToConfirm).send({from: senderVotingKey}); return await this.metadataInstance.methods.confirmPendingChange(miningKeyToConfirm).send({from: senderVotingKey});
} }
@ -138,6 +149,14 @@ export default class Metadata {
} }
async finalize({miningKeyToConfirm, senderVotingKey}) { async finalize({miningKeyToConfirm, senderVotingKey}) {
const confirmations = await this.getConfirmations({miningKey: miningKeyToConfirm});
const getMinThreshold = await this.getMinThreshold({miningKey: miningKeyToConfirm});
if(Number(confirmations) < Number(getMinThreshold)){
throw(
{message:
`There is not enough confimations.\n
The minimum threshold to finalize is ${getMinThreshold}.`})
}
return await this.metadataInstance.methods.finalize(miningKeyToConfirm).send({from: senderVotingKey}); return await this.metadataInstance.methods.finalize(miningKeyToConfirm).send({from: senderVotingKey});
} }

View File

@ -2,14 +2,6 @@ let errorMsgNoMetamaskAccount = `You haven't chosen any account in MetaMask.
Please, choose your initial key in MetaMask and reload the page. Please, choose your initial key in MetaMask and reload the page.
Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.`; Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.`;
function generateElement(msg){
let errorNode = document.createElement("div");
errorNode.innerHTML = `<div>
${msg}
</div>`;
return errorNode;
}
let getWeb3 = () => { let getWeb3 = () => {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
// Wait for loading completion to avoid race conditions with web3 injection timing. // Wait for loading completion to avoid race conditions with web3 injection timing.
@ -28,7 +20,7 @@ let getWeb3 = () => {
case "12648430": case "12648430":
netIdName = 'Oracles' netIdName = 'Oracles'
console.log('This is oracles') console.log('This is oracles')
break break;
default: default:
netIdName = 'ERROR' netIdName = 'ERROR'
errorMsg = `You aren't connected to Oracles Network. errorMsg = `You aren't connected to Oracles Network.
@ -38,10 +30,10 @@ let getWeb3 = () => {
} }
var defaultAccount = web3.eth.defaultAccount || null; var defaultAccount = web3.eth.defaultAccount || null;
if(defaultAccount === null){ if(defaultAccount === null){
reject({msg: errorMsgNoMetamaskAccount, node: generateElement(errorMsgNoMetamaskAccount)}) reject({message: errorMsgNoMetamaskAccount})
} }
if(errorMsg !== null){ if(errorMsg !== null){
reject({msg: errorMsg, node: generateElement(errorMsg)}) reject({message: errorMsg})
} }
results = { results = {
web3Instance: web3, web3Instance: web3,
@ -56,7 +48,7 @@ let getWeb3 = () => {
console.log('Injected web3 detected.'); console.log('Injected web3 detected.');
} else { } else {
reject({msg: errorMsgNoMetamaskAccount, node: generateElement(errorMsgNoMetamaskAccount)}) reject({message: errorMsgNoMetamaskAccount})
console.error('Metamask not found'); console.error('Metamask not found');
} }
}) })