Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wallet] Disconnect active origin on dapp-kit disconnect call #19916

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '', // origin is auto-discovered for wallet's disconnect.
});
};

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