Browse Source

'web3' and 'contracts' for JS context instead of 'deploy'

cl-refactor
arkpar 10 years ago
parent
commit
48dee28af5
  1. 4
      mix/qml/WebPreview.qml
  2. 16
      mix/qml/html/WebContainer.html
  3. 14
      mix/qml/js/ProjectModel.js

4
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 = "<script>deploy=parent.deploy</script>\n" + content;
content = "<script>web3=parent.web3;contracts=parent.contracts;</script>\n" + content;
_request.setResponseContentType("text/html");
}
_request.setResponse(content);

16
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,
};
}
};

14
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");

Loading…
Cancel
Save