Skip to content

Commit

Permalink
dapp-kit disconnect now removes permissions for origin
Browse files Browse the repository at this point in the history
  • Loading branch information
manolisliolios committed Oct 18, 2024
1 parent 0ad70e1 commit c83e10a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)}`);
}
Expand Down
15 changes: 15 additions & 0 deletions apps/wallet/src/dapp-interface/WalletStandardInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,6 +41,8 @@ import {
SUI_TESTNET_CHAIN,
type StandardConnectFeature,
type StandardConnectMethod,
type StandardDisconnectFeature,
type StandardDisconnectMethod,
type StandardEventsFeature,
type StandardEventsListeners,
type StandardEventsOnMethod,
Expand Down Expand Up @@ -119,6 +122,7 @@ export class SuiWallet implements Wallet {

get features(): StandardConnectFeature &
StandardEventsFeature &
StandardDisconnectFeature &
SuiFeatures &
QredoConnectFeature {
return {
Expand All @@ -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,
Expand Down Expand Up @@ -244,6 +252,13 @@ export class SuiWallet implements Wallet {
return { accounts: this.accounts };
};

#disconnect: StandardDisconnectMethod = async () => {
this.#send<DisconnectApp, void>({
type: 'disconnect-app',
origin: window.location.origin,
});
};

#signTransactionBlock: SuiSignTransactionBlockMethod = async ({
transactionBlock,
account,
Expand Down

0 comments on commit c83e10a

Please sign in to comment.