Skip to content

Commit

Permalink
fixes negative number bug, and renders post properly after creating a…
Browse files Browse the repository at this point in the history
… post
  • Loading branch information
Schwartz10 committed Jan 20, 2018
1 parent 0568920 commit 87792e2
Show file tree
Hide file tree
Showing 8 changed files with 932 additions and 808 deletions.
1,706 changes: 913 additions & 793 deletions build/contracts/CapCoin.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -823,5 +823,5 @@
}
},
"schemaVersion": "1.0.1",
"updatedAt": "2018-01-19T23:48:42.207Z"
"updatedAt": "2018-01-20T17:25:13.159Z"
}
2 changes: 1 addition & 1 deletion build/contracts/SimpleStorage.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,5 @@
}
},
"schemaVersion": "1.0.1",
"updatedAt": "2018-01-19T23:48:42.206Z"
"updatedAt": "2018-01-20T17:25:13.158Z"
}
12 changes: 7 additions & 5 deletions contracts/CapCoin.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pragma solidity ^0.4.18;

contract CapCoin {
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';

contract CapCoin is Ownable {

event NewUser(string name);
event BoughtTokens(uint coinBalance);
event CreatedPost(string url);
event LikedPost(uint lotteryAmount, string posterName,
event LikedPost(int lotteryAmount, string posterName,
address poster, uint posterCoinbalance, string likerName,
address liker, uint likerCoinbalance);

Expand All @@ -20,7 +22,7 @@ contract CapCoin {
struct Post {
string url;
string userName;
uint lotteryAmount;
int lotteryAmount;
address owner;
}

Expand All @@ -35,7 +37,7 @@ contract CapCoin {
NewUser(name);
}

function getUser() public view returns (string, uint, string, uint, address) {
function getUser() public view returns (string, uint, string, int, address) {
return (addressToUser[msg.sender].name,
addressToUser[msg.sender].coinBalance,
addressToPost[msg.sender].url,
Expand Down Expand Up @@ -65,7 +67,7 @@ contract CapCoin {
}

function likePost(address post, uint amount) public {
addressToPost[post].lotteryAmount += amount;
addressToPost[post].lotteryAmount += int(amount);
addressToUser[post].coinBalance += amount;
addressToUser[msg.sender].coinBalance -= amount;
LikedPost(addressToPost[post].lotteryAmount,
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3
ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f
0dbbe8e4ae425a6d2687f1a7e3ba17bc98c673636790f1b8ad91193c05875ef1
http://127.0.0.1:7545
6 changes: 3 additions & 3 deletions src/components/CreatePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreatePost extends Component {
/>
<RaisedButton
onClick={e =>
this.props.post(e, this.state.postUrl, this.props.contract.createPost, this.props.accounts[0])}
this.props.post(e, this.state.postUrl, this.props.contract.createPost, this.props.accounts[0], this.props.user.name)}
label="Create Post" primary={true}
/>
</div>
Expand Down Expand Up @@ -71,9 +71,9 @@ const mapState = (state) => {

const mapDispatch = (dispatch) => {
return {
post: function(e, postUrl, contractFunc, account){
post: function(e, postUrl, contractFunc, account, username){
e.preventDefault();
return dispatch(post(postUrl, contractFunc, account));
return dispatch(post(postUrl, contractFunc, account, username));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class Explore extends Component {
<h1 className="single-view-header">Explore</h1>
{this.props.posts.length > 0 &&
this.props.posts.map(post =>
<div id="post-container" key={post.username}>
<div id="post-container" key={post.username}>
<Post
username={post.username}
tokenPot={post.tokenPot}
postUrl={post.postUrl}
address={post.address}
isPreview={false}
/>
</div>
</div>
)}
</div>
)
Expand Down
7 changes: 4 additions & 3 deletions src/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ const likedPost = post => ({type: LIKED_POST, post});
* THUNK CREATORS
*/

export const post = (url, contractFunc, account) =>
export const post = (url, contractFunc, account, username) =>
dispatch =>
contractFunc(url, {from: account})
.then(res => {
let newPost = {}
newPost.postUrl = res.logs[0].args.url;
newPost.account = account;
newPost.tokenPot = -5
newPost.address = account;
newPost.tokenPot = -5;
newPost.username = username;
return dispatch(createPost(newPost));
})
.catch(err => console.log(err));
Expand Down

0 comments on commit 87792e2

Please sign in to comment.