feat: disconnect accounts in browser
This commit is contained in:
parent
5dcd401cd5
commit
3258ac8f9c
|
@ -249,6 +249,9 @@ QtObject:
|
||||||
proc hasPermission*(self: Web3ProviderView, hostname: string, permission: string): bool {.slot.} =
|
proc hasPermission*(self: Web3ProviderView, hostname: string, permission: string): bool {.slot.} =
|
||||||
result = self.status.permissions.hasPermission(hostname, permission.toPermission())
|
result = self.status.permissions.hasPermission(hostname, permission.toPermission())
|
||||||
|
|
||||||
|
proc disconnect*(self: Web3ProviderView) {.slot.} =
|
||||||
|
self.status.permissions.revoke("web3".toPermission())
|
||||||
|
|
||||||
proc postMessage*(self: Web3ProviderView, message: string): string {.slot.} =
|
proc postMessage*(self: Web3ProviderView, message: string): string {.slot.} =
|
||||||
case message.requestType():
|
case message.requestType():
|
||||||
of RequestTypes.Web3SendAsyncReadOnly: message.toWeb3SendAsyncReadOnly().process(self.status)
|
of RequestTypes.Web3SendAsyncReadOnly: message.toWeb3SendAsyncReadOnly().process(self.status)
|
||||||
|
|
|
@ -59,6 +59,21 @@ proc getPermissions*(self: PermissionsModel, dapp: string): HashSet[Permission]
|
||||||
for permission in dappPermission["permissions"].getElems():
|
for permission in dappPermission["permissions"].getElems():
|
||||||
result.incl(permission.getStr().toPermission())
|
result.incl(permission.getStr().toPermission())
|
||||||
|
|
||||||
|
proc revoke*(self: PermissionsModel, permission: Permission) =
|
||||||
|
let response = callPrivateRPC("permissions_getDappPermissions")
|
||||||
|
var permissions = initHashSet[Permission]()
|
||||||
|
|
||||||
|
for dapps in response.parseJson["result"].getElems():
|
||||||
|
for currPerm in dapps["permissions"].getElems():
|
||||||
|
let p = currPerm.getStr().toPermission()
|
||||||
|
if p != permission:
|
||||||
|
permissions.incl(p)
|
||||||
|
|
||||||
|
discard callPrivateRPC("permissions_addDappPermissions", %*[{
|
||||||
|
"dapp": dapps["dapp"].getStr(),
|
||||||
|
"permissions": permissions.toSeq()
|
||||||
|
}])
|
||||||
|
|
||||||
proc hasPermission*(self: PermissionsModel, dapp: string, permission: Permission): bool =
|
proc hasPermission*(self: PermissionsModel, dapp: string, permission: Permission): bool =
|
||||||
result = self.getPermissions(dapp).contains(permission)
|
result = self.getPermissions(dapp).contains(permission)
|
||||||
|
|
||||||
|
|
|
@ -266,6 +266,8 @@ Rectangle {
|
||||||
|
|
||||||
|
|
||||||
signDialog.open();
|
signDialog.open();
|
||||||
|
} else if (request.type === Constants.web3DisconnectAccount) {
|
||||||
|
web3Response(data);
|
||||||
} else {
|
} else {
|
||||||
web3Response(_web3Provider.postMessage(data));
|
web3Response(_web3Provider.postMessage(data));
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,8 +82,11 @@ Popup {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: console.log('TODO Disconnect')
|
onClicked: {
|
||||||
|
_web3Provider.disconnect();
|
||||||
|
provider.postMessage(`{"type":"web3-disconnect-account"}`);
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -805,6 +805,12 @@ You may add additional accurate notices of copyright ownership.
|
||||||
const id = data.messageId;
|
const id = data.messageId;
|
||||||
const callback = callbacks[id];
|
const callback = callbacks[id];
|
||||||
|
|
||||||
|
if(data.type === "web3-disconnect-account") {
|
||||||
|
window.statusAppcurrentAccountAddress = "";
|
||||||
|
window.ethereum.emit("accountsChanged", []);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
if (data.type === "api-response") {
|
if (data.type === "api-response") {
|
||||||
if (data.permission == "qr-code") {
|
if (data.permission == "qr-code") {
|
||||||
|
@ -846,6 +852,9 @@ You may add additional accurate notices of copyright ownership.
|
||||||
new QWebChannel(qt.webChannelTransport, function(channel) {
|
new QWebChannel(qt.webChannelTransport, function(channel) {
|
||||||
backend = channel.objects.backend;
|
backend = channel.objects.backend;
|
||||||
backend.web3Response.connect(onMessage);
|
backend.web3Response.connect(onMessage);
|
||||||
|
|
||||||
|
window.ethereum.on("connected", () => {}); // TODO: Dummy event. Will need to be replaced once connecte/disconnected provider logic is implemented in status-go
|
||||||
|
window.ethereum.emit("connected", {"chainId": backend.networkId.toString()});
|
||||||
});
|
});
|
||||||
|
|
||||||
const bridgeSend = data => {
|
const bridgeSend = data => {
|
||||||
|
@ -918,6 +927,35 @@ You may add additional accurate notices of copyright ownership.
|
||||||
}
|
}
|
||||||
UserRejectedRequest.prototype = Object.create(Error.prototype);
|
UserRejectedRequest.prototype = Object.create(Error.prototype);
|
||||||
|
|
||||||
|
function UnsupportedMethod() {
|
||||||
|
this.name = "Unsupported Method";
|
||||||
|
this.id = 4200;
|
||||||
|
this.code = 4200;
|
||||||
|
this.message = "The Provider does not support the requested method.";
|
||||||
|
}
|
||||||
|
UnsupportedMethod.prototype = Object.create(Error.prototype);
|
||||||
|
|
||||||
|
function Disconnected() {
|
||||||
|
this.name = "Disconnected";
|
||||||
|
this.id = 4900;
|
||||||
|
this.code = 4900;
|
||||||
|
this.message = "The Provider is disconnected from all chains.";
|
||||||
|
}
|
||||||
|
Disconnected.prototype = Object.create(Error.prototype);
|
||||||
|
|
||||||
|
//
|
||||||
|
function ChainDisconnected() {
|
||||||
|
this.name = "Chain Disconnected";
|
||||||
|
this.id = 4901;
|
||||||
|
this.code = 4901;
|
||||||
|
this.message = "The Provider is not connected to the requested chain.";
|
||||||
|
}
|
||||||
|
ChainDisconnected.prototype = Object.create(ChainDisconnected.prototype);
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: chainChanged is not implemented because we do not support switching networks without disconnecting from Status
|
||||||
|
// Provider.on('chainChanged', listener: (chainId: string) => void): Provider;
|
||||||
|
|
||||||
function web3Response (payload, result){
|
function web3Response (payload, result){
|
||||||
return {
|
return {
|
||||||
id: payload.id,
|
id: payload.id,
|
||||||
|
@ -951,6 +989,25 @@ You may add additional accurate notices of copyright ownership.
|
||||||
EthereumProvider.prototype.isStatus = true;
|
EthereumProvider.prototype.isStatus = true;
|
||||||
EthereumProvider.prototype.status = new StatusAPI();
|
EthereumProvider.prototype.status = new StatusAPI();
|
||||||
EthereumProvider.prototype.isConnected = function () { return true; };
|
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]) throw new Error(`event "${name}" does not exist`);
|
||||||
|
const filterListeners = (listener) => listener !== listenerToRemove;
|
||||||
|
this._events[name] = this._events[name].filter(filterListeners);
|
||||||
|
}
|
||||||
|
|
||||||
|
EthereumProvider.prototype.emit = function (name, data) {
|
||||||
|
if (!this._events[name]) throw new Error(`event "${name}" does not exist`);
|
||||||
|
this._events[name].forEach(cb => cb(data));
|
||||||
|
}
|
||||||
|
|
||||||
EthereumProvider.prototype.enable = function () {
|
EthereumProvider.prototype.enable = function () {
|
||||||
return sendAPIrequest('web3');
|
return sendAPIrequest('web3');
|
||||||
|
@ -1053,4 +1110,7 @@ You may add additional accurate notices of copyright ownership.
|
||||||
}
|
}
|
||||||
|
|
||||||
window.ethereum = new EthereumProvider();
|
window.ethereum = new EthereumProvider();
|
||||||
|
|
||||||
|
// TODO: connected/disconnected must be emitted if we lose connection to infura. Verify if status-go emits events for that
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -87,6 +87,7 @@ QtObject {
|
||||||
|
|
||||||
readonly property string api_request: "api-request"
|
readonly property string api_request: "api-request"
|
||||||
readonly property string web3SendAsyncReadOnly: "web3-send-async-read-only"
|
readonly property string web3SendAsyncReadOnly: "web3-send-async-read-only"
|
||||||
|
readonly property string web3DisconnectAccount: "web3-disconnect-account"
|
||||||
|
|
||||||
readonly property string permission_web3: "web3"
|
readonly property string permission_web3: "web3"
|
||||||
readonly property string permission_contactCode: "contact-code"
|
readonly property string permission_contactCode: "contact-code"
|
||||||
|
|
Loading…
Reference in New Issue