From ede863ce13891461611f8c4454d638fc304ef665 Mon Sep 17 00:00:00 2001 From: Narek Harutyunyan Date: Mon, 8 Jan 2018 15:49:21 +0400 Subject: [PATCH 01/11] Fixed #9 - Added Network selector --- src/App.js | 4 ++++ src/PrepareForm.js | 2 ++ src/SelectNetwork.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/SelectNetwork.js diff --git a/src/App.js b/src/App.js index 0e368dc..b34da3d 100644 --- a/src/App.js +++ b/src/App.js @@ -404,6 +404,10 @@ class App extends Component { this.setState({collateral_txhash: value}, this.waitForConfirmations); } + else if (name === 'networkSelector') + { + this.updateNetwork(target.value); + } else { // make sure numbers are numbers diff --git a/src/PrepareForm.js b/src/PrepareForm.js index 7fccd4a..ed4f8c6 100644 --- a/src/PrepareForm.js +++ b/src/PrepareForm.js @@ -24,6 +24,7 @@ import React, { Component } from 'react'; import TextInputField from './TextInputField.js'; import SelectFirstPayment from './SelectFirstPayment.js'; import SelectPaymentCycles from './SelectPaymentCycles.js'; +import SelectNetwork from './SelectNetwork.js'; import DisplayTotal from './DisplayTotal.js'; import ValidationError from './ValidationError.js'; import PreparedProposal from './PreparedProposal.js'; @@ -59,6 +60,7 @@ class PrepareForm extends Component + diff --git a/src/SelectNetwork.js b/src/SelectNetwork.js new file mode 100644 index 0000000..2eec788 --- /dev/null +++ b/src/SelectNetwork.js @@ -0,0 +1,33 @@ +/* Energi Proposal Creator +*/ + +import React, { Component } from 'react'; + +class SelectNetwork extends Component +{ + getNetworks() + { + let htmlOptionTags = []; + htmlOptionTags.push(); + htmlOptionTags.push(); + htmlOptionTags.push(); + return htmlOptionTags; + } + + render() + { + let props = this.props; + return ( +
+ +
+ ); + } +} + +export default SelectNetwork; From 413824ec64357297c9fe1656e3ca089f5b8f4da7 Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Tue, 16 Jan 2018 13:43:02 -0700 Subject: [PATCH 02/11] changing ticker symbol to NRG --- src/App.js | 2 +- src/DisplayTotal.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 0e368dc..b9d4d2a 100644 --- a/src/App.js +++ b/src/App.js @@ -319,7 +319,7 @@ class App extends Component const payment_amount = state.gobj[0][1].payment_amount; if (payment_amount > maximumBudgetAmount) { - setError("Payment amount exceeds maximum budget of " + maximumBudgetAmount.toString() + " EGI"); + setError("Payment amount exceeds maximum budget of " + maximumBudgetAmount.toString() + " NRG"); return false; } if (payment_amount <= 0) diff --git a/src/DisplayTotal.js b/src/DisplayTotal.js index 7c503b8..458aaee 100644 --- a/src/DisplayTotal.js +++ b/src/DisplayTotal.js @@ -65,7 +65,7 @@ class DisplayTotal extends Component return (
- Total: {this.get_total()} EGI {this.get_date_str()} + Total: {this.get_total()} NRG {this.get_date_str()}
); } From 17aa45f770f5c12582379ec647d3c7127cd2e9f2 Mon Sep 17 00:00:00 2001 From: Narek Harutyunyan Date: Sat, 20 Jan 2018 15:53:04 +0400 Subject: [PATCH 03/11] Fixed #8 Fixed the warnings + small functionality fix --- src/App.js | 29 +++++++++++++++-------------- src/DisplayTotal.js | 4 +--- src/PreparedProposal.js | 2 -- src/SubmitProposalForm.js | 2 -- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/App.js b/src/App.js index b9d4d2a..80ea4b8 100644 --- a/src/App.js +++ b/src/App.js @@ -81,7 +81,7 @@ class App extends Component function() { this.apiSyncState++; - if (this.apiSyncState == 2) this.initializeEpochs(); + if (this.apiSyncState === 2) this.initializeEpochs(); } ); return responseData; @@ -97,7 +97,7 @@ class App extends Component getBestBlock() { - function getBlock(hash) + var getBlock = function(hash) { return fetch(this.explorerAPI + 'getblock?hash=' + hash) .then((resp) => { @@ -108,7 +108,7 @@ class App extends Component function() { this.apiSyncState++; - if (this.apiSyncState == 2) this.initializeEpochs(); + if (this.apiSyncState === 2) this.initializeEpochs(); } ); return responseData; @@ -122,7 +122,7 @@ class App extends Component .catch(err => {this.setError("Unable to fetch current blockchain information. Please try again later. " + err.toString())}); } - function getHash(height) + var getHash = function(height) { return fetch(this.explorerAPI + 'getblockhash?index=' + Number(height).toString()) .then((resp) => { @@ -141,7 +141,7 @@ class App extends Component .catch(err => {this.setError("Unable to fetch current blockchain information. Please try again later. " + err.toString())}); } - function getHeight() + var getHeight = function() { return fetch(this.explorerAPI + 'getblockcount') .then((resp) => { @@ -167,7 +167,7 @@ class App extends Component updateNetwork(networkName) { - function fetchBlockchainInfo() + var fetchBlockchainInfo = function() { this.getGovernanceInfo(); this.getBestBlock(); @@ -178,7 +178,7 @@ class App extends Component this.setState({network: networkName}, function() { if (this.state.network === 'main') this.explorerAPI = 'https://explore.energi.network/api/'; - else if (this.state.network == 'test') this.explorerAPI = 'http://explore.test.energi.network/api/'; + else if (this.state.network === 'test') this.explorerAPI = 'http://explore.test.energi.network/api/'; else if (this.state.network === 'test60x') this.explorerAPI = 'http://explore.test60x.energi.network/api/'; else this.setError("Invalid network"); @@ -193,9 +193,9 @@ class App extends Component return new Promise(resolve => setTimeout(resolve, ms)); } - async function waitForSync() + var waitForSync = async function() { - while (this.apiSyncState != 2) await sleep(100); + while (this.apiSyncState !== 2) await sleep(100); } waitForSync = waitForSync.bind(this); @@ -207,7 +207,7 @@ class App extends Component let new_gobj = this.state.gobj; new_gobj[0][1].start_epoch = initial_epoch; new_gobj[0][1].end_epoch = initial_epoch + (gov.superblockcycle * 60); - this.setState({gobj: new_gobj}, this.validateNewState()); + this.setState({gobj: new_gobj}, this.validateNewState); } componentDidMount() @@ -350,11 +350,12 @@ class App extends Component result = result && validateProposalAddress(this.setError, this.state); result = result && validateProposalAmount(this.setError, this.state); result = result && validateProposalType(this.setError, this.state); + return result; } waitForConfirmations() { - function fetchConfirmations() + var fetchConfirmations = function() { return fetch(this.explorerAPI + 'getrawtransaction?txid=' + this.state.collateral_txhash + '&decrypt=1') .then((resp) => { @@ -379,7 +380,7 @@ class App extends Component return new Promise(resolve => setTimeout(resolve, ms)); } - async function checkConfirmations() + var checkConfirmations = async function() { while (this.state.confirmations < 6) { @@ -428,7 +429,7 @@ class App extends Component new_state.gobj[0][1].end_epoch = new_state.gobj[0][1].start_epoch + (new_state.payment_cycles * this.state.governanceInfo.superblockcycle * 60); } - this.setState(new_state, this.validateNewState()); + this.setState(new_state, this.validateNewState); } } @@ -436,7 +437,7 @@ class App extends Component { const dateTime = new Date().getTime(); const timestamp = Math.floor(dateTime / 1000); - this.setState({submitted: true, proposalTime: timestamp}, this.validateNewState()); + this.setState({submitted: true, proposalTime: timestamp}, this.validateNewState); } render() diff --git a/src/DisplayTotal.js b/src/DisplayTotal.js index 458aaee..282e79a 100644 --- a/src/DisplayTotal.js +++ b/src/DisplayTotal.js @@ -49,7 +49,7 @@ class DisplayTotal extends Component const start_epoch = this.props.gobj[0][1].start_epoch; const end_epoch = this.props.gobj[0][1].end_epoch; - if (this.props.payment_cycles == 1) + if (this.props.payment_cycles === 1) { return "at " + format_date(start_epoch); } @@ -59,8 +59,6 @@ class DisplayTotal extends Component render() { - let props = this.props; - if (this.props.gobj[0][1].payment_amount <= 0) return null; return ( diff --git a/src/PreparedProposal.js b/src/PreparedProposal.js index b8c058f..b80977a 100644 --- a/src/PreparedProposal.js +++ b/src/PreparedProposal.js @@ -43,8 +43,6 @@ class PreparedProposal extends Component render() { - let props = this.props; - if (!this.props.submitted || (this.props.validationError !== '')) return null; return ( diff --git a/src/SubmitProposalForm.js b/src/SubmitProposalForm.js index 68548f2..5501dfc 100644 --- a/src/SubmitProposalForm.js +++ b/src/SubmitProposalForm.js @@ -42,8 +42,6 @@ class SubmitProposalForm extends Component render() { - let props = this.props; - if (this.props.confirmations < 6) return null; return ( From daa0d2080abe8b397bdb1d9ec4195aaa1375814e Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Fri, 9 Feb 2018 14:53:20 -0700 Subject: [PATCH 04/11] commented out mainnet option and made 60x testnet the default for now --- src/SelectNetwork.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SelectNetwork.js b/src/SelectNetwork.js index 2eec788..9bbf218 100644 --- a/src/SelectNetwork.js +++ b/src/SelectNetwork.js @@ -8,9 +8,9 @@ class SelectNetwork extends Component getNetworks() { let htmlOptionTags = []; - htmlOptionTags.push(); - htmlOptionTags.push(); + //htmlOptionTags.push(); htmlOptionTags.push(); + htmlOptionTags.push(); return htmlOptionTags; } From fc492178402d7e3bfc9208bf06558dd709f285e0 Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Tue, 27 Mar 2018 12:15:37 -0600 Subject: [PATCH 05/11] fetching data for superblock budgets --- src/App.js | 87 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/src/App.js b/src/App.js index e8e278c..40585a2 100644 --- a/src/App.js +++ b/src/App.js @@ -64,35 +64,78 @@ class App extends Component this.waitForConfirmations = this.waitForConfirmations.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); - this.getGovernanceInfo = this.getGovernanceInfo.bind(this); + this.getSuperblockInfo = this.getSuperblockInfo.bind(this); this.getBestBlock = this.getBestBlock.bind(this); this.updateNetwork = this.updateNetwork.bind(this); this.initializeEpochs = this.initializeEpochs.bind(this); } - getGovernanceInfo() + getSuperblockInfo() { - return fetch(this.explorerAPI + 'getgovernanceinfo') - .then((resp) => { - if (resp.ok) { + var getGovernanceInfo = function() + { + return fetch(this.explorerAPI + 'getgovernanceinfo') + .then((resp) => { + if (resp.ok) { + return resp.json() + .then((responseData) => { + this.setState({governanceInfo: responseData}, + function() + { + getSuperblockBudget(); + } + ); + return responseData; + }); + } return resp.json() - .then((responseData) => { - this.setState({governanceInfo: responseData}, - function() - { - this.apiSyncState++; - if (this.apiSyncState === 2) this.initializeEpochs(); - } - ); - return responseData; + .then((error) => { + return Promise.reject(error); }); - } - return resp.json() - .then((error) => { - return Promise.reject(error); - }); - }) - .catch(err => {this.setError("Unable to fetch current blockchain information. Please try again later. " + err.toString())}); + }) + .catch(err => {this.setError("Unable to fetch current blockchain information. Please try again later. " + err.toString())}); + } + + var getSuperblockBudget = function(depth = 0) + { + const maxDepth = 26; + const superblockNumber = this.state.governanceInfo.nextsuperblock + (depth * this.state.governanceInfo.superblockcycle); + return fetch(this.explorerAPI + 'getsuperblockbudget/' + superblockNumber) + .then((resp) => { + if (resp.ok) { + return resp.json() + .then((responseData) => { + var superblockBudgets = this.state.superblockBudgets || []; + superblockBudgets[depth] = responseData; + this.setState({superblockBudgets: superblockBudgets}, + function() + { + if (depth === (maxDepth - 1)) + { + this.apiSyncState++; + if (this.apiSyncState === 2) this.initializeEpochs(); + } + else + { + getSuperblockBudget(depth + 1); + } + } + ); + return responseData; + }); + } + return resp.json() + .then((error) => { + return Promise.reject(error); + }); + }) + .catch(err => {this.setError("Unable to fetch current blockchain information. Please try again later. " + err.toString())}); + } + + getGovernanceInfo = getGovernanceInfo.bind(this); + getSuperblockBudget = getSuperblockBudget.bind(this); + + getGovernanceInfo(); } getBestBlock() @@ -169,7 +212,7 @@ class App extends Component { var fetchBlockchainInfo = function() { - this.getGovernanceInfo(); + this.getSuperblockInfo(); this.getBestBlock(); } From 8332edfcf9d645726b60a417fc370074d27ecbdd Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Tue, 27 Mar 2018 17:08:12 -0600 Subject: [PATCH 06/11] we actually need 52 superblock budgets --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 40585a2..5124333 100644 --- a/src/App.js +++ b/src/App.js @@ -98,7 +98,7 @@ class App extends Component var getSuperblockBudget = function(depth = 0) { - const maxDepth = 26; + const maxDepth = 52; const superblockNumber = this.state.governanceInfo.nextsuperblock + (depth * this.state.governanceInfo.superblockcycle); return fetch(this.explorerAPI + 'getsuperblockbudget/' + superblockNumber) .then((resp) => { From 6cce15b09300c3f1d30a68a7451d31dfa2d5e0b9 Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Tue, 27 Mar 2018 17:08:29 -0600 Subject: [PATCH 07/11] use getsuperblockbudget api to determine maximum proposal amount --- src/App.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 5124333..f55c915 100644 --- a/src/App.js +++ b/src/App.js @@ -358,7 +358,11 @@ class App extends Component function validateProposalAmount(setError, state) { - const maximumBudgetAmount = state.governanceInfo.lastsuperblock === 0 ? 4000000 : 184000; + const nextSuperblockTime = ((state.governanceInfo.nextsuperblock - state.bestBlock.height) * 60) + state.bestBlock.time; + const superblockIndex = (state.gobj[0][1].start_epoch - nextSuperblockTime) / 60 / state.governanceInfo.superblockcycle; + let needed_budgets = state.superblockBudgets.slice(superblockIndex, superblockIndex + state.payment_cycles); + const maximumBudgetAmount = Math.min(...needed_budgets); + const payment_amount = state.gobj[0][1].payment_amount; if (payment_amount > maximumBudgetAmount) { From ca552c71ab1fd087514c1fddf1feb49a449d849d Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Sun, 29 Apr 2018 14:34:20 -0600 Subject: [PATCH 08/11] set default network to main net, enable main net in network selector, disable 60x testnet --- src/App.js | 4 ++-- src/SelectNetwork.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index f55c915..c56c865 100644 --- a/src/App.js +++ b/src/App.js @@ -222,7 +222,7 @@ class App extends Component { if (this.state.network === 'main') this.explorerAPI = 'https://explore.energi.network/api/'; else if (this.state.network === 'test') this.explorerAPI = 'http://explore.test.energi.network/api/'; - else if (this.state.network === 'test60x') this.explorerAPI = 'http://explore.test60x.energi.network/api/'; + //else if (this.state.network === 'test60x') this.explorerAPI = 'http://explore.test60x.energi.network/api/'; else this.setError("Invalid network"); fetchBlockchainInfo(); @@ -257,7 +257,7 @@ class App extends Component { document.title = "Energi Proposal Creator"; - this.updateNetwork('test60x'); + this.updateNetwork('main'); } setError(errStr) diff --git a/src/SelectNetwork.js b/src/SelectNetwork.js index 9bbf218..ba3a38f 100644 --- a/src/SelectNetwork.js +++ b/src/SelectNetwork.js @@ -8,8 +8,8 @@ class SelectNetwork extends Component getNetworks() { let htmlOptionTags = []; - //htmlOptionTags.push(); - htmlOptionTags.push(); + htmlOptionTags.push(); + //htmlOptionTags.push(); htmlOptionTags.push(); return htmlOptionTags; } From 45b890c6ee63e84a02e54fd6111cfe2f04a6729b Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Sun, 29 Apr 2018 14:36:52 -0600 Subject: [PATCH 09/11] fixing explorer api urls for testnets --- src/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index c56c865..3f92a3f 100644 --- a/src/App.js +++ b/src/App.js @@ -221,8 +221,8 @@ class App extends Component this.setState({network: networkName}, function() { if (this.state.network === 'main') this.explorerAPI = 'https://explore.energi.network/api/'; - else if (this.state.network === 'test') this.explorerAPI = 'http://explore.test.energi.network/api/'; - //else if (this.state.network === 'test60x') this.explorerAPI = 'http://explore.test60x.energi.network/api/'; + else if (this.state.network === 'test') this.explorerAPI = 'https://explore.test.energi.network/api/'; + //else if (this.state.network === 'test60x') this.explorerAPI = 'https://explore.test60x.energi.network/api/'; else this.setError("Invalid network"); fetchBlockchainInfo(); From dfc46159369883891b2d483f4642071a56b7729e Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Sun, 29 Apr 2018 14:37:01 -0600 Subject: [PATCH 10/11] newline at end of file --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd36b56..120b32f 100644 --- a/package.json +++ b/package.json @@ -13,4 +13,4 @@ "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } -} \ No newline at end of file +} From dfef83b7da500a1075200084731ff343c2037d2b Mon Sep 17 00:00:00 2001 From: Ryan Lucchese Date: Sun, 29 Apr 2018 14:41:42 -0600 Subject: [PATCH 11/11] updating packages --- package-lock.json | 12 ++++++------ package.json | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0813c91..819fa02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8009,9 +8009,9 @@ } }, "react": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.2.0.tgz", - "integrity": "sha512-ZmIomM7EE1DvPEnSFAHZn9Vs9zJl5A9H7el0EGTE6ZbW9FKe/14IYAlPbC8iH25YarEQxZL+E8VW7Mi7kfQrDQ==", + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react/-/react-16.3.2.tgz", + "integrity": "sha512-o5GPdkhciQ3cEph6qgvYB7LTOHw/GB0qRI6ZFNugj49qJCFfgHwVNjZ5u+b7nif4vOeMIOuYj3CeYe2IBD74lg==", "requires": { "fbjs": "0.8.16", "loose-envify": "1.3.1", @@ -8045,9 +8045,9 @@ } }, "react-dom": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.2.0.tgz", - "integrity": "sha512-zpGAdwHVn9K0091d+hr+R0qrjoJ84cIBFL2uU60KvWBPfZ7LPSrfqviTxGHWN0sjPZb2hxWzMexwrvJdKePvjg==", + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.3.2.tgz", + "integrity": "sha512-MMPko3zYncNrz/7gG17wJWUREZDvskZHXOwbttzl0F0L3wDmToyuETuo/r8Y5yvDejwYcRyWI1lvVBjLJWFwKA==", "requires": { "fbjs": "0.8.16", "loose-envify": "1.3.1", diff --git a/package.json b/package.json index 120b32f..7a6a14c 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { - "react": "^16.2.0", - "react-dom": "^16.2.0", + "react": "^16.3.2", + "react-dom": "^16.3.2", "react-scripts": "1.0.17" }, "scripts": {