Respect onlyIfTrusted parameter on Solana connect request

This commit is contained in:
Ivan Grachev 2022-07-14 23:11:02 +03:00
parent a72bf1b1a9
commit cff5fe2e8c
2 changed files with 13 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -59,8 +59,12 @@ class TokenarySolana extends EventEmitter {
this.pendingPayloads = [];
}
connect() {
return this.request({method: "connect"});
connect(params) {
var payload = {method: "connect"};
if (typeof params !== "undefined") {
payload.params = params;
}
return this.request(payload);
}
disconnect() {
@ -143,7 +147,12 @@ class TokenarySolana extends EventEmitter {
switch (payload.method) {
case "connect":
if (!this.publicKey) {
return this.postMessage("connect", payload.id, {});
if ("params" in payload && "onlyIfTrusted" in payload.params && payload.params.onlyIfTrusted) {
this.sendError(payload.id, "Click a button to connect");
return;
} else {
return this.postMessage("connect", payload.id, {});
}
} else {
this.isConnected = true;
this.emitConnect(this.publicKey);