-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: improve connected disconnected state (#1323)
* remove/disconnect dapp * handle session deletion * display different conenction states * remove and disconnect * reset router on confirm --------- Co-authored-by: Nicole O'Brien <[email protected]>
- Loading branch information
1 parent
f9ad9f1
commit 1407d42
Showing
13 changed files
with
165 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 4 additions & 7 deletions
11
packages/shared/src/lib/auxiliary/wallet-connect/actions/disconnectDapp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/shared/src/lib/auxiliary/wallet-connect/actions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './disconnectDapp' | ||
export * from './initializeWalletConnect' | ||
export * from './pairWithNewDapp' | ||
export * from './removeDapp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/shared/src/lib/auxiliary/wallet-connect/actions/removeDapp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { logAndNotifyError } from '@core/error/actions' | ||
import { getWalletClient, setConnectedDapps } from '../stores' | ||
import { getSdkError } from '@walletconnect/utils' | ||
import { IConnectedDapp } from '../interface' | ||
|
||
export async function removeDapp(dapp: IConnectedDapp): Promise<void> { | ||
const client = getWalletClient() | ||
if (!client) { | ||
return | ||
} | ||
|
||
try { | ||
if (dapp.session) { | ||
await client.disconnectSession({ | ||
topic: dapp.session.topic, | ||
reason: getSdkError('USER_DISCONNECTED'), | ||
}) | ||
} | ||
await client.core.pairing.disconnect({ topic: dapp.topic }) | ||
setConnectedDapps() | ||
} catch (err) { | ||
logAndNotifyError({ | ||
type: 'walletConnect', | ||
message: String(err), | ||
logToConsole: true, | ||
saveToErrorLog: true, | ||
showNotification: false, | ||
}) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/shared/src/lib/auxiliary/wallet-connect/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './eth_sendTransaction.handler' | ||
export * from './eth_signTransaction.handler' | ||
export * from './eth_signTypedData.handler' | ||
export * from './onSessionDelete.handler' | ||
export * from './onSessionProposal.handler' | ||
export * from './onSessionRequest.handler' | ||
export * from './sign_message.handler' |
15 changes: 15 additions & 0 deletions
15
packages/shared/src/lib/auxiliary/wallet-connect/handlers/onSessionDelete.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { showNotification } from '@auxiliary/notification' | ||
import { Web3WalletTypes } from '@walletconnect/web3wallet' | ||
import { getConnectedDapps, setConnectedDapps } from '../stores' | ||
|
||
export function onSessionDelete(event: Web3WalletTypes.SessionDelete): void { | ||
const { topic } = event | ||
|
||
const dapp = getConnectedDapps().find((_dapp) => _dapp.session?.topic === topic) | ||
|
||
showNotification({ | ||
variant: 'warning', | ||
text: 'Disconnected from ' + dapp?.metadata?.name, | ||
}) | ||
setConnectedDapps() | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/shared/src/lib/auxiliary/wallet-connect/interface/connected-dapp.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { IDappMetadata } from './dapp-metadata.interface' | ||
import { IPairing } from './pairing.interface' | ||
import { ISession } from './session.interface' | ||
|
||
export interface IConnectedDapp extends Omit<IPairing, 'peerMetadata'> { | ||
metadata?: IDappMetadata | ||
session?: ISession | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/shared/src/lib/auxiliary/wallet-connect/interface/session.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { ProposalTypes, RelayerTypes, SignClientTypes } from '@walletconnect/types' | ||
|
||
export interface ISession { | ||
topic: string | ||
pairingTopic: string | ||
relay: RelayerTypes.ProtocolOptions | ||
expiry: number | ||
acknowledged: boolean | ||
controller: string | ||
namespaces: Record< | ||
string, | ||
{ | ||
chains?: string[] | ||
accounts: string[] | ||
methods: string[] | ||
events: string[] | ||
} | ||
> | ||
requiredNamespaces: ProposalTypes.RequiredNamespaces | ||
optionalNamespaces: ProposalTypes.OptionalNamespaces | ||
sessionProperties?: ProposalTypes.SessionProperties | ||
self: { | ||
publicKey: string | ||
metadata: SignClientTypes.Metadata | ||
} | ||
peer: { | ||
publicKey: string | ||
metadata: SignClientTypes.Metadata | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters