Support multiple promises as data or mixed with non promises

This commit is contained in:
obscuren 2014-09-25 10:32:54 +02:00
parent 29f5dd38e3
commit d5d1e50365

View File

@ -92,18 +92,18 @@
promises.push(params.from.then(function(_from) { params.from = _from; })); promises.push(params.from.then(function(_from) { params.from = _from; }));
} }
if(isPromise(params.data)) { if(typeof params.data !== "object" || isPromise(params.data)) {
promises.push(params.data.then(function(_code) { params.data = _code; })); params.data = [params.data]
} else { }
if(typeof params.data === "object") {
data = ""; var data = params.data;
for(var i = 0; i < params.data.length; i++) { for(var i = 0; i < params.data.length; i++) {
data += params.data[i] if(isPromise(params.data[i])) {
} var promise = params.data[i];
} else { var _i = i;
data = params.data; promises.push(promise.then(function(_arg) { params.data[_i] = _arg; }));
} }
} }
// Make sure everything is string // Make sure everything is string
var fields = ["value", "gas", "gasPrice"]; var fields = ["value", "gas", "gasPrice"];
@ -117,6 +117,7 @@
// Load promises then call the last "transact". // Load promises then call the last "transact".
return Q.all(promises).then(function() { return Q.all(promises).then(function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
params.data = params.data.join("");
postData({call: "transact", args: params}, function(data) { postData({call: "transact", args: params}, function(data) {
if(data[1]) if(data[1])
reject(data[0]); reject(data[0]);
@ -458,6 +459,7 @@
g_seed++; g_seed++;
console.log(data)
navigator.qt.postMessage(JSON.stringify(data)); navigator.qt.postMessage(JSON.stringify(data));
} }