diff --git a/packages/beacon-transport-walletconnect/src/WalletConnectTransport.ts b/packages/beacon-transport-walletconnect/src/WalletConnectTransport.ts index 02604abe8..9b4f82215 100644 --- a/packages/beacon-transport-walletconnect/src/WalletConnectTransport.ts +++ b/packages/beacon-transport-walletconnect/src/WalletConnectTransport.ts @@ -36,7 +36,7 @@ export class WalletConnectTransport< ) { super( name, - WalletConnectCommunicationClient.getInstance(wcOptions), + WalletConnectCommunicationClient.getInstance(wcOptions, isLeader), new PeerManager(storage, storageKey) ) } @@ -93,7 +93,7 @@ export class WalletConnectTransport< } public async getPeers(): Promise { - const client = WalletConnectCommunicationClient.getInstance(this.wcOptions) + const client = WalletConnectCommunicationClient.getInstance(this.wcOptions, this.isLeader) const session = client.currentSession() if (!session) { return [] diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index c21cd45f2..7e0856206 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -111,16 +111,22 @@ export class WalletConnectCommunicationClient extends CommunicationClient { */ private messageIds: string[] = [] - constructor(private wcOptions: { network: NetworkType; opts: SignClientTypes.Options }) { + constructor( + private wcOptions: { network: NetworkType; opts: SignClientTypes.Options }, + private isLeader: Function + ) { super() } - static getInstance(wcOptions: { - network: NetworkType - opts: SignClientTypes.Options - }): WalletConnectCommunicationClient { + static getInstance( + wcOptions: { + network: NetworkType + opts: SignClientTypes.Options + }, + isLeader: Function + ): WalletConnectCommunicationClient { if (!this.instance) { - this.instance = new WalletConnectCommunicationClient(wcOptions) + this.instance = new WalletConnectCommunicationClient(wcOptions, isLeader) } return WalletConnectCommunicationClient.instance } @@ -675,6 +681,12 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.notifyListeners(_pairingTopic, errorResponse) } }) + .then(async () => { + const isLeader = await this.isLeader() + if (!isLeader) { + await this.closeSignClient() + } + }) logger.warn('return uri and topic')