Skip to content

Commit

Permalink
Convert to wei
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Apr 19, 2018
1 parent 0519d4d commit a73ba2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/actions/wallet.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as ActionTypes from '../actiontypes';
import Network from '../network'

import { SampleCrowdsale } from '../contracts';
import { SAMPLE_CROWDSALE_ADDRESS } from '../constants';
import { SAMPLE_TOKEN_ADDRESS } from '../constants';
import { SampleToken, } from '../contracts';



const WalletActions = {

getBalance(address) {
return async function (dispatch) {
const sampleToken = await SampleToken.at(SAMPLE_TOKEN_ADDRESS);
const balance = await sampleToken.balanceOf(address);
WalletActions.updateBalance(address, balance);
dispatch(WalletActions.updateBalance(address, balance));
};
},

Expand All @@ -20,12 +23,11 @@ const WalletActions = {
},


buy(address, amount) {
buy(address) {
return async function (dispatch) {
const sampleCrowdsale = await SampleCrowdsale.at(SAMPLE_CROWDSALE_ADDRESS);
console.log(address);
await sampleCrowdsale.buyTokens(address, { from: address, value: amount });
WalletActions.getBalance(address);
await sampleCrowdsale.sendTransaction({ from: address, value: Network.web3().toWei(0.1, "ether") });
dispatch(WalletActions.getBalance(address));
};
},

Expand Down
4 changes: 2 additions & 2 deletions src/components/Wallet.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Wallet extends Component {
return (
<div>
<p>I have { this.props.balance.toString() } tokens.</p>
<button onClick={ () => this.buyTokens(this.props.address) }>Buy 0.1 tokens</button>
<button onClick={ () => this.buyTokens(this.props.address) }>Buy 0.1 ether</button>
</div>
);
}

buyTokens(address) {
Store.dispatch(WalletActions.buy(address, 0.1));
Store.dispatch(WalletActions.buy(address));
}


Expand Down

0 comments on commit a73ba2b

Please sign in to comment.