Removing references to SNT at import level

This commit is contained in:
Richard Ramos 2018-12-05 10:24:45 -04:00
parent 4096aa1bfa
commit 696e5d9c47
14 changed files with 54 additions and 127 deletions

View File

@ -1,10 +1,10 @@
import React, { Fragment } from 'react';
import SNTUI from './snt-ui';
import TokenUI from './token-ui';
export default ({ setAccount }) => {
return (
<div class="container">
<SNTUI />
<TokenUI />
</div>
)
}

View File

@ -2,7 +2,7 @@ import {Link} from "react-router-dom";
import Button from '@material-ui/core/Button';
import React, {Component} from 'react';
import Typography from '@material-ui/core/Typography'
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
import { withRouter } from 'react-router-dom'
import PollManager from 'Embark/contracts/PollManager';
@ -31,7 +31,7 @@ class ConnectYourWallet extends Component {
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
if(web3.currentProvider.isStatus){
const tokenBalance = await SNT.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const tokenBalance = await DappToken.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
updateBalances(idPoll, tokenBalance, ethBalance, votes);
history.push('/votingCredits/' + idPoll);

View File

@ -1,6 +1,6 @@
import React, {Component} from 'react';
import { withRouter } from 'react-router-dom'
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
import PollManager from 'Embark/contracts/PollManager';
class ExternalWallet extends Component {
@ -39,7 +39,7 @@ class ExternalWallet extends Component {
// TODO: extract this code to utils. It's repeated in ConnectYourWallt, ExternalWallet and HowVotingWorks
const tknVotes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call({from: web3.eth.defaultAccount});
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
const tokenBalance = await SNT.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const tokenBalance = await DappToken.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
updateBalances(idPoll, tokenBalance, ethBalance, votes);

View File

@ -4,7 +4,7 @@ import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
import { withRouter } from 'react-router-dom';
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
import PollManager from 'Embark/contracts/PollManager';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
@ -68,7 +68,7 @@ class HowVotingWorks extends Component {
const tknVotes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call({from: web3.eth.defaultAccount});
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
const tokenBalance = await SNT.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const tokenBalance = await DappToken.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call({from: web3.eth.defaultAccount});
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
updateBalances(idPoll, tokenBalance, ethBalance, votes);

View File

@ -130,17 +130,17 @@ class PollVoting extends Component {
const maxVotes = Math.floor(Math.sqrt(balance));
const maxValuesForBallots = [];
let votedSNT = 0;
let votedTokens = 0;
for(let i = 0; i < poll._numBallots; i++){
if(votes[i] == undefined){
votes[i] = 0;
} else {
votedSNT += votes[i]*votes[i];
votedTokens += votes[i]*votes[i];
}
}
for(let i = 0; i < poll._numBallots; i++){
maxValuesForBallots[i] = Math.floor(Math.sqrt(balance - votedSNT + votes[i]*votes[i]));
maxValuesForBallots[i] = Math.floor(Math.sqrt(balance - votedTokens + votes[i]*votes[i]));
}
return <Fragment>

View File

@ -6,7 +6,7 @@ import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import { withRouter } from 'react-router-dom'
import HelpDialog from '../HelpDialog';
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
Date.prototype.DDMMYYYY = function () {
var yyyy = this.getFullYear().toString();
@ -52,12 +52,12 @@ class PollCreationCredits extends Component {
}
EmbarkJS.onReady(async () => {
const tokenBalance = await SNT.methods.balanceOf(web3.eth.defaultAccount).call({from: web3.eth.defaultAccount});
const tokenBalance = await DappToken.methods.balanceOf(web3.eth.defaultAccount).call({from: web3.eth.defaultAccount});
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
this.setState({tokenBalance, ethBalance});
if(web3.utils.fromWei(ethBalance.toString(), "ether") > 0 ||
if(web3.utils.fromWei(ethBalance.toString(), "ether") > 0 &&
Math.floor(web3.utils.fromWei(tokenBalance.toString(), "ether")) >= 1
){
history.push('/poll/title');

View File

@ -1,58 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import Hidden from '@material-ui/core/Hidden';
import OrderingFilter from '../simple-voting/OrderingFilter';
import { VotingContext } from '../../context';
const hasSnt = snt => Number(snt.balance) > 0;
const styles = {
root: {
flexGrow: 1,
fontSize: '16px',
},
text: {
flex: 1,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
toolBar: {
display: 'flex',
justifyContent: 'space-around'
}
};
function ButtonAppBar(props) {
const { classes, togglePoll, symbol } = props;
return (
<VotingContext.Consumer>
{({ snt, toggleAdmin }) =>
<div className={classes.root} >
<AppBar position="static">
<Toolbar className={classes.toolBar}>
<Hidden mdDown>
<Button className={classes.menuButton} color="inherit" aria-label="Menu" onClick={toggleAdmin}>Admin</Button>
</Hidden>
{snt && <Button disabled={!hasSnt(snt)} variant="outlined" color="inherit" onClick={togglePoll}>{hasSnt(snt) ? 'Add Proposal' : 'Your account has no ' + symbol}</Button>}
</Toolbar>
</AppBar>
</div>
}
</VotingContext.Consumer>
);
}
ButtonAppBar.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ButtonAppBar);

View File

@ -1,7 +1,6 @@
import React, {Component} from 'react';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography'
import SNT from 'Embark/contracts/SNT';
import { withRouter } from 'react-router-dom';
import { HashRouter as Router, Route, Link, Switch } from "react-router-dom";

View File

@ -1,16 +1,16 @@
import EmbarkJS from 'Embark/EmbarkJS';
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
import React from 'react';
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
import web3 from "Embark/web3"
class SNTUI extends React.Component {
class TokenUI extends React.Component {
constructor(props) {
super(props);
this.state = {
address: "",
amountToMint: 100,
amountToMint: "100000000000000000000",
accountBalance: 0,
accountB: web3.eth.defaultAccount,
balanceOf: 0,
@ -34,27 +34,27 @@ class SNTUI extends React.Component {
var value = parseInt(this.state.amountToMint, 10);
var address = this.state.address;
SNT.methods.controller().call()
DappToken.methods.controller().call()
.then((controller) => {
return SNT.methods.generateTokens(address, value.toString())
return DappToken.methods.generateTokens(address, value.toString())
.send({from: controller, gasLimit: 1000000});
})
.then(console.log);
this._addToLog(SNT.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
this._addToLog(DappToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
}
getBalance(e){
e.preventDefault();
if (EmbarkJS.isNewWeb3()) {
SNT.methods.balanceOf(web3.eth.defaultAccount).call()
DappToken.methods.balanceOf(web3.eth.defaultAccount).call()
.then(_value => this.setState({accountBalance: _value}))
} else {
SNT.balanceOf(web3.eth.defaultAccount)
DappToken.balanceOf(web3.eth.defaultAccount)
.then(_value => this.x({valueGet: _value}))
}
this._addToLog(SNT.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")");
this._addToLog(DappToken.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")");
}
_addToLog(txt){
@ -64,7 +64,7 @@ class SNTUI extends React.Component {
render(){
return (<React.Fragment>
<h3> 1. Mint SNT Token</h3>
<h3> 1. Mint your token</h3>
<Form inline>
<FormGroup>
<FormControl
@ -101,4 +101,4 @@ class SNTUI extends React.Component {
}
}
export default SNTUI;
export default TokenUI;

View File

@ -4,7 +4,7 @@ import web3 from "Embark/web3"
import EmbarkJS from 'Embark/EmbarkJS';
import PollManager from 'Embark/contracts/PollManager';
import Voting from './components/Voting';
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
import { VotingContext } from './context';
import Web3Render from './components/standard/Web3Render';
import { getPolls, omitPolls } from './utils/polls';
@ -45,12 +45,6 @@ class App extends React.Component {
}
this._getPolls();
/* this._setAccounts();
SNT.methods.symbol().call().then((symbol) => {
this.setState({symbol});
})*/
}
web3.eth.net.getId((err, netId) => {
if(EmbarkJS.environment == 'testnet' && netId !== TESTNET){
@ -103,14 +97,6 @@ class App extends React.Component {
this.setState({ rawPolls: [], loading: false });
}
_setAccounts() {
const { fromWei } = web3.utils;
web3.eth.getAccounts(async (err, [address]) => {
const balance = await SNT.methods.balanceOf(address).call();
this.setState({ snt: { balance: fromWei(balance) }});
})
}
updatePoll = async (idPoll) => {
const { poll, nPolls } = PollManager.methods;
const { rawPolls } = this.state;

View File

@ -1,7 +1,7 @@
import web3 from "Embark/web3"
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
import PollManager from 'Embark/contracts/PollManager';
import SNT from 'Embark/contracts/SNT';
import DappToken from 'Embark/contracts/DappToken';
const excluded = {
// PROPER_LIGHT_CLIENT_SUPPORT : 3,
@ -9,7 +9,7 @@ const excluded = {
export const getBalance = async (startBlock) => {
const { fromWei } = web3.utils;
const { balanceOfAt } = SNT.methods;
const { balanceOfAt } = DappToken.methods;
const balance = await balanceOfAt(web3.eth.defaultAccount, startBlock - 1).call();
return fromWei(balance);
}

View File

@ -40,7 +40,7 @@ module.exports = {
"MiniMeTokenFactory": {
},
"SNT": {
"DappToken": {
"instanceOf": "MiniMeToken",
"args": [
"$MiniMeTokenFactory",
@ -53,7 +53,7 @@ module.exports = {
]
},
"PollManager": {
"args": ["$SNT"]
"args": ["$DappToken"]
},
"RLPHelper": {
"deploy": false
@ -97,7 +97,7 @@ module.exports = {
"MiniMeTokenFactory": {
address: "0x6bfa86a71a7dbc68566d5c741f416e3009804279"
},
"SNT": {
"DappToken": {
instanceOf: "MiniMeToken",
address: "0xc55cf4b03948d7ebc8b9e8bad92643703811d162"
},
@ -124,7 +124,7 @@ module.exports = {
"MiniMeTokenFactory": {
address: "0x6bfa86a71a7dbc68566d5c741f416e3009804279"
},
"SNT": {
"DappToken": {
instanceOf: "MiniMeToken",
args: [
"$MiniMeTokenFactory",
@ -139,7 +139,7 @@ module.exports = {
from: "0x00000...."
},
"PollManager": {
args: ["$SNT"],
args: ["$DappToken"],
gasPrice: 5000000000,
from: "0x00000...."
}
@ -152,7 +152,7 @@ module.exports = {
"MiniMeTokenFactory": {
"address": "0xa1c957C0210397D2d0296341627B74411756d476"
},
"SNT": {
"DappToken": {
"instanceOf": "MiniMeToken",
"address": "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
},
@ -170,7 +170,7 @@ module.exports = {
"MiniMeTokenFactory": {
"address": "0xa1c957C0210397D2d0296341627B74411756d476"
},
"SNT": {
"DappToken": {
"instanceOf": "MiniMeToken",
"address": "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
},
@ -198,7 +198,7 @@ module.exports = {
"MiniMeTokenFactory": {
"address": "0xa1c957C0210397D2d0296341627B74411756d476"
},
"SNT": {
"DappToken": {
"address": "0x05fD4a5c96c54a17D845D62C6cB00E39D39BeaF4"
},
"PollManager": {

View File

@ -35,9 +35,9 @@ contract PollManager is Controlled {
rlpHelper = new RLPHelper();
}
/// @notice Only allow addresses that have > 0 SNT to perform an operation
modifier onlySNTHolder {
require(token.balanceOf(msg.sender) > 0, "SNT Balance is required to perform this operation");
/// @notice Only allow addresses that have > 0 Tokens to perform an operation
modifier onlyTokenHolder {
require(token.balanceOf(msg.sender) > 0, "Token balance is required to perform this operation");
_;
}
@ -50,7 +50,7 @@ contract PollManager is Controlled {
bytes _description,
uint8 _numBallots)
public
onlySNTHolder
onlyTokenHolder
returns (uint _idPoll)
{
_idPoll = addPoll(block.number, _endTime, _description, _numBallots);
@ -67,7 +67,7 @@ contract PollManager is Controlled {
bytes _description,
uint8 _numBallots)
public
onlySNTHolder
onlyTokenHolder
returns (uint _idPoll)
{
require(_endTime > block.timestamp, "End time must be greater than current timestamp");
@ -174,7 +174,7 @@ contract PollManager is Controlled {
unvote(_idPoll);
uint amount = token.balanceOfAt(msg.sender, p.startBlock);
require(amount != 0, "No SNT balance available at start block of poll");
require(amount != 0, "No Token balance available at start block of poll");
p.voters++;
@ -191,7 +191,7 @@ contract PollManager is Controlled {
}
}
require(totalBallots <= amount, "Total ballots must be less than the SNT balance at poll start block");
require(totalBallots <= amount, "Total ballots must be less than the Token balance at poll start block");
emit Vote(_idPoll, msg.sender, _ballots);
}

View File

@ -5,7 +5,7 @@ var _ = require('lodash');
var rlp = require('rlp');
const PollManager = embark.require('Embark/contracts/PollManager');
const SNT = embark.require('Embark/contracts/SNT');
const DappToken = embark.require('Embark/contracts/DappToken');
const decimals = (amount) => web3.utils.toWei(amount.toString(), "ether");
@ -18,7 +18,7 @@ config({
"MiniMeToken": {
"deploy": false,
},
"SNT":{
"DappToken":{
"instanceOf": "MiniMeToken",
"args": [
"$MiniMeTokenFactory",
@ -33,7 +33,7 @@ config({
},
"PollManager": {
"deploy": true,
"args": ["$SNT"]
"args": ["$DappToken"]
}
}
});
@ -48,13 +48,13 @@ describe("VotingDapp", function () {
before(function(done) {
web3.eth.getAccounts().then((acc) => {
accounts = acc;
return SNT.methods.generateTokens(accounts[0], decimals(12)).send();
return DappToken.methods.generateTokens(accounts[0], decimals(12)).send();
}).then(() => {
return SNT.methods.generateTokens(accounts[1], decimals(10)).send();
return DappToken.methods.generateTokens(accounts[1], decimals(10)).send();
}).then(() => {
return SNT.methods.generateTokens(accounts[2], decimals(12)).send();
return DappToken.methods.generateTokens(accounts[2], decimals(12)).send();
}).then(() => {
return SNT.methods.generateTokens(accounts[3], decimals(7)).send();
return DappToken.methods.generateTokens(accounts[3], decimals(7)).send();
}).then(() => {
return web3.eth.getBlockNumber();
}).then((block) => {
@ -69,7 +69,7 @@ describe("VotingDapp", function () {
let pollId;
it("Creating a proposal without holding SNT should fail", async () => {
it("Creating a proposal without holding DappToken should fail", async () => {
try {
const receipt = await PollManager.methods.addPoll(
blockNumber,
@ -83,7 +83,7 @@ describe("VotingDapp", function () {
}
});
it("A SNT holder can create polls", async () => {
it("A DappToken holder can create polls", async () => {
const blockNumber = (await web3.eth.getBlockNumber()) + 1;
const receipt = await PollManager.methods.addPoll(
@ -105,7 +105,7 @@ describe("VotingDapp", function () {
assert.equal(canVote, true, "User should be able to vote");
});
it("A SNT holder cannot vote if ballots total is greater than current balance", async () => {
it("A DappToken holder cannot vote if ballots total is greater than current balance", async () => {
try {
const receipt = await PollManager.methods.vote(pollId, [decimals(11), decimals(12), decimals(12)]).send({from: accounts[0]});
assert.fail('should have reverted before');
@ -139,7 +139,7 @@ describe("VotingDapp", function () {
});
it("Voting when you're not a SNT holder SHOULD FAIL!", async () => {
it("Voting when you're not a DappToken holder SHOULD FAIL!", async () => {
try {
const receipt = await PollManager.methods.vote(pollId, [decimals(1), decimals(2), decimals(3)])
.send({from: accounts[8]});