mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 15:48:10 +00:00
Formatting results
This commit is contained in:
parent
46f11a335f
commit
5907339d4d
@ -8,6 +8,7 @@ import Slider from '@material-ui/lab/Slider';
|
|||||||
import Tooltip from '@material-ui/core/Tooltip';
|
import Tooltip from '@material-ui/core/Tooltip';
|
||||||
import PollManager from 'Embark/contracts/PollManager';
|
import PollManager from 'Embark/contracts/PollManager';
|
||||||
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
||||||
|
import web3 from "Embark/web3"
|
||||||
|
|
||||||
class Poll extends Component {
|
class Poll extends Component {
|
||||||
|
|
||||||
@ -27,9 +28,10 @@ class Poll extends Component {
|
|||||||
|
|
||||||
const { customVote, poll, unvote } = PollManager.methods;
|
const { customVote, poll, unvote } = PollManager.methods;
|
||||||
const { idPoll, value } = this.state;
|
const { idPoll, value } = this.state;
|
||||||
const balance4Voting = value * value;
|
const { toWei } = web3.utils;
|
||||||
|
|
||||||
const toSend = balance4Voting === 0 ? unvote(idPoll) : customVote(idPoll, balance4Voting);
|
const balance4Voting = toWei(value * value);
|
||||||
|
const toSend = balance4Voting == 0 ? unvote(idPoll) : customVote(idPoll, balance4Voting);
|
||||||
|
|
||||||
toSend.estimateGas()
|
toSend.estimateGas()
|
||||||
.then(gasEstimated => {
|
.then(gasEstimated => {
|
||||||
@ -53,17 +55,18 @@ class Poll extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
const { fromWei } = web3.utils;
|
||||||
MiniMeTokenInterface.options.address = this.props._token;
|
MiniMeTokenInterface.options.address = this.props._token;
|
||||||
MiniMeTokenInterface.methods.balanceOfAt(web3.eth.defaultAccount, this.props._startBlock - 1)
|
MiniMeTokenInterface.methods.balanceOfAt(web3.eth.defaultAccount, this.props._startBlock - 1)
|
||||||
.call()
|
.call()
|
||||||
.then(balance => {
|
.then(balance => {
|
||||||
this.setState({balance});
|
this.setState({balance: fromWei(balance)});
|
||||||
});
|
});
|
||||||
|
|
||||||
PollManager.methods.getVote(this.props.idPoll, web3.eth.defaultAccount)
|
PollManager.methods.getVote(this.props.idPoll, web3.eth.defaultAccount)
|
||||||
.call()
|
.call()
|
||||||
.then(vote => {
|
.then(vote => {
|
||||||
this.setState({value: Math.sqrt(vote)});
|
this.setState({value: parseInt(Math.sqrt(fromWei(vote)))});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +83,7 @@ class Poll extends Component {
|
|||||||
votes } = this.state;
|
votes } = this.state;
|
||||||
|
|
||||||
const disableVote = balance == 0 || !_canVote || isSubmitting;
|
const disableVote = balance == 0 || !_canVote || isSubmitting;
|
||||||
|
const { fromWei } = web3.utils;
|
||||||
const maxValue = Math.floor(Math.sqrt(balance));
|
const maxValue = Math.floor(Math.sqrt(balance));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -93,7 +97,7 @@ class Poll extends Component {
|
|||||||
Votes: {_qvResults}
|
Votes: {_qvResults}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="subheading" color="textSecondary">
|
<Typography variant="subheading" color="textSecondary">
|
||||||
SNT Allocated: {_results}
|
SNT Allocated: {fromWei(_results)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<Tooltip id="tooltip-icon" placement="top" title={`${value * value} SNT - ${value} vote credits`}>
|
<Tooltip id="tooltip-icon" placement="top" title={`${value * value} SNT - ${value} vote credits`}>
|
||||||
|
@ -121,7 +121,7 @@ contract PollManager is Controlled {
|
|||||||
p.voters++;
|
p.voters++;
|
||||||
|
|
||||||
p.results += amount;
|
p.results += amount;
|
||||||
p.qvResults += sqrt(amount);
|
p.qvResults += sqrt(amount / 1 ether);
|
||||||
|
|
||||||
emit Vote(_idPoll, msg.sender, amount);
|
emit Vote(_idPoll, msg.sender, amount);
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ contract PollManager is Controlled {
|
|||||||
p.voters++;
|
p.voters++;
|
||||||
|
|
||||||
p.results += _amount;
|
p.results += _amount;
|
||||||
p.qvResults += sqrt(_amount);
|
p.qvResults += sqrt(_amount / 1 ether);
|
||||||
|
|
||||||
emit Vote(_idPoll, msg.sender, _amount);
|
emit Vote(_idPoll, msg.sender, _amount);
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ contract PollManager is Controlled {
|
|||||||
|
|
||||||
p.voters--;
|
p.voters--;
|
||||||
p.results -= amount;
|
p.results -= amount;
|
||||||
p.qvResults -= sqrt(amount);
|
p.qvResults -= sqrt(amount / 1 ether);
|
||||||
|
|
||||||
require(MiniMeToken(p.token).transferFrom(address(this), msg.sender, amount));
|
require(MiniMeToken(p.token).transferFrom(address(this), msg.sender, amount));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user