diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 26d06542..041c650d 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -146,21 +146,25 @@ export function receiveContractProfileError() { } export function fetchContract(contractName) { + console.dir("== fetchContract"); + console.dir(contractName); return { type: FETCH_CONTRACT, contractName }; } -export function receiveContract(contractName, contract) { +export function receiveContract(contract) { + console.dir("== receiveContract"); + console.dir(contract); return { type: RECEIVE_CONTRACT, - contractName, contract }; } export function receiveContractError() { + console.dir("== receiveContractError"); return { type: RECEIVE_CONTRACT_ERROR }; diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index ef3ddaf1..1f4d01ff 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -66,6 +66,8 @@ export function webSocketBlockHeader() { } export function fetchContract(contractName) { + console.dir("api: fetchContract"); + console.dir(contractName); return axios.get('http://localhost:8000/embark-api/contract/' + contractName); } diff --git a/embark-ui/src/components/Contract.js b/embark-ui/src/components/Contract.js index f0e41e67..ed5767bc 100644 --- a/embark-ui/src/components/Contract.js +++ b/embark-ui/src/components/Contract.js @@ -13,13 +13,11 @@ const Contract = ({contract}) => ( - return ( - - {contract.name} - {contract.address} - {contract.deploy} - - ) + + {contract.name || contract.className} + {contract.address || contract.deployedAddress}} + {contract.deploy.toString()} + diff --git a/embark-ui/src/containers/ContractContainer.js b/embark-ui/src/containers/ContractContainer.js index 8c8c39a6..13fe2ab8 100644 --- a/embark-ui/src/containers/ContractContainer.js +++ b/embark-ui/src/containers/ContractContainer.js @@ -1,37 +1,46 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; +import { compose } from 'redux'; import { fetchContract } from '../actions'; import Contract from '../components/Contract'; +import { withRouter } from 'react-router' class ContractContainer extends Component { componentWillMount() { console.dir("----"); console.dir(this.props); - console.dir(this.state); - this.props.fetchContract(this.props.contractName); + //console.dir(this.state); + //console.dir(this.props.match.params.contractName); + //console.dir(this.props.match.params.contractName); + //console.dir(this.props.fetchContract.toString()); + this.props.fetchContract(this.props.match.params.contractName); } render() { - //const { contract } = this.props; - //if (!contracts.data) { - // return ( - //

- // Loading contracts... - //

- // ) - //} + console.dir("||======>"); + console.dir(this.props); + console.dir("||======>"); + const { contract } = this.props; + if (!contract.data) { + return ( +

+ Loading contract... +

+ ) + } - //if (contracts.error) { - // return ( - //

- // Error API... - //

- // ) - //} + if (contract.error) { + return ( +

+ Error API... +

+ ) + } + + console.dir(contract); return ( - // -
hello
+ ); } }; @@ -42,10 +51,11 @@ function mapStateToProps(state) { return { contract: state.contract } } -export default connect( - mapStateToProps, - { - fetchContract - }, +export default compose( + connect( + mapStateToProps, + { fetchContract } + ), + withRouter )(ContractContainer) diff --git a/embark-ui/src/reducers/contractReducer.js b/embark-ui/src/reducers/contractReducer.js index cb3a4ce9..0bca3003 100644 --- a/embark-ui/src/reducers/contractReducer.js +++ b/embark-ui/src/reducers/contractReducer.js @@ -1,6 +1,8 @@ import {RECEIVE_CONTRACT, RECEIVE_CONTRACT_ERROR} from "../actions"; export default function contract(state = {}, action) { + console.dir("** reducer"); + console.dir(arguments); switch (action.type) { case RECEIVE_CONTRACT: return Object.assign({}, state, {data: action.contract.data}); diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 3886f503..5ea2d06e 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -5,6 +5,7 @@ import blocksReducer from './blocksReducer'; import transactionsReducer from './transactionsReducer'; import commandsReducer from './commandsReducer'; import contractsReducer from './contractsReducer'; +import contractReducer from './contractReducer'; const rootReducer = combineReducers({ accounts: accountsReducer, @@ -12,7 +13,8 @@ const rootReducer = combineReducers({ blocks: blocksReducer, transactions: transactionsReducer, commands: commandsReducer, - contracts: contractsReducer + contracts: contractsReducer, + contract: contractReducer }); export default rootReducer; diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 196c24ed..1948e8b1 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -125,15 +125,19 @@ export default function *root() { } export function *fetchContract(action) { + console.dir("** fetchContract"); + console.dir(action); try { - const contract = yield call(api.fetchContract); + const contract = yield call(api.fetchContract, action.contractName); yield put(actions.receiveContract(contract)); } catch (e) { + console.dir(e); yield put(actions.receiveContractError()); } } export function *watchFetchContract() { + console.dir("** watchFetchContract"); yield takeEvery(actions.FETCH_CONTRACT, fetchContract); }