mirror of
https://github.com/status-im/meritocracy.git
synced 2025-02-17 16:16:29 +00:00
check for network, and list praises
This commit is contained in:
parent
cc913bf21e
commit
418ccee9d7
@ -18,6 +18,9 @@ TODO:
|
|||||||
- listen to events to update UI, (initially on page load but within function calls)
|
- listen to events to update UI, (initially on page load but within function calls)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const MAINNET = 1;
|
||||||
|
const TESTNET = 3;
|
||||||
|
|
||||||
// Todo Resolve ENS entries
|
// Todo Resolve ENS entries
|
||||||
const options = [
|
const options = [
|
||||||
{ 'label' : 'Jarrad (Test)', 'value' : '0x061b0227116e76025D5573cFbb1Ac854916286Fe' },
|
{ 'label' : 'Jarrad (Test)', 'value' : '0x061b0227116e76025D5573cFbb1Ac854916286Fe' },
|
||||||
@ -82,7 +85,8 @@ class App extends React.Component {
|
|||||||
status: []
|
status: []
|
||||||
},
|
},
|
||||||
award: 0,
|
award: 0,
|
||||||
praise: ''
|
praise: '',
|
||||||
|
networkName: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -97,11 +101,19 @@ class App extends React.Component {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
EmbarkJS.onReady(async (err) => {
|
EmbarkJS.onReady(async (err) => {
|
||||||
// TODO: check for chain
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return this.setState({error: err.message || err});
|
return this.setState({error: err.message || err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const netId = await web3.eth.net.getId();
|
||||||
|
if (EmbarkJS.environment === 'testnet' && netId !== TESTNET) {
|
||||||
|
this.setState({ error: 'Please connect to Ropsten' });
|
||||||
|
return;
|
||||||
|
} else if (EmbarkJS.environment === 'livenet' && netId !== MAINNET) {
|
||||||
|
this.setState({ error: 'Please connect to Mainnet' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({busy: false});
|
this.setState({busy: false});
|
||||||
|
|
||||||
this.getCurrentContributorData();
|
this.getCurrentContributorData();
|
||||||
@ -133,16 +145,31 @@ class App extends React.Component {
|
|||||||
error: '',
|
error: '',
|
||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
award: 0
|
award: 0
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCurrentContributorData(){
|
async getCurrentContributorData(){
|
||||||
const currentContributor = await this.getContributor(web3.eth.defaultAccount);
|
const currentContributor = await this.getContributor(web3.eth.defaultAccount);
|
||||||
|
|
||||||
|
let praises = [];
|
||||||
|
for(let i = 0; i < currentContributor.praiseNum; i++){
|
||||||
|
praises.push(Meritocracy.methods.getStatus(web3.eth.defaultAccount, i).call());
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(currentContributor);
|
||||||
|
currentContributor.praises = await Promise.all(praises);
|
||||||
|
currentContributor.allocation = web3.utils.fromWei(currentContributor.allocation, "ether");
|
||||||
|
currentContributor.totalForfeited = web3.utils.fromWei(currentContributor.totalForfeited, "ether");
|
||||||
|
currentContributor.totalReceived = web3.utils.fromWei(currentContributor.totalReceived, "ether");
|
||||||
|
currentContributor.received = web3.utils.fromWei(currentContributor.received, "ether");
|
||||||
|
|
||||||
this.setState({currentContributor});
|
this.setState({currentContributor});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getContributor(_address) {
|
async getContributor(_address) {
|
||||||
return await Meritocracy.methods.contributors(_address).call();
|
const contributor = await Meritocracy.methods.contributors(_address).call();
|
||||||
|
contributor.praiseNum = await Meritocracy.methods.getStatusLength(_address).call();
|
||||||
|
return contributor;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getContributors() {
|
async getContributors() {
|
||||||
@ -162,16 +189,18 @@ class App extends React.Component {
|
|||||||
|
|
||||||
let addresses = selectedContributors.map(a => a.value);
|
let addresses = selectedContributors.map(a => a.value);
|
||||||
|
|
||||||
|
const sntAmount = web3.utils.toWei(award.toString(), "ether");
|
||||||
|
|
||||||
let toSend;
|
let toSend;
|
||||||
switch(addresses.length) {
|
switch(addresses.length) {
|
||||||
case 0:
|
case 0:
|
||||||
this.setState({errorMsg: 'No Contributor Selected'});
|
this.setState({errorMsg: 'No Contributor Selected'});
|
||||||
return;
|
return;
|
||||||
case 1:
|
case 1:
|
||||||
toSend = Meritocracy.methods.award(addresses[0], award, praise);
|
toSend = Meritocracy.methods.award(addresses[0], sntAmount, praise);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
toSend = Meritocracy.methods.awardContributors(addresses, award, praise);
|
toSend = Meritocracy.methods.awardContributors(addresses, sntAmount, praise);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,9 +209,8 @@ class App extends React.Component {
|
|||||||
|
|
||||||
const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
|
const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
|
||||||
const receipt = await toSend.send({from: web3.eth.defaultAccount, gas: estimatedGas + 1000});
|
const receipt = await toSend.send({from: web3.eth.defaultAccount, gas: estimatedGas + 1000});
|
||||||
|
|
||||||
this.getCurrentContributorData();
|
|
||||||
this.resetUIFields();
|
this.resetUIFields();
|
||||||
|
this.getCurrentContributorData();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
this.setState({errorMsg: 'tx failed? got enough tokens to award?'});
|
this.setState({errorMsg: 'tx failed? got enough tokens to award?'});
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -224,7 +252,7 @@ class App extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedContributors, contributorList, award, currentContributor, busy, error, errorMsg } = this.state;
|
const { selectedContributors, contributorList, award, currentContributor, busy, error, errorMsg } = this.state;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (<div>
|
return (<div>
|
||||||
<div>Something went wrong connecting to ethereum. Please make sure you have a node running or are using metamask to connect to the ethereum network:</div>
|
<div>Something went wrong connecting to ethereum. Please make sure you have a node running or are using metamask to connect to the ethereum network:</div>
|
||||||
@ -266,7 +294,7 @@ class App extends React.Component {
|
|||||||
<span>Your Received Kudos: <b>{ currentContributor.received } SNT</b> <Button variant="outline-primary" onClick={this.withdrawTokens} disabled={busy}>Withdraw</Button></span> <br/>
|
<span>Your Received Kudos: <b>{ currentContributor.received } SNT</b> <Button variant="outline-primary" onClick={this.withdrawTokens} disabled={busy}>Withdraw</Button></span> <br/>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Row>
|
<Row>
|
||||||
<Col>0x00 has sent you 500 SNT "keep up the good work"</Col>
|
{currentContributor.praises && currentContributor.praises.map((item, i) => <Col key={i}>{item.author} has sent you {web3.utils.fromWei(item.amount, "ether")} SNT {item.praise && "\"" + item.praise + "\""}</Col>)}
|
||||||
</Row>
|
</Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
@ -154,12 +154,12 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"afterDeploy": [
|
"afterDeploy": [
|
||||||
// Give Tokens to Meritocracy Owner
|
// Give Tokens to Meritocracy Owner
|
||||||
"SNT.methods.generateTokens('$accounts[0]', '100000000000000000000').send()",
|
"SNT.methods.generateTokens('$accounts[0]', '1000000000000000000000').send()",
|
||||||
// Add All Contributors
|
// Add All Contributors
|
||||||
"Meritocracy.methods.addContributors([" + getContributors().toString() + "]).send()",
|
"Meritocracy.methods.addContributors([" + getContributors().toString() + "]).send()",
|
||||||
// Allocate Owner Tokens
|
// Allocate Owner Tokens
|
||||||
"SNT.methods.approve('$Meritocracy', 10000).send()",
|
"SNT.methods.approve('$Meritocracy', '1000000000000000000000').send()",
|
||||||
"Meritocracy.methods.allocate(10000).send()",
|
"Meritocracy.methods.allocate('1000000000000000000000').send()",
|
||||||
]
|
]
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -151,6 +151,22 @@ contract Meritocracy {
|
|||||||
emit ContributorTransaction(cSender.addr, cReceiver.addr);
|
emit ContributorTransaction(cSender.addr, cReceiver.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStatusLength(address _contributor) public view returns (uint) {
|
||||||
|
return contributors[_contributor].status.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatus(address _contributor, uint _index) public view returns (
|
||||||
|
address author,
|
||||||
|
string memory praise,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 time
|
||||||
|
) {
|
||||||
|
author = contributors[_contributor].status[_index].author;
|
||||||
|
praise = contributors[_contributor].status[_index].praise;
|
||||||
|
amount = contributors[_contributor].status[_index].amount;
|
||||||
|
time = contributors[_contributor].status[_index].time;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow Contributor to award multiple Contributors
|
// Allow Contributor to award multiple Contributors
|
||||||
function awardContributors(address[] calldata _contributors, uint256 _amountEach, string calldata _praise) external {
|
function awardContributors(address[] calldata _contributors, uint256 _amountEach, string calldata _praise) external {
|
||||||
// Locals
|
// Locals
|
||||||
|
Loading…
x
Reference in New Issue
Block a user