mirror of
https://github.com/status-im/status-react.git
synced 2025-02-02 06:07:33 +00:00
web3 coinbase async fix
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
26dd1c1f5a
commit
af7c356134
@ -24,35 +24,41 @@ var StatusHttpProvider = function (host, timeout) {
|
|||||||
|
|
||||||
StatusHttpProvider.prototype.isStatus = true;
|
StatusHttpProvider.prototype.isStatus = true;
|
||||||
|
|
||||||
function syncResponse(payload, result){
|
function web3Response (payload, result){
|
||||||
return {id: payload.id,
|
return {id: payload.id,
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
result: result};
|
result: result};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSyncResponse (payload) {
|
||||||
|
if (payload.method == "eth_accounts"){
|
||||||
|
return web3Response(payload, [currentAccountAddress])
|
||||||
|
} else if (payload.method == "eth_coinbase"){
|
||||||
|
return web3Response(payload, currentAccountAddress)
|
||||||
|
} else if (payload.method == "net_version"){
|
||||||
|
return web3Response(payload, networkId)
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StatusHttpProvider.prototype.send = function (payload) {
|
StatusHttpProvider.prototype.send = function (payload) {
|
||||||
//TODO to be compatible with MM https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client
|
//TODO to be compatible with MM https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client
|
||||||
if (payload.method == "eth_accounts"){
|
var syncResponse = getSyncResponse(payload);
|
||||||
return syncResponse(payload, [currentAccountAddress])
|
if (syncResponse){
|
||||||
} else if (payload.method == "eth_coinbase"){
|
return syncResponse;
|
||||||
return syncResponse(payload, currentAccountAddress)
|
|
||||||
} else if (payload.method == "net_version"){
|
|
||||||
return syncResponse(payload, networkId)
|
|
||||||
} else {
|
} else {
|
||||||
alert('You tried to send "' + payload.method + '" synchronously. Synchronous requests are not supported, sorry.');
|
alert('You tried to send "' + payload.method + '" synchronously. Synchronous requests are not supported, sorry.');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StatusHttpProvider.prototype.prepareRequest = function () {
|
StatusHttpProvider.prototype.sendAsync = function (payload, callback) {
|
||||||
var request = new XMLHttpRequest();
|
var syncResponse = getSyncResponse(payload);
|
||||||
|
if (syncResponse){
|
||||||
request.open('POST', this.host, false);
|
callback(null, syncResponse);
|
||||||
request.setRequestHeader('Content-Type', 'application/json');
|
}
|
||||||
return request;
|
else {
|
||||||
};
|
|
||||||
|
|
||||||
function sendAsync(payload, callback) {
|
|
||||||
var messageId = callbackId++;
|
var messageId = callbackId++;
|
||||||
callbacks[messageId] = callback;
|
callbacks[messageId] = callback;
|
||||||
if (typeof StatusBridge == "undefined") {
|
if (typeof StatusBridge == "undefined") {
|
||||||
@ -66,9 +72,16 @@ function sendAsync(payload, callback) {
|
|||||||
} else {
|
} else {
|
||||||
StatusBridge.sendRequest(this.host, JSON.stringify(messageId), JSON.stringify(payload));
|
StatusBridge.sendRequest(this.host, JSON.stringify(messageId), JSON.stringify(payload));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StatusHttpProvider.prototype.sendAsync = sendAsync;
|
StatusHttpProvider.prototype.prepareRequest = function () {
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
|
request.open('POST', this.host, false);
|
||||||
|
request.setRequestHeader('Content-Type', 'application/json');
|
||||||
|
return request;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously tries to make Http request
|
* Synchronously tries to make Http request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user