From e216eab16bda2b44fed32db18bc97963b6c999f0 Mon Sep 17 00:00:00 2001 From: Nate Lapinski Date: Thu, 14 May 2020 21:29:09 +0900 Subject: [PATCH 1/4] Check if Contract.address is set before displaying any UI input elements. Update some html/css to hide input elements by default, and display a welcome message instead. --- .../templates/Crypto Pizzas/app/app.css | 2 +- .../templates/Crypto Pizzas/app/app.html | 5 +++-- .../editor/templates/Crypto Pizzas/app/app.js | 17 ++++++++++++++++ .../editor/templates/Hello World/app/app.css | 4 ++-- .../editor/templates/Hello World/app/app.html | 8 +++++++- .../editor/templates/Hello World/app/app.js | 20 ++++++++++++++++++- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/editor/templates/Crypto Pizzas/app/app.css b/packages/editor/templates/Crypto Pizzas/app/app.css index b648cfa9..0f27a7e7 100755 --- a/packages/editor/templates/Crypto Pizzas/app/app.css +++ b/packages/editor/templates/Crypto Pizzas/app/app.css @@ -35,7 +35,7 @@ hr { opacity: .6; } -.error { +.error, .hidden { display: none; } diff --git a/packages/editor/templates/Crypto Pizzas/app/app.html b/packages/editor/templates/Crypto Pizzas/app/app.html index 71f45e89..3b4f7bdd 100755 --- a/packages/editor/templates/Crypto Pizzas/app/app.html +++ b/packages/editor/templates/Crypto Pizzas/app/app.html @@ -57,8 +57,9 @@

Create new CryptoPizza

- - + + +

Please deploy () your contract to begin.

diff --git a/packages/editor/templates/Crypto Pizzas/app/app.js b/packages/editor/templates/Crypto Pizzas/app/app.js index 9b909311..375d4b8e 100755 --- a/packages/editor/templates/Crypto Pizzas/app/app.js +++ b/packages/editor/templates/Crypto Pizzas/app/app.js @@ -37,6 +37,10 @@ Pizza.prototype.init = function() { // Create the contract instance for the specific address provided in the configuration. this.instance = this.Contract.address ? contract_interface.at(this.Contract.address) : { getPizzasByOwner: () => {} }; + + if (this.hasContractDeployed()) { + this.activateInputElements(); + } } // Generate random DNA from string @@ -351,6 +355,19 @@ Pizza.prototype.bindInputs = function() { }); } +// Show Input elements in app.html once the contract has been deployed, +// and hide the starter message. +Pizza.prototype.activateInputElements = function() { + $('#create-name').removeClass('hidden'); + $('#button-create').removeClass('hidden'); + $('#start-message').addClass('hidden'); +} + +// A contract will not have its address set until it has been deployed +Pizza.prototype.hasContractDeployed = function() { + return this.instance && this.instance.address; +}; + // Show status on bottom of the page when some action happens function showStatus(text) { var status = document.getElementById("status"); diff --git a/packages/editor/templates/Hello World/app/app.css b/packages/editor/templates/Hello World/app/app.css index c203b507..910decc9 100755 --- a/packages/editor/templates/Hello World/app/app.css +++ b/packages/editor/templates/Hello World/app/app.css @@ -5,7 +5,7 @@ body { text-align: center; } -.text { +.text, .hidden { display: none; } @@ -13,7 +13,7 @@ body { color: red; } -.input-group { +.input-group, .display-message { display: flex; flex-direction: column; align-items: center; diff --git a/packages/editor/templates/Hello World/app/app.html b/packages/editor/templates/Hello World/app/app.html index 096482fc..9d44040e 100755 --- a/packages/editor/templates/Hello World/app/app.html +++ b/packages/editor/templates/Hello World/app/app.html @@ -17,7 +17,7 @@

Message: 

Block number: 

There was an error communicating with the contract.

-
+ + +
+
+

Please deploy () your contract to begin.

+
+
diff --git a/packages/editor/templates/Hello World/app/app.js b/packages/editor/templates/Hello World/app/app.js index 168fff69..d3af7f05 100755 --- a/packages/editor/templates/Hello World/app/app.js +++ b/packages/editor/templates/Hello World/app/app.js @@ -150,6 +150,19 @@ HelloWorld.prototype.bindButton = function() { }); }; +// Show Input elements in app.html once the contract has been deployed, +// and hide the starter message. +HelloWorld.prototype.activateInputElements = function() { + $("#create").removeClass("hidden"); + $("#welcome-text").removeClass("display-message"); + $("#welcome-text").addClass("hidden"); +}; + +// A contract will not have its address set until it has been deployed +HelloWorld.prototype.hasContractDeployed = function() { + return this.instance && this.instance.address; +}; + // JavaScript boilerplate to create the instance of the `HelloWorld` object // defined above, and show the HTML elements on the page: HelloWorld.prototype.main = function() { @@ -160,7 +173,12 @@ HelloWorld.prototype.main = function() { HelloWorld.prototype.onReady = function() { this.init(); - this.bindButton(); + // Don't show interactive UI elements like input/button until + // the contract has been deployed. + if (this.hasContractDeployed()) { + this.activateInputElements(); + this.bindButton(); + } this.main(); }; From 5c3d16e99d5ef6a31d23e780bc38bb8e96d09562 Mon Sep 17 00:00:00 2001 From: Nate Lapinski Date: Sat, 6 Jun 2020 17:08:46 +0900 Subject: [PATCH 2/4] Update HelloWorld template to display a welcome message until the contract has been deployed. --- packages/editor/templates/Hello World/app/app.html | 13 +++++++++---- packages/editor/templates/Hello World/app/app.js | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/editor/templates/Hello World/app/app.html b/packages/editor/templates/Hello World/app/app.html index 9d44040e..dbf6f7a4 100755 --- a/packages/editor/templates/Hello World/app/app.html +++ b/packages/editor/templates/Hello World/app/app.html @@ -11,10 +11,15 @@ - -

Message: 

- -

Block number: 

+ +
+

Welcome!

+

There was an error communicating with the contract.