diff --git a/mix/qml/WebPreview.qml b/mix/qml/WebPreview.qml
index 08f25b3df..10d0b3c83 100644
--- a/mix/qml/WebPreview.qml
+++ b/mix/qml/WebPreview.qml
@@ -28,7 +28,7 @@ Item {
}
function updateContract() {
- webView.runJavaScript("updateContract(\"" + clientModel.contractAddress + "\", " + codeModel.code.contractInterface + ")");
+ webView.runJavaScript("updateContract(\"" + codeModel.code.contract.name + "\", \"" + clientModel.contractAddress + "\", " + codeModel.code.contractInterface + ")");
}
function reloadOnSave() {
@@ -136,7 +136,7 @@ Item {
content = fileIo.readFile(projectModel.getDocument(documentId).path);
if (documentId === pageListModel.get(pageCombo.currentIndex).documentId) {
//root page, inject deployment script
- content = "\n" + content;
+ content = "\n" + content;
_request.setResponseContentType("text/html");
}
_request.setResponse(content);
diff --git a/mix/qml/html/WebContainer.html b/mix/qml/html/WebContainer.html
index 372860209..09a8734d5 100644
--- a/mix/qml/html/WebContainer.html
+++ b/mix/qml/html/WebContainer.html
@@ -15,17 +15,15 @@ reloadPage = function() {
preview.contentWindow.location.reload();
};
-updateContract = function(address, contractFace) {
+updateContract = function(name, address, contractFace) {
if (window.web3) {
window.web3.provider.polls = [];
- window.contractAddress = address;
- window.contractInterface = contractFace;
- window.contract = window.web3.eth.contract(address, contractFace);
- window.deploy = {
- contractAddress: address,
- contractInterface: contractFace,
- contract: window.contract,
- web3: window.web3
+ var contract = window.web3.eth.contract(address, contractFace);
+ window.contracts = {};
+ window.contracts[name] = {
+ address: address,
+ interface: contractFace,
+ contract: contract,
};
}
};
diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js
index fb6872bd4..be6c07c5b 100644
--- a/mix/qml/js/ProjectModel.js
+++ b/mix/qml/js/ProjectModel.js
@@ -326,16 +326,16 @@ function finalizeDeployment(deploymentId, address) {
fileIo.copyFile(doc.path, deploymentDir + doc.fileName);
}
//write deployment js
+ var contractAccessor = "contracts[\"" + codeModel.code.contract.name + "\"]";
var deploymentJs =
"// Autogenerated by Mix\n" +
- "var web3 = require(\"web3\");\n" +
- "var contractInterface = " + codeModel.code.contractInterface + ";\n" +
- "deploy = {\n" +
- "\tweb3: web3,\n" +
- "\tcontractAddress: \"" + address + "\",\n" +
- "\tcontractInterface: contractInterface,\n" +
+ "web3 = require(\"web3\");\n" +
+ "contracts = {};\n" +
+ contractAccessor + " = {\n" +
+ "\tinterface: " + codeModel.code.contractInterface + ",\n" +
+ "\taddress: \"" + address + "\"\n" +
"};\n" +
- "deploy.contract = web3.eth.contract(deploy.contractAddress, deploy.contractInterface);\n";
+ contractAccessor + ".contract = web3.eth.contract(" + contractAccessor + ".address, " + contractAccessor + ".interface);\n";
fileIo.writeFile(deploymentDir + "deployment.js", deploymentJs);
//copy scripts
fileIo.copyFile("qrc:///js/bignumber.min.js", deploymentDir + "bignumber.min.js");