make adding new contributors work
This commit is contained in:
parent
16eaafc688
commit
08b967978d
|
@ -12,7 +12,8 @@ class Admin extends React.Component {
|
||||||
contributorName: '',
|
contributorName: '',
|
||||||
contributorAddress: '',
|
contributorAddress: '',
|
||||||
busy: false,
|
busy: false,
|
||||||
error: ''
|
error: '',
|
||||||
|
successMsg: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
onChange = (name, e) => {
|
onChange = (name, e) => {
|
||||||
|
@ -21,10 +22,10 @@ class Admin extends React.Component {
|
||||||
|
|
||||||
addContributor = async (e) => {
|
addContributor = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({busy: true});
|
this.setState({busy: true, successMsg: ''});
|
||||||
try {
|
try {
|
||||||
await addContributor(this.state.contributorName, this.state.contributorAddress);
|
await addContributor(this.state.contributorName, this.state.contributorAddress);
|
||||||
this.setState({contributorName: '', contributorAddress: '', busy: false});
|
this.setState({busy: false, successMsg: 'Contributor added!'});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.setState({error: e.message || e, busy: false});
|
this.setState({error: e.message || e, busy: false});
|
||||||
}
|
}
|
||||||
|
@ -36,6 +37,7 @@ class Admin extends React.Component {
|
||||||
return (<div>
|
return (<div>
|
||||||
<h2>Admin Panel</h2>
|
<h2>Admin Panel</h2>
|
||||||
{error && <Alert variant="danger">{error}</Alert>}
|
{error && <Alert variant="danger">{error}</Alert>}
|
||||||
|
{successMsg && <Alert variant="success">{successMsg}</Alert>}
|
||||||
{busy && <Alert variant="primary">Working...</Alert>}
|
{busy && <Alert variant="primary">Working...</Alert>}
|
||||||
<h3>Add a contributor</h3>
|
<h3>Add a contributor</h3>
|
||||||
<ValidatedForm onSubmit={(e) => this.addContributor(e)}>
|
<ValidatedForm onSubmit={(e) => this.addContributor(e)}>
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Home extends React.Component {
|
||||||
|
|
||||||
this.setState({busy: false});
|
this.setState({busy: false});
|
||||||
} catch (e) {
|
} 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;
|
const maxAllocation = selectedContributors.length ? currentContributor.allocation / selectedContributors.length : 0;
|
||||||
|
|
||||||
return (<div>
|
return (<div>
|
||||||
{errorMsg && <Alert bsStyle="danger">{errorMsg}</Alert>}
|
{errorMsg && <Alert variant="danger">{errorMsg}</Alert>}
|
||||||
{busy && <p>Working...</p>}
|
{busy && <p>Working...</p>}
|
||||||
|
|
||||||
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
||||||
|
|
|
@ -8,20 +8,16 @@ const mainAccount = web3.eth.defaultAccount;
|
||||||
export function addContributor(name, address) {
|
export function addContributor(name, address) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
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();
|
const list = await getContributorList();
|
||||||
list.push({label: name, value: address});
|
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) {
|
} catch (e) {
|
||||||
const message = 'Error adding contributor';
|
const message = 'Error adding contributor';
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
@ -38,9 +34,9 @@ export function getContributorList(hash) {
|
||||||
hash = await Meritocracy.methods.contributorListIPFSHash().call();
|
hash = await Meritocracy.methods.contributorListIPFSHash().call();
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = await EmbarkJS.Storage.getUrl(hash);
|
const content = await EmbarkJS.Storage.get(hash);
|
||||||
const response = await axios.get(url);
|
const data = JSON.parse(content);
|
||||||
resolve(response.data.contributors);
|
resolve(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = 'Error getting contributor file on IPFS';
|
const message = 'Error getting contributor file on IPFS';
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
@ -53,12 +49,8 @@ export function getContributorList(hash) {
|
||||||
export function saveContributorList(list) {
|
export function saveContributorList(list) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const url = await EmbarkJS.Storage.getUrl(IPNS_HASH);
|
const newHash = await EmbarkJS.Storage.saveText(JSON.stringify(list));
|
||||||
console.log('Url', url);
|
resolve(newHash);
|
||||||
console.log('saving', {contributors: list});
|
|
||||||
const response = await axios.post(url, {contributors: list});
|
|
||||||
console.log(response.data);
|
|
||||||
resolve(response.data.contributors);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = 'Error saving contributor file on IPFS';
|
const message = 'Error saving contributor file on IPFS';
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
|
|
@ -8,7 +8,7 @@ function getContributors () {
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OG_IPFS_HASH = 'QmfWJJYFBJReu2rzTDzkBKXHazE52GVWrTcVNKdcupnxNH';
|
const OG_IPFS_HASH = 'QmREHBNWoJCx8KDz7PBAThv8mrxGRWimbzqZsL8aDzfLHW';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// default applies to all environments
|
// default applies to all environments
|
||||||
|
@ -128,7 +128,9 @@ module.exports = {
|
||||||
|
|
||||||
// Add All Contributors
|
// Add All Contributors
|
||||||
console.log('Adding all tokens...');
|
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});
|
gas = await addContributors.estimateGas({from: mainAccount});
|
||||||
await addContributors.send({from: mainAccount, gas});
|
await addContributors.send({from: mainAccount, gas});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue