Skip to content

Commit 69fa1b2

Browse files
committed
adapt test app to work with 1.0
1 parent ef98346 commit 69fa1b2

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

js/build/embark.bundle.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ EmbarkJS.Contract = function(options) {
114114
ContractClass.setProvider(this.web3.currentProvider);
115115

116116
return ContractClass;
117-
118117
} else {
119118

120119

js/embark.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ EmbarkJS.Contract = function(options) {
3232
ContractClass.setProvider(this.web3.currentProvider);
3333

3434
return ContractClass;
35-
3635
} else {
3736

3837

lib/contracts/code_generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ result += "\n";
153153
connectionCode += "\nweb3.eth.getAccounts(function(err, account) { if(err) { next(null, true) } else { next(null, false) }})";
154154

155155
connectionCode += "\n}, function(err, _result) {";
156-
connectionCode += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
156+
connectionCode += "\nweb3.eth.getAccounts(function(err, accounts) {;";
157+
connectionCode += "\nweb3.eth.defaultAccount = accounts[0];";
157158
connectionCode += '\ndone();';
158159
connectionCode += "\n});";
160+
connectionCode += "\n});";
159161

160162
result += connectionCode;
161163
}

test_app/app/js/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,31 @@ $(document).ready(function() {
1111

1212
$("#blockchain button.set").click(function() {
1313
var value = parseInt($("#blockchain input.text").val(), 10);
14-
SimpleStorage.set(value);
15-
addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
14+
15+
// If web3.js 1.0 is being used
16+
if (EmbarkJS.isNewWeb3()) {
17+
SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount});
18+
addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})");
19+
} else {
20+
SimpleStorage.set(value);
21+
addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
22+
}
23+
1624
});
1725

1826
$("#blockchain button.get").click(function() {
19-
SimpleStorage.get().then(function(value) {
20-
$("#blockchain .value").html(value.toNumber());
21-
});
22-
addToLog("#blockchain", "SimpleStorage.get()");
27+
// If web3.js 1.0 is being used
28+
if (EmbarkJS.isNewWeb3()) {
29+
SimpleStorage.methods.get().call(function(err, value) {
30+
$("#blockchain .value").html(value);
31+
});
32+
addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
33+
} else {
34+
SimpleStorage.get().then(function(value) {
35+
$("#blockchain .value").html(value.toNumber());
36+
});
37+
addToLog("#blockchain", "SimpleStorage.get()");
38+
}
2339
});
2440

2541
});

0 commit comments

Comments
 (0)