add contract page
This commit is contained in:
parent
40004b5655
commit
fb3753215f
|
@ -146,21 +146,25 @@ export function receiveContractProfileError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchContract(contractName) {
|
export function fetchContract(contractName) {
|
||||||
|
console.dir("== fetchContract");
|
||||||
|
console.dir(contractName);
|
||||||
return {
|
return {
|
||||||
type: FETCH_CONTRACT,
|
type: FETCH_CONTRACT,
|
||||||
contractName
|
contractName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveContract(contractName, contract) {
|
export function receiveContract(contract) {
|
||||||
|
console.dir("== receiveContract");
|
||||||
|
console.dir(contract);
|
||||||
return {
|
return {
|
||||||
type: RECEIVE_CONTRACT,
|
type: RECEIVE_CONTRACT,
|
||||||
contractName,
|
|
||||||
contract
|
contract
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveContractError() {
|
export function receiveContractError() {
|
||||||
|
console.dir("== receiveContractError");
|
||||||
return {
|
return {
|
||||||
type: RECEIVE_CONTRACT_ERROR
|
type: RECEIVE_CONTRACT_ERROR
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,6 +66,8 @@ export function webSocketBlockHeader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchContract(contractName) {
|
export function fetchContract(contractName) {
|
||||||
|
console.dir("api: fetchContract");
|
||||||
|
console.dir(contractName);
|
||||||
return axios.get('http://localhost:8000/embark-api/contract/' + contractName);
|
return axios.get('http://localhost:8000/embark-api/contract/' + contractName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,11 @@ const Contract = ({contract}) => (
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
return (
|
<tr>
|
||||||
<tr>
|
<td>{contract.name || contract.className}</td>
|
||||||
<td>{contract.name}</td>
|
<td>{contract.address || contract.deployedAddress}}</td>
|
||||||
<td>{contract.address}</td>
|
<td>{contract.deploy.toString()}</td>
|
||||||
<td>{contract.deploy}</td>
|
</tr>
|
||||||
</tr>
|
|
||||||
)
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|
|
@ -1,37 +1,46 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { compose } from 'redux';
|
||||||
import { fetchContract } from '../actions';
|
import { fetchContract } from '../actions';
|
||||||
import Contract from '../components/Contract';
|
import Contract from '../components/Contract';
|
||||||
|
import { withRouter } from 'react-router'
|
||||||
|
|
||||||
class ContractContainer extends Component {
|
class ContractContainer extends Component {
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
console.dir("----");
|
console.dir("----");
|
||||||
console.dir(this.props);
|
console.dir(this.props);
|
||||||
console.dir(this.state);
|
//console.dir(this.state);
|
||||||
this.props.fetchContract(this.props.contractName);
|
//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() {
|
render() {
|
||||||
//const { contract } = this.props;
|
console.dir("||======>");
|
||||||
//if (!contracts.data) {
|
console.dir(this.props);
|
||||||
// return (
|
console.dir("||======>");
|
||||||
// <h1>
|
const { contract } = this.props;
|
||||||
// <i>Loading contracts...</i>
|
if (!contract.data) {
|
||||||
// </h1>
|
return (
|
||||||
// )
|
<h1>
|
||||||
//}
|
<i>Loading contract...</i>
|
||||||
|
</h1>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
//if (contracts.error) {
|
if (contract.error) {
|
||||||
// return (
|
return (
|
||||||
// <h1>
|
<h1>
|
||||||
// <i>Error API...</i>
|
<i>Error API...</i>
|
||||||
// </h1>
|
</h1>
|
||||||
// )
|
)
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
console.dir(contract);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
//<Contract contract={contract} />
|
<Contract contract={contract.data} />
|
||||||
<div>hello</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -42,10 +51,11 @@ function mapStateToProps(state) {
|
||||||
return { contract: state.contract }
|
return { contract: state.contract }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default compose(
|
||||||
mapStateToProps,
|
connect(
|
||||||
{
|
mapStateToProps,
|
||||||
fetchContract
|
{ fetchContract }
|
||||||
},
|
),
|
||||||
|
withRouter
|
||||||
)(ContractContainer)
|
)(ContractContainer)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import {RECEIVE_CONTRACT, RECEIVE_CONTRACT_ERROR} from "../actions";
|
import {RECEIVE_CONTRACT, RECEIVE_CONTRACT_ERROR} from "../actions";
|
||||||
|
|
||||||
export default function contract(state = {}, action) {
|
export default function contract(state = {}, action) {
|
||||||
|
console.dir("** reducer");
|
||||||
|
console.dir(arguments);
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case RECEIVE_CONTRACT:
|
case RECEIVE_CONTRACT:
|
||||||
return Object.assign({}, state, {data: action.contract.data});
|
return Object.assign({}, state, {data: action.contract.data});
|
||||||
|
|
|
@ -5,6 +5,7 @@ import blocksReducer from './blocksReducer';
|
||||||
import transactionsReducer from './transactionsReducer';
|
import transactionsReducer from './transactionsReducer';
|
||||||
import commandsReducer from './commandsReducer';
|
import commandsReducer from './commandsReducer';
|
||||||
import contractsReducer from './contractsReducer';
|
import contractsReducer from './contractsReducer';
|
||||||
|
import contractReducer from './contractReducer';
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
accounts: accountsReducer,
|
accounts: accountsReducer,
|
||||||
|
@ -12,7 +13,8 @@ const rootReducer = combineReducers({
|
||||||
blocks: blocksReducer,
|
blocks: blocksReducer,
|
||||||
transactions: transactionsReducer,
|
transactions: transactionsReducer,
|
||||||
commands: commandsReducer,
|
commands: commandsReducer,
|
||||||
contracts: contractsReducer
|
contracts: contractsReducer,
|
||||||
|
contract: contractReducer
|
||||||
});
|
});
|
||||||
|
|
||||||
export default rootReducer;
|
export default rootReducer;
|
||||||
|
|
|
@ -125,15 +125,19 @@ export default function *root() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function *fetchContract(action) {
|
export function *fetchContract(action) {
|
||||||
|
console.dir("** fetchContract");
|
||||||
|
console.dir(action);
|
||||||
try {
|
try {
|
||||||
const contract = yield call(api.fetchContract);
|
const contract = yield call(api.fetchContract, action.contractName);
|
||||||
yield put(actions.receiveContract(contract));
|
yield put(actions.receiveContract(contract));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.dir(e);
|
||||||
yield put(actions.receiveContractError());
|
yield put(actions.receiveContractError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function *watchFetchContract() {
|
export function *watchFetchContract() {
|
||||||
|
console.dir("** watchFetchContract");
|
||||||
yield takeEvery(actions.FETCH_CONTRACT, fetchContract);
|
yield takeEvery(actions.FETCH_CONTRACT, fetchContract);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue