From 6ea81293ec2a32909040e8796f8189d7f3b7023f Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 19 Apr 2018 09:59:48 -0400 Subject: [PATCH] Handling errors and UI reorganization / features - UI shows error screen if contract doesn't exist or fails fetching data - Menu shows selected state and icons can be specified - Component created for card alerts --- .../contracts/components/account-list.js | 10 +--------- .../backend/contracts/components/card-alert.js | 13 +++++++++++++ .../contracts/components/contract-ui.js | 7 +++---- .../contracts/components/function-form.js | 13 ++++--------- .../backend/contracts/components/function.js | 2 +- .../backend/contracts/components/menu-item.js | 11 +++++++++-- .../webserver/backend/contracts/view.html | 4 +++- .../webserver/backend/contracts/view.js | 18 ++++++++++++++++-- 8 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 lib/modules/webserver/backend/contracts/components/card-alert.js diff --git a/lib/modules/webserver/backend/contracts/components/account-list.js b/lib/modules/webserver/backend/contracts/components/account-list.js index 10328b93..abb3b96a 100644 --- a/lib/modules/webserver/backend/contracts/components/account-list.js +++ b/lib/modules/webserver/backend/contracts/components/account-list.js @@ -33,15 +33,7 @@ class AccountList extends React.Component {

Get Accounts

- { - this.state.error - ? -
- {this.state.errorMessage} -
- : - '' - } +
diff --git a/lib/modules/webserver/backend/contracts/components/card-alert.js b/lib/modules/webserver/backend/contracts/components/card-alert.js new file mode 100644 index 00000000..890f4fe9 --- /dev/null +++ b/lib/modules/webserver/backend/contracts/components/card-alert.js @@ -0,0 +1,13 @@ +class CardAlert extends React.Component { + render(){ + return this.props.show ? +
+ {this.props.message} +
+ : + ''; + } +} + + + diff --git a/lib/modules/webserver/backend/contracts/components/contract-ui.js b/lib/modules/webserver/backend/contracts/components/contract-ui.js index 707e7788..164e06db 100644 --- a/lib/modules/webserver/backend/contracts/components/contract-ui.js +++ b/lib/modules/webserver/backend/contracts/components/contract-ui.js @@ -27,7 +27,6 @@ class ContractUI extends React.Component { } handleMenuClick(e){ - console.log(e.target); e.preventDefault(); this.setState({ selectedTab: e.target.getAttribute('data-target') @@ -66,9 +65,9 @@ class ContractUI extends React.Component {

{this.props.name}

- - - + + +
diff --git a/lib/modules/webserver/backend/contracts/components/function-form.js b/lib/modules/webserver/backend/contracts/components/function-form.js index 6fcb8139..9e557b1e 100644 --- a/lib/modules/webserver/backend/contracts/components/function-form.js +++ b/lib/modules/webserver/backend/contracts/components/function-form.js @@ -39,15 +39,10 @@ class FunctionForm extends React.Component { : "" } - { - this.state.error - ? -
- {this.state.message} -
- : - '' - } + + + +
diff --git a/lib/modules/webserver/backend/contracts/components/function.js b/lib/modules/webserver/backend/contracts/components/function.js index 030f477a..dffd6aaf 100644 --- a/lib/modules/webserver/backend/contracts/components/function.js +++ b/lib/modules/webserver/backend/contracts/components/function.js @@ -162,7 +162,7 @@ class Function extends React.Component { return { this.props.abi.inputs - .map((input, i) => ) + .map((input, i) => ) .reduce((accu, elem) => { return accu === null ? [elem] : [...accu, ', ', elem] }, null) diff --git a/lib/modules/webserver/backend/contracts/components/menu-item.js b/lib/modules/webserver/backend/contracts/components/menu-item.js index f975e79e..1224d13c 100644 --- a/lib/modules/webserver/backend/contracts/components/menu-item.js +++ b/lib/modules/webserver/backend/contracts/components/menu-item.js @@ -1,7 +1,14 @@ class MenuItem extends React.Component { render(){ - return - {this.props.text} + + let classNames = "list-group-item list-group-item-action d-flex align-items-center "; + let icon = "fe " + this.props.icon; + if(this.props.target == this.props.selectedTab){ + classNames += "active"; + } + + return + {this.props.text} ; } } diff --git a/lib/modules/webserver/backend/contracts/view.html b/lib/modules/webserver/backend/contracts/view.html index 71cf91d8..34371d55 100644 --- a/lib/modules/webserver/backend/contracts/view.html +++ b/lib/modules/webserver/backend/contracts/view.html @@ -54,6 +54,7 @@ + @@ -172,10 +173,11 @@
+ +
-
diff --git a/lib/modules/webserver/backend/contracts/view.js b/lib/modules/webserver/backend/contracts/view.js index d989dc83..d0332774 100644 --- a/lib/modules/webserver/backend/contracts/view.js +++ b/lib/modules/webserver/backend/contracts/view.js @@ -25,8 +25,8 @@ fetch("/embark/console", { window.web3 = web3; let contractObj = new web3.eth.Contract(contractDefinition.abiDefinition); - contractObj.options.data = "0x" + contractDefinition.code; - contractObj.options.address = contractDefinition.deployedAddress; + contractObj.options.data = "0x" + contractDefinition.code; + contractObj.options.address = contractDefinition.deployedAddress; window[contractDefinition.className] = contractObj; @@ -34,4 +34,18 @@ fetch("/embark/console", { , document.getElementById('contracts-area') ); + }) +.catch(function(err) { + console.log('%cError while rendering UI', 'font-weight: bold'); + console.error(err); + + ReactDOM.render( +
+

Error rendering the UI

+

UI for "{contractName}" cannot be generated

+
, + document.getElementById('contracts-area') + ); + + });