Skip to content

Commit

Permalink
Merge pull request #13 from Schwartz10/exchangeRate
Browse files Browse the repository at this point in the history
exchange rate working
  • Loading branch information
Schwartz10 authored Jan 20, 2018
2 parents 2ecb3b0 + 79a426a commit 23f1ecc
Show file tree
Hide file tree
Showing 7 changed files with 1,164 additions and 704 deletions.
1,833 changes: 1,139 additions & 694 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-20T17:25:13.159Z"
"updatedAt": "2018-01-20T19:00:49.726Z"
}
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-20T17:25:13.158Z"
"updatedAt": "2018-01-20T19:00:49.725Z"
}
17 changes: 15 additions & 2 deletions contracts/CapCoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ contract CapCoin is Ownable {

uint coinSupply = 1000000;
uint coinsBought = 0;
address owner;
uint value;

function CapCoin () {
owner = msg.sender;
}

struct User {
string name;
Expand Down Expand Up @@ -46,10 +52,11 @@ contract CapCoin is Ownable {
}

// need to add economics
function buyTokens(uint amount) public {
function buyTokens(uint amount) payable public {
addressToUser[msg.sender].coinBalance += amount;
coinsBought += amount;
coinSupply -= amount;
value += msg.value;
BoughtTokens(addressToUser[msg.sender].coinBalance);
}

Expand Down Expand Up @@ -85,5 +92,11 @@ contract CapCoin is Ownable {
createPost(url);
}

function() internal payable {}
function kill() {
if (msg.sender == owner) {
selfdestruct(owner);
}
}

function() payable {}
}
7 changes: 4 additions & 3 deletions src/components/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Exchange extends Component {
</SelectField>
<RaisedButton
onClick={(e) =>
this.props.buyTokens(e, this.state.value, this.props.contract.buyTokens, this.props.accounts[0])}
this.props.buyTokens(e, this.state.value, this.props.contract.buyTokens, this.props.accounts[0], this.props.web3.toWei)}
label="Buy Tokens" primary={true}
/>
<h3>You have {this.props.user.coinBalance} Coins</h3>
Expand All @@ -43,6 +43,7 @@ class Exchange extends Component {

const mapState = (state) => {
return {
web3: state.web3,
user: state.user,
contract: state.contract,
accounts: state.accounts
Expand All @@ -51,9 +52,9 @@ const mapState = (state) => {

const mapDispatch = (dispatch) => {
return {
buyTokens: function(e, amount, contractFunc, account){
buyTokens: function(e, amount, contractFunc, account, conversionFunc){
e.preventDefault()
return dispatch(buyTokens(amount, contractFunc, account))
return dispatch(buyTokens(amount, contractFunc, account, conversionFunc))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/LikePhoto.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LikePhoto extends Component {
<ContentRemove />
</FloatingActionButton>
</div>
<RaisedButton primary={true} label="Reward" onClick={e => this.props.like(e, this.props.postUrl, this.props.postAddress, this.props.contract.likePost, this.props.accounts[0], this.state.reward)}/>
<RaisedButton primary={true} disabled={this.state.reward <= 0} label="Reward" onClick={e => this.props.like(e, this.props.postUrl, this.props.postAddress, this.props.contract.likePost, this.props.accounts[0], this.state.reward)}/>
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export const addUser = (name, contractFunc, account) =>
})
.catch(err => console.log(err));

export const buyTokens = (amount, contractFunc, account) =>
export const buyTokens = (amount, contractFunc, account, conversionFunc) =>
dispatch =>
contractFunc(amount, {from: account})
contractFunc(amount, {from: account, gas: 1000000, value: conversionFunc(amount/10, 'ether')})
// contractFunc(amount, {from: account})
.then(res => dispatch(boughtTokens(res.logs[0].args.coinBalance.c[0])))
.catch(err => console.log(err));

Expand Down

0 comments on commit 23f1ecc

Please sign in to comment.