diff --git a/templates/demo/app/components/blockchain.js b/templates/demo/app/components/blockchain.js
new file mode 100644
index 0000000000..b9e5e313c0
--- /dev/null
+++ b/templates/demo/app/components/blockchain.js
@@ -0,0 +1,91 @@
+import EmbarkJS from 'Embark/EmbarkJS';
+import SimpleStorage from 'Embark/contracts/SimpleStorage';
+import React from 'react';
+import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
+
+class Blockchain extends React.Component {
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ valueSet: 10,
+ valueGet: "",
+ logs: []
+ }
+ }
+
+ handleChange(e){
+ this.setState({valueSet: e.target.value});
+ }
+
+ setValue(e){
+ e.preventDefault();
+
+ var value = parseInt(this.state.valueSet, 10);
+
+ // If web3.js 1.0 is being used
+ if (EmbarkJS.isNewWeb3()) {
+ SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount});
+ this._addToLog("SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})");
+ } else {
+ SimpleStorage.set(value);
+ this._addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
+ }
+ }
+
+ getValue(e){
+ e.preventDefault();
+
+ if (EmbarkJS.isNewWeb3()) {
+ SimpleStorage.methods.get().call()
+ .then(_value => this.setState({valueGet: _value}))
+ this._addToLog("SimpleStorage.methods.get(console.log)");
+ } else {
+ SimpleStorage.get()
+ .then(_value => this.setState({valueGet: _value}));
+ this._addToLog("SimpleStorage.get()");
+ }
+ }
+
+ _addToLog(txt){
+ this.state.logs.push(txt);
+ this.setState({logs: this.state.logs});
+ }
+
+ render(){
+ return ( Javascript calls being made: {item} Javascript calls being made: EmbarkJS.Storage.setProvider('ipfs',{'{'}server: 'localhost', port: '5001'{'}'}) {item} Javascript calls being made: EmbarkJS.Messages.setProvider('whisper') {item} 1. Set the value in the blockchain
+
+
+ 2. Get the current value
+
+
+ 3. Contract Calls
+ Save text to storage
+
+
+ Load text from storage given an hash
+
+
+ Upload file to storage
+
+
+ Get file or image from storage
+
+
+ Listen To channel
+
+
+ Send Message
+
+
+
" + txt);
-};
+class App extends React.Component {
-// ===========================
-// Blockchain example
-// ===========================
-$(document).ready(function() {
+ constructor(props) {
+ super(props);
- $("#blockchain button.set").click(function() {
- var value = parseInt($("#blockchain input.text").val(), 10);
-
- // If web3.js 1.0 is being used
- if (EmbarkJS.isNewWeb3()) {
- SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount});
- addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})");
- } else {
- SimpleStorage.set(value);
- addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
+ this.state = {
+ whisperEnabled: false,
+ storageEnabled: false
}
+ }
- });
-
- $("#blockchain button.get").click(function() {
- // If web3.js 1.0 is being used
- if (EmbarkJS.isNewWeb3()) {
- SimpleStorage.methods.get().call(function(err, value) {
- $("#blockchain .value").html(value);
- });
- addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
- } else {
- SimpleStorage.get().then(function(value) {
- $("#blockchain .value").html(value.toNumber());
- });
- addToLog("#blockchain", "SimpleStorage.get()");
- }
- });
-
-});
-
-// ===========================
-// Storage (IPFS) example
-// ===========================
-$(document).ready(function() {
- // automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
- //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
-
- $("#storage .error").hide();
- //EmbarkJS.Storage.ipfsConnection.version()
- // .then(function(){
- $("#status-storage").addClass('status-online');
- $("#storage-controls").show();
- // })
- // .catch(function(err) {
- // if(err){
- // console.log("IPFS Connection Error => " + err.message);
- // $("#storage .error").show();
- // $("#status-storage").addClass('status-offline');
- // $("#storage-controls").hide();
- // }
- // });
-
- $("#storage button.setIpfsText").click(function() {
- var value = $("#storage input.ipfsText").val();
- EmbarkJS.Storage.saveText(value).then(function(hash) {
- $("span.textHash").html(hash);
- $("input.textHash").val(hash);
- addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
- })
- .catch(function(err) {
- if(err){
- console.log("IPFS saveText Error => " + err.message);
- }
- });
- });
-
- $("#storage button.loadIpfsHash").click(function() {
- var value = $("#storage input.textHash").val();
- EmbarkJS.Storage.get(value).then(function(content) {
- $("span.ipfsText").html(content);
- addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
- })
- .catch(function(err) {
- if(err){
- console.log("IPFS get Error => " + err.message);
+ componentDidMount(){
+ __embarkContext.execWhenReady(() => {
+ if (EmbarkJS.isNewWeb3()) {
+ EmbarkJS.Messages.Providers.whisper.getWhisperVersion((err, version) => {
+ if(!err)
+ this.setState({whisperEnabled: true})
+ else
+ console.log(err);
+ });
+ } else {
+ if (EmbarkJS.Messages.providerName === 'whisper') {
+ EmbarkJS.Messages.getWhisperVersion((err, version) => {
+ if(!err)
+ this.setState({whisperEnabled: true})
+ else
+ console.log(err);
+ });
+ }
}
- });
- });
- $("#storage button.uploadFile").click(function() {
- var input = $("#storage input[type=file]");
- EmbarkJS.Storage.uploadFile(input).then(function(hash) {
- $("span.fileIpfsHash").html(hash);
- $("input.fileIpfsHash").val(hash);
- addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
- })
- .catch(function(err) {
- if(err){
- console.log("IPFS uploadFile Error => " + err.message);
- }
+ this.setState({
+ storageEnabled: true
+ });
});
- });
-
- $("#storage button.loadIpfsFile").click(function() {
- var hash = $("#storage input.fileIpfsHash").val();
- var url = EmbarkJS.Storage.getUrl(hash);
- var link = '' + url + '';
- $("span.ipfsFileUrl").html(link);
- $(".ipfsImage").attr('src', url);
- addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
- });
-
-});
+ }
-// ===========================
-// Communication (Whisper) example
-// ===========================
-$(document).ready(function() {
- $("#communication .error").hide();
- $("#communication .errorVersion").hide();
- if (EmbarkJS.Messages.providerName === 'whisper') {
- EmbarkJS.Messages.getWhisperVersion(function(err, version) {
- if (err) {
- $("#communication .error").show();
- $("#communication-controls").hide();
- $("#status-communication").addClass('status-offline');
- } else {
- EmbarkJS.Messages.setProvider('whisper');
- $("#status-communication").addClass('status-online');
- }
- });
+ _renderStatus(title, available){
+ let className = available ? 'pull-right status-online' : 'pull-right status-offline';
+ return
subscribed to " + channel + " now try sending a message");
- EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) {
- $("#communication #messagesList").append("
channel: " + channel + " message: " + message);
- });
- addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})");
- });
-
- $("#communication button.sendMessage").click(function() {
- var channel = $("#communication .send input.channel").val();
- var message = $("#communication .send input.message").val();
- EmbarkJS.Messages.sendMessage({topic: channel, data: message});
- addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})");
- });
+ render(){
+ return (
Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain.
-Click the button to get the current value. The initial value is 100.
-Javascript calls being made:
-generated Hash:
-result:
-generated hash:
-file available at:
-Javascript calls being made:
-messages received:
-
-Javascript calls being made:
-