Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide UI inputs until contract is deployed #233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/editor/templates/Coin/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ body {
color: #FCE8DF;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
text-align: center;
}

.hidden {
display: none;
}
82 changes: 42 additions & 40 deletions packages/editor/templates/Coin/app/app.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://unpkg.com/jquery@3.3.1/dist/jquery.js"></script>
<script type="text/javascript" src="https://unpkg.com/web3@0.20.5/dist/web3.min.js"></script>
<!-- The generated javascript and app.js will be substituted in below -->
<!-- JAVASCRIPT -->

<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://unpkg.com/jquery@3.3.1/dist/jquery.js"></script>
<script type="text/javascript" src="https://unpkg.com/web3@0.20.5/dist/web3.min.js"></script>
<!-- The generated javascript and app.js will be substituted in below -->
<!-- JAVASCRIPT -->

<!-- The app.css contents will be substituted in below -->
<!-- STYLE -->
</head>

<body>
<!-- Form fields for creating new coins -->
<div id="create" class="tabcontent">
<h2>Create new coins</h2>
<div class="input-group">
<h3>Address</h3>
<input type="text" id="create-address" placeholder="Enter address..." />
</div>
<div class="input-group">
<h3>Amount</h3>
<input type="number" id="create-amount" placeholder="Enter amount..." />
</div>
<div class="input-group">
<button class="btn" id="button-create">Send</button>
<!-- The app.css contents will be substituted in below -->
<!-- STYLE -->
</head>
<body>
<div id="welcome-container">
<h1>Welcome!</h1>
<h3>Please deploy (<img src="/static/img/rocket-ship.svg" color="#fff" height="14" width="14">) your contract to begin.</h3>
</div>
</div>
<!-- Form fields for checking wallet balances -->
<div id="balances" class="tabcontent">
<h2>Check balance of wallet</h2>
<div class="input-group">
<h3>Address</h3>
<input type="text" id="balance-address" placeholder="Enter address..." />
<div id="main-container" class="hidden">
<!-- Form fields for creating new coins -->
<div id="create" class="tabcontent">
<h2>Create new coins</h2>
<div class="input-group">
<h3>Address</h3>
<input type="text" id="create-address" placeholder="Enter address..." />
</div>
<div class="input-group">
<h3>Amount</h3>
<input type="number" id="create-amount" placeholder="Enter amount..." />
</div>
<div class="input-group">
<button class="btn" id="button-create">Send</button>
</div>
</div>
<!-- Form fields for checking wallet balances -->
<div id="balances" class="tabcontent">
<h2>Check balance of wallet</h2>
<div class="input-group">
<h3>Address</h3>
<input type="text" id="balance-address" placeholder="Enter address..." />
</div>
<div class="input-group">
<button class="btn" id="button-check">Check balance</button>
</div>
</div>
<h1 class="text message">Balance:&nbsp;<span id="message"></span></h1>
</div>
<div class="input-group">
<button class="btn" id="button-check">Check balance</button>
</div>
</div>

<h1 class="text message">Balance:&nbsp;<span id="message"></span></h1>
</body>

</body>
</html>
27 changes: 25 additions & 2 deletions packages/editor/templates/Coin/app/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The object 'Contracts' will be injected here, which contains all data for all contracts, keyed on contract name:
// Contracts['HelloWorld'] = {
// Contracts['Coin'] = {
// abi: [],
// address: "0x..",
// endpoint: "http://...."
Expand Down Expand Up @@ -158,10 +158,33 @@ Coin.prototype.bindButtons = function() {
});
}

// Remove the welcome content, and display the main content.
// Called once a contract has been deployed
Coin.prototype.updateDisplayContent = function() {
this.hideWelcomeContent();
this.showMainContent();
};

// A contract will not have its address set until it has been deployed
Coin.prototype.hasContractDeployed = function() {
return this.instance && this.instance.address;
};

Coin.prototype.hideWelcomeContent = function() {
$('#welcome-container').addClass('hidden');
};

Coin.prototype.showMainContent = function() {
$('#main-container').removeClass('hidden');
};

// Create the instance of the `Coin` object
Coin.prototype.onReady = function() {
this.bindButtons();
this.init();
if (this.hasContractDeployed()) {
this.updateDisplayContent();
this.bindButtons();
}
};

if(typeof(Contracts) === "undefined") var Contracts={ Coin: { abi: [] }};
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/templates/Crypto Pizzas/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hr {
opacity: .6;
}

.error {
.error, .hidden {
display: none;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/editor/templates/Crypto Pizzas/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
</head>
<body>
<div id="status"></div>
<div id="welcome-container" class="container">
<h1>Welcome!</h1>
<h3 id="start-message">Please deploy (<img src="/static/img/rocket-ship.svg" color="#fff" height="14" width="14">) your contract to begin.</h3>
</div>

<div class="container">
<div id="main-container" class="container hidden">
<!-- Header -->
<header>
<h1>CryptoPizza</h1>
Expand Down
24 changes: 24 additions & 0 deletions packages/editor/templates/Crypto Pizzas/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.updateDisplayContent();
}
}

// Generate random DNA from string
Expand Down Expand Up @@ -351,6 +355,26 @@ Pizza.prototype.bindInputs = function() {
});
}

// Remove the welcome content, and display the main content.
// Called once a contract has been deployed
Pizza.prototype.updateDisplayContent = function() {
this.hideWelcomeContent();
this.showMainContent();
}

Pizza.prototype.hideWelcomeContent = function() {
$('#welcome-container').addClass('hidden');
}

Pizza.prototype.showMainContent = function() {
$('#main-container').removeClass('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");
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/templates/Hello World/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ body {
text-align: center;
}

.text {
.text, .hidden {
display: none;
}

.error {
color: red;
}

.input-group {
.input-group, .display-message {
display: flex;
flex-direction: column;
align-items: center;
Expand Down
34 changes: 21 additions & 13 deletions packages/editor/templates/Hello World/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@
<!-- STYLE -->
</head>
<body>
<!-- Displays message passed via JavaScript -->
<h1 class="text message">Message:&nbsp;<span id="message"></span></h1>
<!-- Displays blocknumber passed via JavaScript -->
<h2 class="text blocknumber">Block number:&nbsp;<span id="blocknumber"></span></h2>
<h2 class="text error">There was an error communicating with the contract.</h2>
<!-- Form field for updating the message -->
<div id="create" class="tabcontent">
<div class="input-group">
<h3>Update Message</h3>
<input type="text" id="message-input" placeholder="Enter new message..." />
<div id="welcome-container">
<h1>Welcome!</h1>
<h3>Please deploy (<img src="/static/img/rocket-ship.svg" color="#fff" height="14" width="14">) your contract to begin.</h3>
</div>
<div id="main-container" class="hidden">
<div>
<!-- Displays message passed via JavaScript -->
<h1 class="text message">Message:&nbsp;<span id="message"></span></h1>
<!-- Displays blocknumber passed via JavaScript -->
<h2 class="text blocknumber">Block number:&nbsp;<span id="blocknumber"></span></h2>
</div>
<div class="input-group">
<button class="btn" id="message-button">Send</button>
<div id="loader" style="display: none;"></div>
<h2 class="text error">There was an error communicating with the contract.</h2>
<!-- Form field for updating the message -->
<div id="create" class="tabcontent">
<div class="input-group">
<h3>Update Message</h3>
<input type="text" id="message-input" placeholder="Enter new message..." />
</div>
<div class="input-group">
<button class="btn" id="message-button">Send</button>
<div id="loader" style="display: none;"></div>
</div>
</div>
</div>
</body>
Expand Down
29 changes: 27 additions & 2 deletions packages/editor/templates/Hello World/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,27 @@ HelloWorld.prototype.bindButton = function() {
});
};

// Creates the instance of the `HelloWorld` object
// Remove the welcome content, and display the main content.
// Called once a contract has been deployed
HelloWorld.prototype.updateDisplayContent = function() {
this.hideWelcomeContent();
this.showMainContent();
};

// A contract will not have its address set until it has been deployed
HelloWorld.prototype.hasContractDeployed = function() {
return this.instance && this.instance.address;
};

HelloWorld.prototype.hideWelcomeContent = function() {
$('#welcome-container').addClass('hidden');
};

HelloWorld.prototype.showMainContent = function() {
$('#main-container').removeClass('hidden');
};

// JavaScript boilerplate to create the instance of the `HelloWorld` object
// defined above, and show the HTML elements on the page:
HelloWorld.prototype.main = function() {
$(".blocknumber").show();
Expand All @@ -160,7 +180,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.updateDisplayContent();
this.bindButton();
}
this.main();
};

Expand Down