mirror of
https://github.com/status-im/visual-identity.git
synced 2025-02-08 10:44:33 +00:00
Merge branch '000-snt-voting-dapp' of https://github.com/status-im/contracts into 000-snt-voting-dapp
This commit is contained in:
commit
b5172c0dbd
@ -8,6 +8,7 @@ import Slider from '@material-ui/lab/Slider';
|
||||
import Tooltip from '@material-ui/core/Tooltip';
|
||||
import PollManager from 'Embark/contracts/PollManager';
|
||||
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
||||
import web3 from "Embark/web3"
|
||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||
import { VotingContext } from '../../context';
|
||||
|
||||
@ -30,9 +31,10 @@ class Poll extends Component {
|
||||
const { customVote, poll, unvote } = PollManager.methods;
|
||||
const { updatePoll, idPoll } = this.props;
|
||||
const { 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()
|
||||
.then(gasEstimated => {
|
||||
@ -53,18 +55,19 @@ class Poll extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { fromWei } = web3.utils;
|
||||
MiniMeTokenInterface.options.address = this.props._token;
|
||||
MiniMeTokenInterface.methods.balanceOfAt(web3.eth.defaultAccount, this.props._startBlock - 1)
|
||||
.call()
|
||||
.then(balance => {
|
||||
this.setState({balance});
|
||||
this.setState({balance: fromWei(balance)});
|
||||
});
|
||||
|
||||
PollManager.methods.getVote(this.props.idPoll, web3.eth.defaultAccount)
|
||||
.call()
|
||||
.then(vote => {
|
||||
this.setState({value: Math.sqrt(vote)});
|
||||
})
|
||||
.call()
|
||||
.then(vote => {
|
||||
this.setState({value: parseInt(Math.sqrt(fromWei(vote)))});
|
||||
})
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -79,6 +82,7 @@ class Poll extends Component {
|
||||
const { value, balance, isSubmitting } = this.state;
|
||||
|
||||
const disableVote = balance == 0 || !_canVote || isSubmitting;
|
||||
const { fromWei } = web3.utils;
|
||||
const maxValue = Math.floor(Math.sqrt(balance));
|
||||
|
||||
return (
|
||||
@ -92,7 +96,7 @@ class Poll extends Component {
|
||||
Votes: {_qvResults}
|
||||
</Typography>
|
||||
<Typography variant="subheading" color="textSecondary">
|
||||
SNT Allocated: {_results}
|
||||
SNT Allocated: {fromWei(_results)}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
<Tooltip id="tooltip-icon" placement="top" title={`${value * value} SNT - ${value} vote credits`}>
|
||||
|
@ -59,7 +59,7 @@
|
||||
"address": "0xc55cf4b03948d7ebc8b9e8bad92643703811d162"
|
||||
},
|
||||
"PollManager": {
|
||||
"args": ["$MiniMeTokenFactory", "$SNT"]
|
||||
"address": "0x456E047eDEa0a91a66C3DC7aCc0B1424d80cf8a6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ contract PollManager is Controlled {
|
||||
p.voters++;
|
||||
|
||||
p.results += amount;
|
||||
p.qvResults += sqrt(amount);
|
||||
p.qvResults += sqrt(amount / 1 ether);
|
||||
|
||||
emit Vote(_idPoll, msg.sender, amount);
|
||||
}
|
||||
@ -144,7 +144,7 @@ contract PollManager is Controlled {
|
||||
p.voters++;
|
||||
|
||||
p.results += _amount;
|
||||
p.qvResults += sqrt(_amount);
|
||||
p.qvResults += sqrt(_amount / 1 ether);
|
||||
|
||||
emit Vote(_idPoll, msg.sender, _amount);
|
||||
}
|
||||
@ -162,7 +162,7 @@ contract PollManager is Controlled {
|
||||
|
||||
p.voters--;
|
||||
p.results -= amount;
|
||||
p.qvResults -= sqrt(amount);
|
||||
p.qvResults -= sqrt(amount / 1 ether);
|
||||
|
||||
require(MiniMeToken(p.token).transferFrom(address(this), msg.sender, amount));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user