Skip to content

Commit

Permalink
Merge pull request #1 from Schwartz10/fetchUser-take2
Browse files Browse the repository at this point in the history
Fetch user take2
  • Loading branch information
Schwartz10 authored Jan 18, 2018
2 parents cef124e + a579918 commit 5c93ed5
Show file tree
Hide file tree
Showing 6 changed files with 628 additions and 1,702 deletions.
2,294 changes: 600 additions & 1,694 deletions build/contracts/CapCoin.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,9 @@
"5777": {
"events": {},
"links": {},
"address": "0xf12b5dd4ead5f743c6baa640b0216200e89b60da"
"address": "0x345ca3e014aaf5dca488057592ee47305d9b3e10"
}
},
"schemaVersion": "1.0.1",
"updatedAt": "2018-01-18T14:33:11.577Z"
"updatedAt": "2018-01-18T19:03:08.782Z"
}
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-18T14:33:11.547Z"
"updatedAt": "2018-01-18T19:03:08.779Z"
}
5 changes: 5 additions & 0 deletions contracts/CapCoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ contract CapCoin {

uint coinSupply = 1000000;
uint coinsBought = 0;
uint contractNum;

function CapCoin () {
contractNum = 1;
}

struct User {
string name;
Expand Down
8 changes: 5 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class App extends Component {
await this.props.getWeb3()
await this.props.getContract(this.props.web3)
await this.props.getAccounts(this.props.web3)
// await this.props.getUser(this.props.web3)
await this.props.findUser(this.props.contract.getUser, this.props.accounts[0])
}

render() {
Expand All @@ -44,6 +44,8 @@ class App extends Component {
function mapStateToProps(state){
return {
web3: state.web3,
contract: state.contract,
accounts: state.accounts
}
}

Expand All @@ -58,8 +60,8 @@ function mapDispatchToProps(dispatch){
getAccounts: function (web3){
return dispatch(fetchAccounts(web3));
},
getUser: function (web3){
return dispatch(fetchUser(web3));
findUser: function (contractFunc, account){
return dispatch(fetchUser(contractFunc, account));
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ const createUser = user => ({type: CREATE_USER, user})
* THUNK CREATORS
*/

export const fetchUser = (web3, address) => {}
export const fetchUser = (contractFunc, account) =>
dispatch =>
contractFunc.call({from: account})
.then(res => {
let user = {}
user.name = res[0];
user.coinBalance = Number(res[1].toString(10));
return dispatch(getUser(user))
})
.catch(err => console.log(err))

export const addUser = (name, contractFunc, account) =>
dispatch =>
contractFunc(name, {from: account})
.then(res => dispatch(createUser(res.logs[0].args)))
.then(res => {

console.log(res)
dispatch(createUser(res.logs[0].args))})
.catch(err => console.log(err))

/**
Expand Down

0 comments on commit 5c93ed5

Please sign in to comment.