From bf77c2b010049f0b5a8dfe763deb830dd9a15dbf Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 15 Aug 2018 14:59:16 +0100 Subject: [PATCH] Show sources --- embark-ui/src/actions/index.js | 7 +++ embark-ui/src/api/index.js | 4 ++ embark-ui/src/components/ContractLayout.js | 22 ++++---- embark-ui/src/components/Contracts.js | 2 +- embark-ui/src/components/Fiddle.js | 2 +- embark-ui/src/containers/AppContainer.js | 5 +- embark-ui/src/containers/ContractContainer.js | 5 -- .../src/containers/ContractLayoutContainer.js | 44 +++++++++++++++ .../src/containers/ContractSourceContainer.js | 53 +++++++++++++++++++ .../src/containers/ContractsContainer.js | 12 ++++- embark-ui/src/reducers/index.js | 5 +- embark-ui/src/reducers/selectors.js | 4 ++ embark-ui/src/routes.js | 6 +-- embark-ui/src/sagas/index.js | 10 +++- lib/modules/ens/index.js | 24 --------- 15 files changed, 151 insertions(+), 54 deletions(-) create mode 100644 embark-ui/src/containers/ContractLayoutContainer.js create mode 100644 embark-ui/src/containers/ContractSourceContainer.js diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 0442554e..45ebf9c1 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -104,6 +104,13 @@ export const contractProfile = { failure: (error) => action(CONTRACT_PROFILE[FAILURE], {error}) }; +export const CONTRACT_FILE = createRequestTypes('CONTRACT_FILE'); +export const contractFile = { + request: (filename) => action(CONTRACT_FILE[REQUEST], {filename}), + success: (source, payload) => action(CONTRACT_FILE[SUCCESS], {contractFiles: [{source, filename: payload.filename}]}), + failure: (error) => action(CONTRACT_FILE[FAILURE], {error}) +}; + export const VERSIONS = createRequestTypes('VERSIONS'); export const versions = { request: () => action(VERSIONS[REQUEST]), diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 7bdc21e4..2de94a6f 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -96,6 +96,10 @@ export function postEnsRecord(payload) { return post('/ens/register', payload); } +export function fetchContractFile(payload) { + return get('/files/contracts', {params: payload}); +} + export function listenToChannel(channel) { return new WebSocket(`${constants.wsEndpoint}/communication/listenTo/${channel}`); } diff --git a/embark-ui/src/components/ContractLayout.js b/embark-ui/src/components/ContractLayout.js index d3e6a300..71b838a7 100644 --- a/embark-ui/src/components/ContractLayout.js +++ b/embark-ui/src/components/ContractLayout.js @@ -10,8 +10,9 @@ import { import ContractContainer from '../containers/ContractContainer'; import ContractLoggerContainer from '../containers/ContractLoggerContainer'; import ContractProfileContainer from '../containers/ContractProfileContainer'; +import ContractSourceContainer from '../containers/ContractSourceContainer'; -const ContractLayout = (props) => ( +const ContractLayout = ({match}) => ( Contract @@ -19,15 +20,15 @@ const ContractLayout = (props) => ( - Back to {props.match.params.contractName} + Back to {match.params.contractName} @@ -35,7 +36,7 @@ const ContractLayout = (props) => ( @@ -43,7 +44,7 @@ const ContractLayout = (props) => ( @@ -51,7 +52,7 @@ const ContractLayout = (props) => ( @@ -59,7 +60,7 @@ const ContractLayout = (props) => ( @@ -70,9 +71,10 @@ const ContractLayout = (props) => ( - + + - + diff --git a/embark-ui/src/components/Contracts.js b/embark-ui/src/components/Contracts.js index cbae96e3..a118774a 100644 --- a/embark-ui/src/components/Contracts.js +++ b/embark-ui/src/components/Contracts.js @@ -24,7 +24,7 @@ const Contracts = ({contracts}) => ( bodyItems={ contracts.map((contract) => { return ([ - {content: {contract.className}}, + {content: {contract.className}}, {content: contract.address}, {content: contract.deploy.toString()} ]); diff --git a/embark-ui/src/components/Fiddle.js b/embark-ui/src/components/Fiddle.js index a380fe93..590d8e8c 100644 --- a/embark-ui/src/components/Fiddle.js +++ b/embark-ui/src/components/Fiddle.js @@ -14,7 +14,7 @@ class Fiddle extends React.Component { render() { const {onCodeChange, value, errors, warnings} = this.props; - const annotations = errors.map((error) => { return error.annotation; }).concat(warnings.map(warning => { return warning.annotation; })); + const annotations = errors && errors.map((error) => { return error.annotation; }).concat(warnings.map(warning => { return warning.annotation; })); return ( diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 5f1e7317..45312588 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -9,7 +9,6 @@ import routes from '../routes'; import { initBlockHeader, - contracts as contractsAction, processes as processesAction, versions as versionsAction, plugins as pluginsAction @@ -19,7 +18,6 @@ class AppContainer extends Component { componentDidMount() { this.props.initBlockHeader(); this.props.fetchProcesses(); - this.props.fetchContracts(); this.props.fetchVersions(); this.props.fetchPlugins(); } @@ -37,7 +35,6 @@ class AppContainer extends Component { AppContainer.propTypes = { initBlockHeader: PropTypes.func, - fetchContracts: PropTypes.func, fetchProcesses: PropTypes.func, fetchPlugins: PropTypes.func, fetchVersions: PropTypes.func @@ -48,7 +45,7 @@ export default connect( { initBlockHeader, fetchProcesses: processesAction.request, - fetchContracts: contractsAction.request, + fetchVersions: versionsAction.request, fetchPlugins: pluginsAction.request }, diff --git a/embark-ui/src/containers/ContractContainer.js b/embark-ui/src/containers/ContractContainer.js index e263f1a0..925135e8 100644 --- a/embark-ui/src/containers/ContractContainer.js +++ b/embark-ui/src/containers/ContractContainer.js @@ -9,10 +9,6 @@ import DataWrapper from "../components/DataWrapper"; import {getContract} from "../reducers/selectors"; class ContractContainer extends Component { - componentDidMount() { - this.props.fetchContract(this.props.match.params.contractName); - } - render() { return ( ( @@ -33,7 +29,6 @@ function mapStateToProps(state, props) { ContractContainer.propTypes = { match: PropTypes.object, contract: PropTypes.object, - fetchContract: PropTypes.func, error: PropTypes.string }; diff --git a/embark-ui/src/containers/ContractLayoutContainer.js b/embark-ui/src/containers/ContractLayoutContainer.js new file mode 100644 index 00000000..43243286 --- /dev/null +++ b/embark-ui/src/containers/ContractLayoutContainer.js @@ -0,0 +1,44 @@ +import React, {Component} from 'react'; +import {connect} from 'react-redux'; +import PropTypes from 'prop-types'; +import {withRouter} from 'react-router-dom'; + +import {contract as contractAction} from '../actions'; +import ContractLayout from '../components/ContractLayout'; +import {getContract} from "../reducers/selectors"; + +class ContractLayoutContainer extends Component { + componentDidMount() { + this.props.fetchContract(this.props.match.params.contractName); + } + + render() { + if (this.props.contract){ + return ; + } else { + return ; + } + } +} + +function mapStateToProps(state, props) { + return { + contract: getContract(state, props.match.params.contractName), + error: state.errorMessage, + loading: state.loading + }; +} + +ContractLayoutContainer.propTypes = { + match: PropTypes.object, + contract: PropTypes.object, + fetchContract: PropTypes.func, + error: PropTypes.string +}; + +export default withRouter(connect( + mapStateToProps, + { + fetchContract: contractAction.request + } +)(ContractLayoutContainer)); diff --git a/embark-ui/src/containers/ContractSourceContainer.js b/embark-ui/src/containers/ContractSourceContainer.js new file mode 100644 index 00000000..53590cec --- /dev/null +++ b/embark-ui/src/containers/ContractSourceContainer.js @@ -0,0 +1,53 @@ +import React, {Component} from 'react'; +import {connect} from 'react-redux'; +import PropTypes from 'prop-types'; +import {withRouter} from 'react-router-dom'; +import {Page} from "tabler-react"; + +import {contractFile as contractFileAction} from '../actions'; +import DataWrapper from "../components/DataWrapper"; +import Fiddle from "../components/Fiddle"; +import {getContract, getContractFile} from "../reducers/selectors"; + +class ContractSourceContainer extends Component { + componentDidMount() { + this.props.fetchContractFile(this.props.contract.originalFilename); + } + + render() { + return ( + + ( + + )} /> + + ); + } +} + +function mapStateToProps(state, props) { + const contract = getContract(state, props.match.params.contractName); + const contractFile = getContractFile(state, contract.originalFilename); + + return { + contract, + contractFile, + error: state.errorMessage, + loading: state.loading + }; +} + +ContractSourceContainer.propTypes = { + match: PropTypes.object, + contract: PropTypes.object, + contractFile: PropTypes.object, + fetchContractFile: PropTypes.func, + error: PropTypes.string +}; + +export default withRouter(connect( + mapStateToProps, + { + fetchContractFile: contractFileAction.request + } +)(ContractSourceContainer)); diff --git a/embark-ui/src/containers/ContractsContainer.js b/embark-ui/src/containers/ContractsContainer.js index dca0f6f8..94b0839f 100644 --- a/embark-ui/src/containers/ContractsContainer.js +++ b/embark-ui/src/containers/ContractsContainer.js @@ -1,12 +1,17 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; import PropTypes from 'prop-types'; +import {contracts as contractsAction} from "../actions"; import Contracts from '../components/Contracts'; import DataWrapper from "../components/DataWrapper"; import {getContracts} from "../reducers/selectors"; class ContractsContainer extends Component { + componentDidMount() { + this.props.fetchContracts(); + } + render() { return ( 0} {...this.props} render={({contracts}) => ( @@ -21,9 +26,12 @@ function mapStateToProps(state) { } ContractsContainer.propTypes = { - contracts: PropTypes.array + contracts: PropTypes.array, + fetchContracts: PropTypes.func, }; export default connect( - mapStateToProps + mapStateToProps,{ + fetchContracts: contractsAction.request + } )(ContractsContainer); diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 64c9b6ef..c6836e7b 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -12,6 +12,7 @@ const entitiesDefaultState = { processLogs: [], contracts: [], contractProfiles: [], + contractFiles: [], contractLogs: [], commands: [], messages: [], @@ -47,6 +48,9 @@ const filtrer = { contracts: function(contract, index, self) { return index === self.findIndex((t) => t.className === contract.className); }, + contractFiles: function(contractFile, index, self) { + return index === self.findIndex((c) => c.filename === contractFile.filename); + }, accounts: function(account, index, self) { return index === self.findIndex((t) => t.address === account.address); }, @@ -95,7 +99,6 @@ function errorMessage(state = null, action) { return action.error || state; } -/* eslint multiline-ternary: "off" */ function errorEntities(state = {}, action) { if (!action.type.endsWith(SUCCESS)) { return state; diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index 5b51102c..d733e65f 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -62,6 +62,10 @@ export function getContractProfile(state, contractName) { return state.entities.contractProfiles.find((contractProfile => contractProfile.name === contractName)); } +export function getContractFile(state, filename) { + return state.entities.contractFiles.find((contractFile => contractFile.filename === filename)); +} + export function getVersions(state) { return state.entities.versions; } diff --git a/embark-ui/src/routes.js b/embark-ui/src/routes.js index 346b510f..b41316ba 100644 --- a/embark-ui/src/routes.js +++ b/embark-ui/src/routes.js @@ -2,12 +2,11 @@ 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/ContractLayoutContainer'; import NoMatch from './components/NoMatch'; import ExplorerLayout from './components/ExplorerLayout'; import ProcessesLayout from './components/ProcessesLayout'; -import ContractLayout from './components/ContractLayout'; import FiddleContainer from './containers/FiddleContainer'; const routes = ( @@ -16,8 +15,7 @@ const routes = ( - - + diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 8d90aac8..2518f85e 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -5,7 +5,7 @@ import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects'; const {account, accounts, block, blocks, transaction, transactions, processes, commands, processLogs, contracts, contract, contractProfile, messageSend, versions, plugins, messageListen, fiddle, - ensRecord, ensRecords, contractLogs} = actions; + ensRecord, ensRecords, contractLogs, contractFile} = actions; function *doRequest(entity, apiFn, payload) { const {response, error} = yield call(apiFn, payload); @@ -31,6 +31,7 @@ export const fetchContractLogs = doRequest.bind(null, contractLogs, api.fetchCon export const fetchContracts = doRequest.bind(null, contracts, api.fetchContracts); export const fetchContract = doRequest.bind(null, contract, api.fetchContract); export const fetchContractProfile = doRequest.bind(null, contractProfile, api.fetchContractProfile); +export const fetchContractFile = doRequest.bind(null, contractFile, api.fetchContractFile); export const fetchFiddle = doRequest.bind(null, fiddle, api.fetchFiddle); export const sendMessage = doRequest.bind(null, messageSend, api.sendMessage); export const fetchEnsRecord = doRequest.bind(null, ensRecord, api.fetchEnsRecord); @@ -88,6 +89,10 @@ export function *watchFetchContractProfile() { yield takeEvery(actions.CONTRACT_PROFILE[actions.REQUEST], fetchContractProfile); } +export function *watchFetchContractFile() { + yield takeEvery(actions.CONTRACT_FILE[actions.REQUEST], fetchContractFile); +} + export function *watchFetchVersions() { yield takeEvery(actions.VERSIONS[actions.REQUEST], fetchVersions); } @@ -193,11 +198,12 @@ export default function *root() { fork(watchFetchPlugins), fork(watchFetchBlocks), fork(watchFetchContracts), + fork(watchFetchContractProfile), + fork(watchFetchContractFile), fork(watchListenToMessages), fork(watchSendMessage), fork(watchFetchContract), fork(watchFetchTransaction), - fork(watchFetchContractProfile), fork(watchFetchFiddle), fork(watchFetchEnsRecord), fork(watchPostEnsRecords) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 6434611e..f40c577b 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -280,30 +280,6 @@ class ENS { }); } - registerSubdomains(subdomains, config, callback) { - const self = this; - - self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { - async.parallel({ - ens: self.createRegistryContract.bind(this, config), - registrar: self.createRegistrarContract.bind(this, config), - resolver: self.createResolverContract.bind(this, config) - }, function (err, contracts) { - if (err) { - return callback(err); - } - const {ens, registrar, resolver} = contracts; - - async.each(Object.keys(subdomains), (subdomainName, eachCb) => { - const address = subdomains[subdomainName]; - const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix); - ENSFunctions.registerSubDomain(ens, registrar, resolver, defaultAccount, subdomainName, - self.registration.rootDomain, reverseNode, address, self.logger, eachCb); - }, callback); - }); - }); - } - createRegistryContract(config, callback) { this.events.request("blockchain:contract:create", { abi: config.registryAbi,