make adding new contributors work
This commit is contained in:
parent
16eaafc688
commit
08b967978d
|
@ -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 (<div>
|
||||
<h2>Admin Panel</h2>
|
||||
{error && <Alert variant="danger">{error}</Alert>}
|
||||
{successMsg && <Alert variant="success">{successMsg}</Alert>}
|
||||
{busy && <Alert variant="primary">Working...</Alert>}
|
||||
<h3>Add a contributor</h3>
|
||||
<ValidatedForm onSubmit={(e) => this.addContributor(e)}>
|
||||
|
|
|
@ -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 (<div>
|
||||
{errorMsg && <Alert bsStyle="danger">{errorMsg}</Alert>}
|
||||
{errorMsg && <Alert variant="danger">{errorMsg}</Alert>}
|
||||
{busy && <p>Working...</p>}
|
||||
|
||||
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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});
|
||||
|
||||
|
|
Loading…
Reference in New Issue