diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js
index ea8384058..26d06542d 100644
--- a/embark-ui/src/actions/index.js
+++ b/embark-ui/src/actions/index.js
@@ -78,6 +78,18 @@ export const RECEIVE_NEW_PROCESS_LOG = 'RECEIVE_NEW_PROCESS_LOG';
export const RECEIVE_PROCESS_LOGS_ERROR = 'RECEIVE_PROCESS_LOGS_ERROR';
// BlockHeader
export const INIT_BLOCK_HEADER = 'INIT_BLOCK_HEADER';
+// Contracts
+export const FETCH_CONTRACTS = 'FETCH_CONTRACTS';
+export const RECEIVE_CONTRACTS = 'RECEIVE_CONTRACTS';
+export const RECEIVE_CONTRACTS_ERROR = 'RECEIVE_CONTRACTS_ERROR';
+// Contract
+export const FETCH_CONTRACT = 'FETCH_CONTRACT';
+export const RECEIVE_CONTRACT = 'RECEIVE_CONTRACT';
+export const RECEIVE_CONTRACT_ERROR = 'RECEIVE_CONTRACT_ERROR';
+// Contract Profile
+export const FETCH_CONTRACT_PROFILE = 'FETCH_CONTRACT_PROFILE';
+export const RECEIVE_CONTRACT_PROFILE = 'RECEIVE_CONTRACT_PROFILE';
+export const RECEIVE_CONTRACT_PROFILE_ERROR = 'RECEIVE_CONTRACT_PROFILE_ERROR';
export function fetchProcessLogs(processName) {
return {
@@ -113,3 +125,64 @@ export function initBlockHeader(){
type: INIT_BLOCK_HEADER
};
}
+
+export function fetchContractProfile() {
+ return {
+ type: FETCH_CONTRACT_PROFILE
+ };
+}
+
+export function receiveContractProfile(profile) {
+ return {
+ type: RECEIVE_CONTRACT_PROFILE,
+ profile
+ };
+}
+
+export function receiveContractProfileError() {
+ return {
+ type: RECEIVE_CONTRACT_PROFILE_ERROR
+ };
+}
+
+export function fetchContract(contractName) {
+ return {
+ type: FETCH_CONTRACT,
+ contractName
+ };
+}
+
+export function receiveContract(contractName, contract) {
+ return {
+ type: RECEIVE_CONTRACT,
+ contractName,
+ contract
+ };
+}
+
+export function receiveContractError() {
+ return {
+ type: RECEIVE_CONTRACT_ERROR
+ };
+}
+
+
+export function fetchContracts() {
+ return {
+ type: FETCH_CONTRACTS
+ };
+}
+
+export function receiveContracts(contracts) {
+ return {
+ type: RECEIVE_CONTRACTS,
+ contracts
+ };
+}
+
+export function receiveContractsError() {
+ return {
+ type: RECEIVE_CONTRACTS_ERROR
+ };
+}
+
diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js
index 0c8079280..ef3ddaf17 100644
--- a/embark-ui/src/api/index.js
+++ b/embark-ui/src/api/index.js
@@ -64,3 +64,15 @@ export function webSocketProcess(processName) {
export function webSocketBlockHeader() {
return new WebSocket(`${constants.wsEndpoint}/blockchain/blockHeader`);
}
+
+export function fetchContract(contractName) {
+ return axios.get('http://localhost:8000/embark-api/contract/' + contractName);
+}
+
+export function fetchContracts() {
+ return axios.get('http://localhost:8000/embark-api/contracts');
+}
+
+export function fetchContractProfile(contractName) {
+ return axios.get('http://localhost:8000/embark-api/profiler/' + contractName);
+}
diff --git a/embark-ui/src/components/Contract.js b/embark-ui/src/components/Contract.js
new file mode 100644
index 000000000..f0e41e676
--- /dev/null
+++ b/embark-ui/src/components/Contract.js
@@ -0,0 +1,29 @@
+import React from 'react';
+import {Link} from 'react-router-dom';
+
+const Contract = ({contract}) => (
+
+ Contract
+
+
+
+ Name |
+ Address |
+ State |
+
+
+
+ return (
+
+ {contract.name} |
+ {contract.address} |
+ {contract.deploy} |
+
+ )
+
+
+
+);
+
+export default Contract;
+
diff --git a/embark-ui/src/components/Contracts.js b/embark-ui/src/components/Contracts.js
new file mode 100644
index 000000000..79aacffc7
--- /dev/null
+++ b/embark-ui/src/components/Contracts.js
@@ -0,0 +1,31 @@
+import React from 'react';
+import {Link} from 'react-router-dom';
+
+const Contracts = ({contracts}) => (
+
+ Contracts
+
+
+
+ Name |
+ Address |
+ State |
+
+
+
+ {contracts.map((contract) => {
+ return (
+
+ {contract.name} |
+ {contract.address} |
+ {contract.deploy} |
+
+ )
+ })}
+
+
+
+);
+
+export default Contracts;
+
diff --git a/embark-ui/src/containers/ContractContainer.js b/embark-ui/src/containers/ContractContainer.js
new file mode 100644
index 000000000..8c8c39a6d
--- /dev/null
+++ b/embark-ui/src/containers/ContractContainer.js
@@ -0,0 +1,51 @@
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { fetchContract } from '../actions';
+import Contract from '../components/Contract';
+
+class ContractContainer extends Component {
+ componentWillMount() {
+ console.dir("----");
+ console.dir(this.props);
+ console.dir(this.state);
+ this.props.fetchContract(this.props.contractName);
+ }
+
+ render() {
+ //const { contract } = this.props;
+ //if (!contracts.data) {
+ // return (
+ //
+ // Loading contracts...
+ //
+ // )
+ //}
+
+ //if (contracts.error) {
+ // return (
+ //
+ // Error API...
+ //
+ // )
+ //}
+
+ return (
+ //
+ hello
+ );
+ }
+};
+
+function mapStateToProps(state) {
+ console.dir("---->>>>>");
+ console.dir(arguments);
+ return { contract: state.contract }
+}
+
+export default connect(
+ mapStateToProps,
+ {
+ fetchContract
+ },
+)(ContractContainer)
+
diff --git a/embark-ui/src/containers/ContractsContainer.js b/embark-ui/src/containers/ContractsContainer.js
new file mode 100644
index 000000000..d2c1f856d
--- /dev/null
+++ b/embark-ui/src/containers/ContractsContainer.js
@@ -0,0 +1,45 @@
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { fetchContracts } from '../actions';
+import Contracts from '../components/Contracts';
+
+class ContractsContainer extends Component {
+ componentWillMount() {
+ this.props.fetchContracts();
+ }
+
+ render() {
+ const { contracts } = this.props;
+ if (!contracts.data) {
+ return (
+
+ Loading contracts...
+
+ )
+ }
+
+ if (contracts.error) {
+ return (
+
+ Error API...
+
+ )
+ }
+
+ return (
+
+ );
+ }
+};
+
+function mapStateToProps(state) {
+ return { contracts: state.contracts }
+}
+
+export default connect(
+ mapStateToProps,
+ {
+ fetchContracts
+ },
+)(ContractsContainer)
+
diff --git a/embark-ui/src/reducers/contractReducer.js b/embark-ui/src/reducers/contractReducer.js
new file mode 100644
index 000000000..cb3a4ce96
--- /dev/null
+++ b/embark-ui/src/reducers/contractReducer.js
@@ -0,0 +1,12 @@
+import {RECEIVE_CONTRACT, RECEIVE_CONTRACT_ERROR} from "../actions";
+
+export default function contract(state = {}, action) {
+ switch (action.type) {
+ case RECEIVE_CONTRACT:
+ return Object.assign({}, state, {data: action.contract.data});
+ case RECEIVE_CONTRACT_ERROR:
+ return Object.assign({}, state, {error: true});
+ default:
+ return state;
+ }
+}
diff --git a/embark-ui/src/reducers/contractsReducer.js b/embark-ui/src/reducers/contractsReducer.js
new file mode 100644
index 000000000..cf37d9c56
--- /dev/null
+++ b/embark-ui/src/reducers/contractsReducer.js
@@ -0,0 +1,12 @@
+import {RECEIVE_CONTRACTS, RECEIVE_CONTRACTS_ERROR} from "../actions";
+
+export default function contracts(state = {}, action) {
+ switch (action.type) {
+ case RECEIVE_CONTRACTS:
+ return Object.assign({}, state, {data: action.contracts.data});
+ case RECEIVE_CONTRACTS_ERROR:
+ return Object.assign({}, state, {error: true});
+ default:
+ return state;
+ }
+}
diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js
index 07eac1469..3886f5037 100644
--- a/embark-ui/src/reducers/index.js
+++ b/embark-ui/src/reducers/index.js
@@ -4,13 +4,15 @@ import accountsReducer from './accountsReducer';
import blocksReducer from './blocksReducer';
import transactionsReducer from './transactionsReducer';
import commandsReducer from './commandsReducer';
+import contractsReducer from './contractsReducer';
const rootReducer = combineReducers({
accounts: accountsReducer,
processes: processesReducer,
blocks: blocksReducer,
transactions: transactionsReducer,
- commands: commandsReducer
+ commands: commandsReducer,
+ contracts: contractsReducer
});
export default rootReducer;
diff --git a/embark-ui/src/routes.js b/embark-ui/src/routes.js
index 62a0dd60a..f5127e098 100644
--- a/embark-ui/src/routes.js
+++ b/embark-ui/src/routes.js
@@ -2,6 +2,9 @@ import React from 'react';
import {Route, Switch} from 'react-router-dom';
import HomeContainer from './containers/HomeContainer';
+import AccountsContainer from './containers/AccountsContainer';
+import ContractsContainer from './containers/ContractsContainer';
+import ContractContainer from './containers/ContractContainer';
import NoMatch from './components/NoMatch';
import ExplorerLayout from './components/ExplorerLayout';
import ProcessesLayout from './components/ProcessesLayout';
@@ -12,6 +15,9 @@ const routes = (
+
+
+
diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js
index b0496e60b..196c24ed3 100644
--- a/embark-ui/src/sagas/index.js
+++ b/embark-ui/src/sagas/index.js
@@ -114,10 +114,38 @@ export default function *root() {
fork(watchFetchProcesses),
fork(watchFetchProcessLogs),
fork(watchListenToProcessLogs),
- fork(watchFetchBlocks),
fork(watchFetchBlock),
- fork(watchFetchTransactions),
+ fork(watchFetchTransactions)
fork(watchFetchTransaction),
fork(watchPostCommand)
+ fork(watchFetchBlocks),
+ fork(watchFetchContracts),
+ fork(watchFetchContract),
]);
}
+
+export function *fetchContract(action) {
+ try {
+ const contract = yield call(api.fetchContract);
+ yield put(actions.receiveContract(contract));
+ } catch (e) {
+ yield put(actions.receiveContractError());
+ }
+}
+
+export function *watchFetchContract() {
+ yield takeEvery(actions.FETCH_CONTRACT, fetchContract);
+}
+
+export function *fetchContracts() {
+ try {
+ const contracts = yield call(api.fetchContracts);
+ yield put(actions.receiveContracts(contracts));
+ } catch (e) {
+ yield put(actions.receiveContractsError());
+ }
+}
+
+export function *watchFetchContracts() {
+ yield takeEvery(actions.FETCH_CONTRACTS, fetchContracts);
+}
diff --git a/lib/modules/contracts_manager/index.js b/lib/modules/contracts_manager/index.js
index 6edfb96fe..c0864cd07 100644
--- a/lib/modules/contracts_manager/index.js
+++ b/lib/modules/contracts_manager/index.js
@@ -69,16 +69,19 @@ class ContractsManager {
self.events.setCommandHandler("contracts:all", (contractName, cb) => {
let contracts = self.listContracts();
- let results = {};
+ let results = [];
+ let i = 0;
for (let className in contracts) {
let contract = contracts[className];
- results[className] = {
+ results.push({
+ index: i,
name: contract.className,
deploy: contract.deploy,
error: contract.error,
address: contract.deployedAddress
- };
+ });
+ i += 1;
}
cb(results);
});
@@ -97,6 +100,9 @@ class ContractsManager {
'/embark-api/contracts',
(req, res) => {
self.events.request('contracts:all', null, res.send.bind(res));
+ //self.events.request('contracts:list', (err, contracts) => {
+ // res.send(contracts);
+ //});
}
);
}