Skip to content

Commit

Permalink
[wallet] Disconnect active origin on dapp-kit disconnect call (#19916)
Browse files Browse the repository at this point in the history
## Description 

Currently, when disconnecting from any dapp, the internal connection of
the wallet for the given origin is not reset, making the experience
unpredictable and confusing (main UX confusion we've been facing on
every single bug bash).

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
manolisliolios authored Oct 21, 2024
1 parent 11ddc9e commit 06574f7
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: '', // origin is auto-discovered for wallet's disconnect.
});
};

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

0 comments on commit 06574f7

Please sign in to comment.