2019-02-20 15:57:12 -05:00
|
|
|
/*global web3*/
|
|
|
|
import React from 'react';
|
2018-01-16 19:17:52 -05:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
2019-02-20 15:57:12 -05:00
|
|
|
import {SimpleStorage, Test, SimpleStorageTest} from '../../embarkArtifacts/contracts';
|
2018-01-16 19:17:52 -05:00
|
|
|
|
2019-02-20 15:57:12 -05:00
|
|
|
window.SimpleStorageTest = SimpleStorageTest;
|
2018-10-12 18:22:17 -04:00
|
|
|
|
2018-01-16 19:17:52 -05:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
|
2017-12-13 19:24:20 -05:00
|
|
|
import $ from 'jquery';
|
2018-01-17 13:16:43 -05:00
|
|
|
import 'bootstrap/dist/css/bootstrap.css';
|
|
|
|
import 'bootstrap/dist/css/bootstrap-theme.css';
|
2018-03-02 17:25:56 -05:00
|
|
|
import 'bootstrap/dist/js/bootstrap.min.js';
|
2017-12-13 17:36:24 -05:00
|
|
|
|
|
|
|
window.EmbarkJS = EmbarkJS;
|
2018-03-22 15:36:20 -04:00
|
|
|
window.SimpleStorage = SimpleStorage;
|
2017-12-20 11:32:11 -05:00
|
|
|
window.Test = Test;
|
2018-10-24 13:10:31 -04:00
|
|
|
//window.Assert = Assert;
|
2017-12-13 17:36:24 -05:00
|
|
|
|
2018-01-16 19:17:52 -05:00
|
|
|
window.React = React;
|
|
|
|
|
2017-12-13 17:36:24 -05:00
|
|
|
import './foo.css';
|
|
|
|
|
2018-01-17 13:16:43 -05:00
|
|
|
import App from './app.js';
|
2018-01-16 19:17:52 -05:00
|
|
|
|
|
|
|
ReactDOM.render(<App />, document.getElementById('root'));
|
|
|
|
|
2017-02-09 19:38:02 -05:00
|
|
|
var addToLog = function(id, txt) {
|
|
|
|
$(id + " .logs").append("<br>" + txt);
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// Blockchain example
|
|
|
|
// ===========================
|
|
|
|
$(document).ready(function() {
|
2019-02-22 14:10:53 -05:00
|
|
|
EmbarkJS.onReady((err) => {
|
2019-02-20 15:57:12 -05:00
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-13 17:36:24 -05:00
|
|
|
console.log([1,2,3].map(v => v + 1));
|
2017-02-09 19:38:02 -05:00
|
|
|
|
|
|
|
$("#blockchain button.set").click(function() {
|
|
|
|
var value = parseInt($("#blockchain input.text").val(), 10);
|
2017-10-07 21:02:05 -04:00
|
|
|
|
2018-11-29 17:12:15 -05:00
|
|
|
SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000});
|
|
|
|
addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000})");
|
2017-02-09 19:38:02 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#blockchain button.get").click(function() {
|
2018-11-29 17:12:15 -05:00
|
|
|
SimpleStorage.methods.get().call(function(err, value) {
|
|
|
|
$("#blockchain .value").html(value);
|
|
|
|
});
|
|
|
|
addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
|
2017-02-09 19:38:02 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// Storage (IPFS) example
|
|
|
|
// ===========================
|
|
|
|
$(document).ready(function() {
|
2017-06-27 16:01:54 -04:00
|
|
|
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
|
2017-02-28 23:29:16 -05:00
|
|
|
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
2017-02-09 19:38:02 -05:00
|
|
|
|
2017-10-09 08:59:02 -04:00
|
|
|
$("#storage .error").hide();
|
2017-12-13 17:36:24 -05:00
|
|
|
//EmbarkJS.Storage.ipfsConnection.version()
|
|
|
|
// .then(function(){
|
2017-10-25 06:19:24 -04:00
|
|
|
$("#status-storage").addClass('status-online');
|
|
|
|
$("#storage-controls").show();
|
2017-12-13 17:36:24 -05:00
|
|
|
// })
|
|
|
|
// .catch(function(err) {
|
|
|
|
// if(err){
|
|
|
|
// console.log("IPFS Connection Error => " + err.message);
|
|
|
|
// $("#storage .error").show();
|
|
|
|
// $("#status-storage").addClass('status-offline');
|
|
|
|
// $("#storage-controls").hide();
|
|
|
|
// }
|
|
|
|
// });
|
2017-10-09 08:59:02 -04:00
|
|
|
|
|
|
|
$("#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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#storage button.loadIpfsFile").click(function() {
|
|
|
|
var hash = $("#storage input.fileIpfsHash").val();
|
|
|
|
var url = EmbarkJS.Storage.getUrl(hash);
|
|
|
|
var link = '<a href="' + url + '" target="_blank">' + url + '</a>';
|
|
|
|
$("span.ipfsFileUrl").html(link);
|
|
|
|
$(".ipfsImage").attr('src', url);
|
|
|
|
addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
|
|
|
|
});
|
2017-02-09 19:38:02 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// Communication (Whisper) example
|
|
|
|
// ===========================
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
2017-10-09 08:59:02 -04:00
|
|
|
$("#communication .error").hide();
|
|
|
|
$("#communication .errorVersion").hide();
|
|
|
|
if (EmbarkJS.Messages.providerName === 'whisper') {
|
2019-02-20 15:57:12 -05:00
|
|
|
EmbarkJS.Messages.getWhisperVersion(function(err, _version) {
|
2017-10-09 08:59:02 -04:00
|
|
|
if (err) {
|
|
|
|
$("#communication .error").show();
|
|
|
|
$("#communication-controls").hide();
|
|
|
|
$("#status-communication").addClass('status-offline');
|
|
|
|
} else {
|
|
|
|
EmbarkJS.Messages.setProvider('whisper');
|
|
|
|
$("#status-communication").addClass('status-online');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#communication button.listenToChannel").click(function() {
|
|
|
|
var channel = $("#communication .listen input.channel").val();
|
|
|
|
$("#communication #subscribeList").append("<br> subscribed to " + channel + " now try sending a message");
|
2019-02-11 00:08:01 -06:00
|
|
|
EmbarkJS.Messages.listenTo({topic: [channel]}).subscribe(function({data: message}) {
|
2017-10-09 08:59:02 -04:00
|
|
|
$("#communication #messagesList").append("<br> 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 + "'})");
|
|
|
|
});
|
2017-02-09 19:38:02 -05:00
|
|
|
|
|
|
|
});
|