adapt test app to work with 1.0

This commit is contained in:
Iuri Matias 2017-10-07 21:02:05 -04:00
parent ef98346963
commit 69fa1b24c3
4 changed files with 25 additions and 9 deletions

View File

@ -114,7 +114,6 @@ EmbarkJS.Contract = function(options) {
ContractClass.setProvider(this.web3.currentProvider);
return ContractClass;
} else {

View File

@ -32,7 +32,6 @@ EmbarkJS.Contract = function(options) {
ContractClass.setProvider(this.web3.currentProvider);
return ContractClass;
} else {

View File

@ -153,9 +153,11 @@ result += "\n";
connectionCode += "\nweb3.eth.getAccounts(function(err, account) { if(err) { next(null, true) } else { next(null, false) }})";
connectionCode += "\n}, function(err, _result) {";
connectionCode += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
connectionCode += "\nweb3.eth.getAccounts(function(err, accounts) {;";
connectionCode += "\nweb3.eth.defaultAccount = accounts[0];";
connectionCode += '\ndone();';
connectionCode += "\n});";
connectionCode += "\n});";
result += connectionCode;
}

View File

@ -11,15 +11,31 @@ $(document).ready(function() {
$("#blockchain button.set").click(function() {
var value = parseInt($("#blockchain input.text").val(), 10);
SimpleStorage.set(value);
addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
// 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 + ")");
}
});
$("#blockchain button.get").click(function() {
SimpleStorage.get().then(function(value) {
$("#blockchain .value").html(value.toNumber());
});
addToLog("#blockchain", "SimpleStorage.get()");
// 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()");
}
});
});