Handle eth_accounts exception
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
a0b4bc3dec
commit
49accf0cb7
|
@ -84,6 +84,7 @@
|
|||
} else if (data.isAllowed) {
|
||||
if (data.permission == 'web3') {
|
||||
window.statusAppcurrentAccountAddress = data.data[0];
|
||||
window.ethereum.emit("accountsChanged", data.data);
|
||||
}
|
||||
callback.resolve(data.data);
|
||||
} else {
|
||||
|
@ -152,6 +153,30 @@
|
|||
EthereumProvider.prototype.status = new StatusAPI();
|
||||
EthereumProvider.prototype.isConnected = function () { return true; };
|
||||
|
||||
EthereumProvider.prototype._events = {};
|
||||
|
||||
EthereumProvider.prototype.on = function(name, listener) {
|
||||
if (!this._events[name]) {
|
||||
this._events[name] = [];
|
||||
}
|
||||
this._events[name].push(listener);
|
||||
}
|
||||
|
||||
EthereumProvider.prototype.removeListener = function (name, listenerToRemove) {
|
||||
if (!this._events[name]) {
|
||||
return
|
||||
}
|
||||
|
||||
const filterListeners = (listener) => listener !== listenerToRemove;
|
||||
this._events[name] = this._events[name].filter(filterListeners);
|
||||
}
|
||||
|
||||
EthereumProvider.prototype.emit = function (name, data) {
|
||||
if (!this._events[name]) {
|
||||
return
|
||||
}
|
||||
this._events[name].forEach(cb => cb(data));
|
||||
}
|
||||
EthereumProvider.prototype.enable = function () {
|
||||
return sendAPIrequest('web3');
|
||||
};
|
||||
|
@ -160,11 +185,6 @@
|
|||
return sendAPIrequest('qr-code', {regex: regex});
|
||||
};
|
||||
|
||||
EthereumProvider.prototype.on = function (type, handler)
|
||||
{
|
||||
console.log("Not supported by Status")
|
||||
}
|
||||
|
||||
EthereumProvider.prototype.request = function (requestArguments)
|
||||
{
|
||||
if (!requestArguments) {
|
||||
|
|
|
@ -403,18 +403,35 @@
|
|||
:error %1
|
||||
:result %2}])]}))))
|
||||
|
||||
(fx/defn handle-no-permissions [cofx {:keys [method id]} message-id]
|
||||
(if (= method "eth_accounts")
|
||||
;; eth_accounts returns empty array for compatibility with meta-mask
|
||||
(send-to-bridge cofx
|
||||
{:type constants/web3-send-async-callback
|
||||
:messageId message-id
|
||||
:result {:jsonrpc "2.0"
|
||||
:id (int id)
|
||||
:result []}})
|
||||
(send-to-bridge cofx
|
||||
{:type constants/web3-send-async-callback
|
||||
:messageId message-id
|
||||
:error {:code 4100}})))
|
||||
|
||||
(def permissioned-method
|
||||
#{"eth_accounts" "eth_coinbase" "eth_sendTransaction" "eth_sign"
|
||||
"keycard_signTypedData"
|
||||
"eth_signTypedData" "personal_sign" "personal_ecRecover"})
|
||||
|
||||
(defn has-permissions? [{:dapps/keys [permissions]} dapp-name method]
|
||||
(boolean
|
||||
(and (permissioned-method method)
|
||||
(not (some #{constants/dapp-permission-web3} (get-in permissions [dapp-name :permissions]))))))
|
||||
|
||||
(fx/defn web3-send-async-read-only
|
||||
[{:keys [db] :as cofx} dapp-name {:keys [method] :as payload} message-id]
|
||||
(let [{:dapps/keys [permissions]} db]
|
||||
(if (and (#{"eth_accounts" "eth_coinbase" "eth_sendTransaction" "eth_sign"
|
||||
"keycard_signTypedData"
|
||||
"eth_signTypedData" "personal_sign" "personal_ecRecover"} method)
|
||||
(not (some #{constants/dapp-permission-web3} (get-in permissions [dapp-name :permissions]))))
|
||||
(send-to-bridge cofx
|
||||
{:type constants/web3-send-async-callback
|
||||
:messageId message-id
|
||||
:error {:code 4100}})
|
||||
(web3-send-async cofx payload message-id))))
|
||||
(if (has-permissions? db dapp-name method)
|
||||
(handle-no-permissions cofx payload message-id)
|
||||
(web3-send-async cofx payload message-id)))
|
||||
|
||||
(fx/defn handle-scanned-qr-code
|
||||
[cofx data {:keys [dapp-name permission message-id]}]
|
||||
|
|
Loading…
Reference in New Issue