From 08b967978db9d670fce1a6be22f02a1896423458 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 10 Apr 2019 13:52:00 -0400 Subject: [PATCH] make adding new contributors work --- app/js/components/Admin.js | 8 +++++--- app/js/components/Home.js | 4 ++-- app/js/services/Meritocracy.js | 30 +++++++++++------------------- config/contracts.js | 6 ++++-- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/app/js/components/Admin.js b/app/js/components/Admin.js index 24a70c5..09c2a49 100644 --- a/app/js/components/Admin.js +++ b/app/js/components/Admin.js @@ -12,7 +12,8 @@ class Admin extends React.Component { contributorName: '', contributorAddress: '', busy: false, - error: '' + error: '', + successMsg: '' }; onChange = (name, e) => { @@ -21,10 +22,10 @@ class Admin extends React.Component { addContributor = async (e) => { e.preventDefault(); - this.setState({busy: true}); + this.setState({busy: true, successMsg: ''}); try { await addContributor(this.state.contributorName, this.state.contributorAddress); - this.setState({contributorName: '', contributorAddress: '', busy: false}); + this.setState({busy: false, successMsg: 'Contributor added!'}); } catch (e) { this.setState({error: e.message || e, busy: false}); } @@ -36,6 +37,7 @@ class Admin extends React.Component { return (

Admin Panel

{error && {error}} + {successMsg && {successMsg}} {busy && Working...}

Add a contributor

this.addContributor(e)}> diff --git a/app/js/components/Home.js b/app/js/components/Home.js index 0d780a0..85937dd 100644 --- a/app/js/components/Home.js +++ b/app/js/components/Home.js @@ -53,7 +53,7 @@ class Home extends React.Component { this.setState({busy: false}); } catch (e) { - this.setState({errorMessage: e.message || e}); + this.setState({errorMsg: e.message || e}); } } @@ -192,7 +192,7 @@ class Home extends React.Component { const maxAllocation = selectedContributors.length ? currentContributor.allocation / selectedContributors.length : 0; return (
- {errorMsg && {errorMsg}} + {errorMsg && {errorMsg}} {busy &&

Working...

} {currentContributor.name &&

Hello, {currentContributor.name} !

} diff --git a/app/js/services/Meritocracy.js b/app/js/services/Meritocracy.js index fd5a408..599a211 100644 --- a/app/js/services/Meritocracy.js +++ b/app/js/services/Meritocracy.js @@ -8,20 +8,16 @@ const mainAccount = web3.eth.defaultAccount; export function addContributor(name, address) { return new Promise(async (resolve, reject) => { try { - const addContributor = Meritocracy.methods.addContributor(address); - let gas = await addContributor.estimateGas({from: mainAccount}); - console.log({gas}); - const receipt = await addContributor.send({from: mainAccount, gas: gas + 1000}); - - console.log({receipt}); - const list = await getContributorList(); list.push({label: name, value: address}); - console.log({list}); - await saveContributorList(list); + const newHash = await saveContributorList(list); - resolve(); + const addContributor = Meritocracy.methods.addContributor(address, newHash); + let gas = await addContributor.estimateGas({from: mainAccount}); + const receipt = await addContributor.send({from: mainAccount, gas: gas + 1000}); + + resolve(receipt); } catch (e) { const message = 'Error adding contributor'; console.error(message); @@ -38,9 +34,9 @@ export function getContributorList(hash) { hash = await Meritocracy.methods.contributorListIPFSHash().call(); } - const url = await EmbarkJS.Storage.getUrl(hash); - const response = await axios.get(url); - resolve(response.data.contributors); + const content = await EmbarkJS.Storage.get(hash); + const data = JSON.parse(content); + resolve(data); } catch (e) { const message = 'Error getting contributor file on IPFS'; console.error(message); @@ -53,12 +49,8 @@ export function getContributorList(hash) { export function saveContributorList(list) { return new Promise(async (resolve, reject) => { try { - const url = await EmbarkJS.Storage.getUrl(IPNS_HASH); - console.log('Url', url); - console.log('saving', {contributors: list}); - const response = await axios.post(url, {contributors: list}); - console.log(response.data); - resolve(response.data.contributors); + const newHash = await EmbarkJS.Storage.saveText(JSON.stringify(list)); + resolve(newHash); } catch (e) { const message = 'Error saving contributor file on IPFS'; console.error(message); diff --git a/config/contracts.js b/config/contracts.js index b8ee658..0d103f7 100644 --- a/config/contracts.js +++ b/config/contracts.js @@ -8,7 +8,7 @@ function getContributors () { return addresses; } -const OG_IPFS_HASH = 'QmfWJJYFBJReu2rzTDzkBKXHazE52GVWrTcVNKdcupnxNH'; +const OG_IPFS_HASH = 'QmREHBNWoJCx8KDz7PBAThv8mrxGRWimbzqZsL8aDzfLHW'; module.exports = { // default applies to all environments @@ -128,7 +128,9 @@ module.exports = { // Add All Contributors console.log('Adding all tokens...'); - const addContributors = Meritocracy.methods.addContributors(getContributors()); + const contributors = getContributors(); + contributors.push(mainAccount); + const addContributors = Meritocracy.methods.addContributors(contributors, OG_IPFS_HASH); gas = await addContributors.estimateGas({from: mainAccount}); await addContributors.send({from: mainAccount, gas});