From c83e10a81d554b3725f9b869960708ccdc7e1472 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Fri, 18 Oct 2024 23:31:01 +0300 Subject: [PATCH 1/3] dapp-kit disconnect now removes permissions for origin --- .../connections/ContentScriptConnection.ts | 3 +++ .../src/dapp-interface/WalletStandardInterface.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/apps/wallet/src/background/connections/ContentScriptConnection.ts b/apps/wallet/src/background/connections/ContentScriptConnection.ts index 4eb296c0a428d..1b72a231cb2d1 100644 --- a/apps/wallet/src/background/connections/ContentScriptConnection.ts +++ b/apps/wallet/src/background/connections/ContentScriptConnection.ts @@ -25,6 +25,7 @@ import { import Permissions from '_src/background/Permissions'; import Transactions from '_src/background/Transactions'; import { FEATURES, growthbook } from '_src/shared/experimentation/features'; +import { isDisconnectApp } from '_src/shared/messaging/messages/payloads/permissions/DisconnectApp'; import { isQredoConnectPayload } from '_src/shared/messaging/messages/payloads/QredoConnect'; import { isSignMessageRequest, @@ -151,6 +152,8 @@ export class ContentScriptConnection extends Connection { throw new Error('This feature is not implemented yet.'); } await requestUserApproval(payload.args, this, msg); + } else if (isDisconnectApp(payload)) { + await Permissions.delete(this.origin); } else { throw new Error(`Unknown message, ${JSON.stringify(msg.payload)}`); } diff --git a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts index 389dcc6dccb75..16e874c29ed42 100644 --- a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts +++ b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts @@ -22,6 +22,7 @@ import type { } from '_payloads/transactions'; import { API_ENV } from '_src/shared/api-env'; import type { NetworkEnvType } from '_src/shared/api-env'; +import { type DisconnectApp } from '_src/shared/messaging/messages/payloads/permissions/DisconnectApp'; import { isQredoConnectPayload, type QredoConnectPayload, @@ -40,6 +41,8 @@ import { SUI_TESTNET_CHAIN, type StandardConnectFeature, type StandardConnectMethod, + type StandardDisconnectFeature, + type StandardDisconnectMethod, type StandardEventsFeature, type StandardEventsListeners, type StandardEventsOnMethod, @@ -119,6 +122,7 @@ export class SuiWallet implements Wallet { get features(): StandardConnectFeature & StandardEventsFeature & + StandardDisconnectFeature & SuiFeatures & QredoConnectFeature { return { @@ -130,6 +134,10 @@ export class SuiWallet implements Wallet { version: '1.0.0', on: this.#on, }, + 'standard:disconnect': { + version: '1.0.0', + disconnect: this.#disconnect, + }, 'sui:signTransactionBlock': { version: '1.0.0', signTransactionBlock: this.#signTransactionBlock, @@ -244,6 +252,13 @@ export class SuiWallet implements Wallet { return { accounts: this.accounts }; }; + #disconnect: StandardDisconnectMethod = async () => { + this.#send({ + type: 'disconnect-app', + origin: window.location.origin, + }); + }; + #signTransactionBlock: SuiSignTransactionBlockMethod = async ({ transactionBlock, account, From 61a90116379db70de0edafd88694514761a1b89b Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Fri, 18 Oct 2024 23:53:05 +0300 Subject: [PATCH 2/3] Also reset accounts --- apps/wallet/src/dapp-interface/WalletStandardInterface.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts index 16e874c29ed42..1d1dc2df46235 100644 --- a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts +++ b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts @@ -253,9 +253,11 @@ export class SuiWallet implements Wallet { }; #disconnect: StandardDisconnectMethod = async () => { + this.#accounts = []; + this.#events.emit('change', { accounts: this.accounts }); this.#send({ type: 'disconnect-app', - origin: window.location.origin, + origin: '', // origin is auto-discovered for wallet's disconnect. }); }; From 65459f861fa45763e195086a8710ee80f5f11ba3 Mon Sep 17 00:00:00 2001 From: Manolis Liolios Date: Mon, 21 Oct 2024 20:10:50 +0300 Subject: [PATCH 3/3] Avoid resetting accounts, it's already handled by the wallet status change listener --- apps/wallet/src/dapp-interface/WalletStandardInterface.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts index 1d1dc2df46235..7350a5b88f151 100644 --- a/apps/wallet/src/dapp-interface/WalletStandardInterface.ts +++ b/apps/wallet/src/dapp-interface/WalletStandardInterface.ts @@ -253,8 +253,6 @@ export class SuiWallet implements Wallet { }; #disconnect: StandardDisconnectMethod = async () => { - this.#accounts = []; - this.#events.emit('change', { accounts: this.accounts }); this.#send({ type: 'disconnect-app', origin: '', // origin is auto-discovered for wallet's disconnect.