From 78cd2c2e571a5af086bf023b486771b65685c3a1 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 9 Apr 2018 13:19:22 +0300 Subject: [PATCH] Revert "(Fix) Change metadata zipcode from numeric to short string and other fixes" --- src/App.js | 6 +++--- src/Validator.js | 2 +- src/contracts/Metadata.contract.js | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index e22999b..4457841 100644 --- a/src/App.js +++ b/src/App.js @@ -43,7 +43,7 @@ class App extends Component { } async setMetadata(){ const currentData = await this.getMetadataContract().getValidatorData({votingKey: this.getVotingKey()}); - const hasData = currentData.postal_code ? true : false + const hasData = Number(currentData.postal_code) > 0 ? true : false this.defaultValues = currentData; const pendingChange = await this.getMetadataContract().getPendingChange({votingKey: this.getVotingKey()}); if(Number(pendingChange.minThreshold) > 0 ) { @@ -105,7 +105,7 @@ class App extends Component { var addressType = place[0].address_components[i].types[0]; switch(addressType) { case "postal_code": - address_components.postal_code = place[0].address_components[i].short_name; + address_components.postal_code = Number(place[0].address_components[i].short_name); break; case "street_number": address_components.street_number = place[0].address_components[i].short_name; @@ -217,7 +217,7 @@ class App extends Component {
- + diff --git a/src/Validator.js b/src/Validator.js index cf93078..90deb7e 100644 --- a/src/Validator.js +++ b/src/Validator.js @@ -7,7 +7,7 @@ class Validator extends Component { confirmation: null } this.props.metadataContract.getConfirmations({miningKey: this.props.address}).then((confirmation) => { - this.setState({confirmation: confirmation[0]}) + this.setState({confirmation}) }) } render(){ diff --git a/src/contracts/Metadata.contract.js b/src/contracts/Metadata.contract.js index 9fcf48d..85b23dc 100644 --- a/src/contracts/Metadata.contract.js +++ b/src/contracts/Metadata.contract.js @@ -51,7 +51,7 @@ export default class Metadata { this.web3_10.utils.fromAscii(licenseId), fullAddress, this.web3_10.utils.fromAscii(state), - this.web3_10.utils.fromAscii(zipcode), + zipcode, expirationDate ).send({from: votingKey, gasPrice}); } @@ -67,7 +67,7 @@ export default class Metadata { expirationDate: '2021-07-23', licenseId: '2206724', us_state: 'CA', - postal_code: '94404', + postal_code: 94404, } } @@ -82,10 +82,10 @@ export default class Metadata { let createdDate = validatorData.createdDate > 0 ? moment.unix(validatorData.createdDate).format('YYYY-MM-DD') : '' let updatedDate = validatorData.updatedDate > 0 ? moment.unix(validatorData.updatedDate).format('YYYY-MM-DD') : '' let expirationDate = validatorData.expirationDate > 0 ? moment.unix(validatorData.expirationDate).format('YYYY-MM-DD') : '' - if (validatorData.zipcode.length === 4) { + if(validatorData.zipcode.length === 4){ validatorData.zipcode = "0" + validatorData.zipcode; } - if (validatorData.zipcode === "0") { + if(validatorData.zipcode === "0"){ validatorData.zipcode = ''; } return { @@ -97,7 +97,7 @@ export default class Metadata { expirationDate, licenseId: toAscii(validatorData.licenseId), us_state: toAscii(validatorData.state), - postal_code: toAscii(validatorData.zipcode), + postal_code: validatorData.zipcode, } } @@ -141,6 +141,7 @@ export default class Metadata { let createdDate = pendingChanges.createdDate > 0 ? moment.unix(pendingChanges.createdDate).format('YYYY-MM-DD') : '' let updatedDate = pendingChanges.updatedDate > 0 ? moment.unix(pendingChanges.updatedDate).format('YYYY-MM-DD') : '' let expirationDate = pendingChanges.expirationDate > 0 ? moment.unix(pendingChanges.expirationDate).format('YYYY-MM-DD') : '' + let postal_code = Number(pendingChanges.zipcode) || '' return { firstName: toAscii(pendingChanges.firstName), lastName: toAscii(pendingChanges.lastName), @@ -150,7 +151,7 @@ export default class Metadata { expirationDate, licenseId: toAscii(pendingChanges.licenseId), us_state: toAscii(pendingChanges.state), - postal_code: toAscii(pendingChanges.zipcode), + postal_code, minThreshold: pendingChanges.minThreshold } } @@ -162,7 +163,7 @@ export default class Metadata { for (let key of miningKeys) { let pendingChange = await this.getPendingChange({miningKey: key}) pendingChange.address = key; - if (pendingChange.postal_code) { + if(pendingChange.postal_code > 0){ pendingChanges.push(pendingChange) } } @@ -200,7 +201,7 @@ export default class Metadata { async finalize({miningKeyToConfirm, senderVotingKey}) { const confirmations = await this.getConfirmations({miningKey: miningKeyToConfirm}); const getMinThreshold = await this.getMinThreshold({miningKey: miningKeyToConfirm}); - if(Number(confirmations[0]) < Number(getMinThreshold)){ + if(Number(confirmations) < Number(getMinThreshold)){ throw( {message: `There is not enough confimations.\n