diff --git a/lerna.json b/lerna.json index a10292583..3f8ca3613 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { - "version": "4.2.0", + "version": "4.2.1", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/package-lock.json b/package-lock.json index 2570b7385..2fa6f9468 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25390,38 +25390,38 @@ }, "packages/beacon-blockchain-substrate": { "name": "@airgap/beacon-blockchain-substrate", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } }, "packages/beacon-blockchain-tezos": { "name": "@airgap/beacon-blockchain-tezos", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } }, "packages/beacon-blockchain-tezos-sapling": { "name": "@airgap/beacon-blockchain-tezos-sapling", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } }, "packages/beacon-core": { "name": "@airgap/beacon-core", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@stablelib/ed25519": "^1.0.3", "@stablelib/nacl": "^1.0.4", "@stablelib/utf8": "^1.0.1", @@ -25431,67 +25431,67 @@ }, "packages/beacon-dapp": { "name": "@airgap/beacon-dapp", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-transport-walletconnect": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-transport-walletconnect": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } }, "packages/beacon-sdk": { "name": "@airgap/beacon-sdk", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-blockchain-substrate": "4.2.0", - "@airgap/beacon-blockchain-tezos": "4.2.0", - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-dapp": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0", - "@airgap/beacon-utils": "4.2.0", - "@airgap/beacon-wallet": "4.2.0" + "@airgap/beacon-blockchain-substrate": "4.2.1", + "@airgap/beacon-blockchain-tezos": "4.2.1", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-dapp": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1", + "@airgap/beacon-utils": "4.2.1", + "@airgap/beacon-wallet": "4.2.1" } }, "packages/beacon-transport-matrix": { "name": "@airgap/beacon-transport-matrix", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "axios": "^1.6.2" } }, "packages/beacon-transport-postmessage": { "name": "@airgap/beacon-transport-postmessage", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1" } }, "packages/beacon-transport-walletconnect": { "name": "@airgap/beacon-transport-walletconnect", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@walletconnect/sign-client": "2.11.2" } }, "packages/beacon-types": { "name": "@airgap/beacon-types", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { "@types/chrome": "0.0.246" @@ -25499,13 +25499,13 @@ }, "packages/beacon-ui": { "name": "@airgap/beacon-ui", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@walletconnect/utils": "2.11.2", "qrcode-svg": "^1.1.0", "solid-js": "^1.7.11" @@ -25528,7 +25528,7 @@ }, "packages/beacon-utils": { "name": "@airgap/beacon-utils", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { "@stablelib/ed25519": "^1.0.3", @@ -25540,12 +25540,12 @@ }, "packages/beacon-wallet": { "name": "@airgap/beacon-wallet", - "version": "4.2.0", + "version": "4.2.1", "license": "ISC", "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1" } } } diff --git a/packages/beacon-blockchain-substrate/package.json b/packages/beacon-blockchain-substrate/package.json index 125f47a74..9aec6d23d 100644 --- a/packages/beacon-blockchain-substrate/package.json +++ b/packages/beacon-blockchain-substrate/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-substrate", - "version": "4.2.0", + "version": "4.2.1", "description": "This package adds support for `substrate` based blockchains. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } } diff --git a/packages/beacon-blockchain-tezos-sapling/package.json b/packages/beacon-blockchain-tezos-sapling/package.json index fe623fdbd..4ae7c7f86 100644 --- a/packages/beacon-blockchain-tezos-sapling/package.json +++ b/packages/beacon-blockchain-tezos-sapling/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-tezos-sapling", - "version": "4.2.0", + "version": "4.2.1", "description": "This package adds support for `tezos-sapling`, the sapling integration on the Tezos blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } } diff --git a/packages/beacon-blockchain-tezos/package.json b/packages/beacon-blockchain-tezos/package.json index 7b4215183..bc94739da 100644 --- a/packages/beacon-blockchain-tezos/package.json +++ b/packages/beacon-blockchain-tezos/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-blockchain-tezos", - "version": "4.2.0", + "version": "4.2.1", "description": "This package adds support for the `tezos` blockchain. It can be used in combination with the `@airgap/beacon-dapp` or `@airgap/beacon-wallet` packages.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,7 +34,7 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } } diff --git a/packages/beacon-core/package.json b/packages/beacon-core/package.json index d7760df65..3559f088d 100644 --- a/packages/beacon-core/package.json +++ b/packages/beacon-core/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-core", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains internal methods that are used by both the dApp and wallet client.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@stablelib/ed25519": "^1.0.3", "@stablelib/nacl": "^1.0.4", "@stablelib/utf8": "^1.0.1", diff --git a/packages/beacon-core/src/constants.ts b/packages/beacon-core/src/constants.ts index 8d54253e8..2696e1e02 100644 --- a/packages/beacon-core/src/constants.ts +++ b/packages/beacon-core/src/constants.ts @@ -1,4 +1,4 @@ -export const SDK_VERSION: string = '4.2.0' +export const SDK_VERSION: string = '4.2.1' export const BEACON_VERSION: string = '3' export const NOTIFICATION_ORACLE_URL: string = diff --git a/packages/beacon-dapp/package.json b/packages/beacon-dapp/package.json index 5b117d388..81199f85e 100644 --- a/packages/beacon-dapp/package.json +++ b/packages/beacon-dapp/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-dapp", - "version": "4.2.0", + "version": "4.2.1", "description": "Use this package on your dApp to instanciate a DAppClient object and communicate to wallets.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,10 +35,10 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-transport-walletconnect": "4.2.0", - "@airgap/beacon-ui": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-transport-walletconnect": "4.2.1", + "@airgap/beacon-ui": "4.2.1" } } diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index d21bed1a8..ef3b5db25 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -69,7 +69,8 @@ import { SimulatedProofOfEventChallengeRequestInput, SimulatedProofOfEventChallengeRequest, SimulatedProofOfEventChallengeResponse, - RequestSimulatedProofOfEventChallengeInput + RequestSimulatedProofOfEventChallengeInput, + TransportStatus // PermissionRequestV3 // RequestEncryptPayloadInput, // EncryptPayloadResponseOutput, @@ -1341,7 +1342,6 @@ export class DAppClient extends Client { logger.log('requestPermissions', JSON.stringify(accountInfo)) await this.accountManager.addAccount(accountInfo) - await this.setActiveAccount(accountInfo) const output: PermissionResponseOutput = { ...message, @@ -2328,12 +2328,23 @@ export class DAppClient extends Client { } public async disconnect() { + if (!this._transport.isResolved()) { + throw new Error('No transport available.') + } + + const transport = await this.transport + + if (transport.connectionStatus === TransportStatus.NOT_CONNECTED) { + throw new Error('Not connected.') + } + await this.createStateSnapshot() this.sendMetrics('performance-metrics/save', await this.buildPayload('disconnect', 'start')) this.postMessageTransport = undefined this.p2pTransport = undefined this.walletConnectTransport = undefined - await Promise.all([this.clearActiveAccount(), (await this.transport).disconnect()]) + await this.clearActiveAccount() + await transport.disconnect() this.sendMetrics('performance-metrics/save', await this.buildPayload('disconnect', 'success')) } diff --git a/packages/beacon-sdk/package.json b/packages/beacon-sdk/package.json index 71cd71b51..b848d3daa 100644 --- a/packages/beacon-sdk/package.json +++ b/packages/beacon-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-sdk", - "version": "4.2.0", + "version": "4.2.1", "description": "The `beacon-sdk` simplifies and abstracts the communication between dApps and wallets over different transport layers.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,15 +35,15 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-blockchain-substrate": "4.2.0", - "@airgap/beacon-blockchain-tezos": "4.2.0", - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-dapp": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-ui": "4.2.0", - "@airgap/beacon-utils": "4.2.0", - "@airgap/beacon-wallet": "4.2.0" + "@airgap/beacon-blockchain-substrate": "4.2.1", + "@airgap/beacon-blockchain-tezos": "4.2.1", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-dapp": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-ui": "4.2.1", + "@airgap/beacon-utils": "4.2.1", + "@airgap/beacon-wallet": "4.2.1" } } diff --git a/packages/beacon-transport-matrix/package.json b/packages/beacon-transport-matrix/package.json index e42cf0e4b..9e95ba233 100644 --- a/packages/beacon-transport-matrix/package.json +++ b/packages/beacon-transport-matrix/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-matrix", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains methods to facilitate communication over the Beacon network, a decentralised P2P network that is based on the matrix protocol.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "axios": "^1.6.2" } } diff --git a/packages/beacon-transport-postmessage/package.json b/packages/beacon-transport-postmessage/package.json index 5b21144b0..cf3f1a7a2 100644 --- a/packages/beacon-transport-postmessage/package.json +++ b/packages/beacon-transport-postmessage/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-postmessage", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains methods to facilitate communication over the postmessage interface of the browser to talk to browser extensions.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,8 +34,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1" } } diff --git a/packages/beacon-transport-walletconnect/package.json b/packages/beacon-transport-walletconnect/package.json index df78bade7..93b53f6fa 100644 --- a/packages/beacon-transport-walletconnect/package.json +++ b/packages/beacon-transport-walletconnect/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-transport-walletconnect", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains methods to facilitate communication over the WalletConnect network.", "author": "Papers AG", "homepage": "https://walletbeacon.io", @@ -34,9 +34,9 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@walletconnect/sign-client": "2.11.2" } } diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 6567f18ab..4df3a18ca 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -6,9 +6,8 @@ import { Logger, WCStorage } from '@airgap/beacon-core' -import { SignClient } from '@walletconnect/sign-client' import Client from '@walletconnect/sign-client' -import { IPairing, ProposalTypes, SessionTypes, SignClientTypes } from '@walletconnect/types' +import { ProposalTypes, SessionTypes, SignClientTypes } from '@walletconnect/types' import { getSdkError } from '@walletconnect/utils' import { ActiveAccountUnspecified, @@ -114,7 +113,6 @@ export class WalletConnectCommunicationClient extends CommunicationClient { constructor(private wcOptions: { network: NetworkType; opts: SignClientTypes.Options }) { super() - this.getSignClient() this.storage.onMessageHandler = this.onStorageMessageHandler.bind(this) this.storage.onErrorHandler = this.onStorageErrorHandler.bind(this) } @@ -123,14 +121,14 @@ export class WalletConnectCommunicationClient extends CommunicationClient { network: NetworkType opts: SignClientTypes.Options }): WalletConnectCommunicationClient { - if (!WalletConnectCommunicationClient.instance) { - WalletConnectCommunicationClient.instance = new WalletConnectCommunicationClient(wcOptions) + if (!this.instance) { + this.instance = new WalletConnectCommunicationClient(wcOptions) } return WalletConnectCommunicationClient.instance } private getTopicFromSession(session: SessionTypes.Struct): string { - return session.pairingTopic?.length ? session.pairingTopic : session.topic + return session.topic } public async listenForEncryptedMessage( @@ -167,15 +165,17 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.clearEvents() this.signClient = undefined - const client = await this.getSignClient() - const sessions = client?.session.getAll() ?? [] + const client = (await this.getSignClient())! + const lastIndex = client.session.keys.length - 1 - try { - this.session = - sessions?.find((el) => el.topic === this.session?.topic) ?? sessions[0] ?? this.session - this.session && (this.activeAccount = this.getAccounts()[0]) - } catch (err: any) { - logger.error('refreshState', err.message) + if (lastIndex > -1) { + this.session = client.session.get(client.session.keys[lastIndex]) + + this.subscribeToSessionEvents(client) + this.updateStorageWallet(this.session) + this.setDefaultAccountAndNetwork() + } else { + this.clearState() } } @@ -221,9 +221,16 @@ export class WalletConnectCommunicationClient extends CommunicationClient { // implementation } - private ping(target: Client | IPairing, topic: string) { - target - .ping({ topic }) + private async ping() { + const client = await this.getSignClient() + + if (!client || !this.session) { + logger.error('No session available.') + return + } + + client + .ping({ topic: this.session.topic }) .then(() => { if (this.messageIds.length) { this.acknowledgeRequest(this.messageIds[0]) @@ -238,18 +245,14 @@ export class WalletConnectCommunicationClient extends CommunicationClient { }) } - private checkWalletReadiness(topic: string) { - const target = this.signClient?.pairing.getAll().some((el) => el.topic === topic) - ? this.signClient?.core.pairing - : this.signClient - - if (!target || this.pingInterval) { + private async checkWalletReadiness(_topic: string) { + if (this.pingInterval) { return } - this.ping(target, topic) + this.ping() this.pingInterval = setInterval(() => { - this.ping(target, topic) + this.ping() }, 30000) } @@ -561,11 +564,22 @@ export class WalletConnectCommunicationClient extends CommunicationClient { return } - const sessions = signClient.session.getAll() - if (sessions && sessions.length > 0) { - this.session = sessions[0] - this.setDefaultAccountAndNetwork() + // const sessions = signClient.session.getAll() + // if (sessions && sessions.length > 0) { + // this.session = sessions[0] + // this.setDefaultAccountAndNetwork() + // this.updateStorageWallet(this.session) + // return undefined + // } + + const lastIndex = signClient.session.keys.length - 1 + + if (lastIndex > -1) { + this.session = signClient.session.get(signClient.session.keys[lastIndex]) + this.updateStorageWallet(this.session) + this.setDefaultAccountAndNetwork() + return undefined } @@ -643,7 +657,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { if (session?.controller !== this.session?.controller) { logger.debug('Controller doesnt match, closing active session', [session.pairingTopic]) - this.activeAccount && this.closeActiveSession(this.activeAccount) + this.activeAccount && this.closeActiveSession(this.activeAccount, false) this.session = undefined // close the previous session } @@ -895,19 +909,6 @@ export class WalletConnectCommunicationClient extends CommunicationClient { ) } - // private async clearCache() { - // const signClient = await this.getSignClient() - // signClient?.proposal.map.clear() - // signClient?.pendingRequest.map.clear() - // signClient?.session.map.clear() - // ;(signClient?.core.expirer as Expirer).expirations.clear() - // signClient?.core.history.records.clear() - // signClient?.core.crypto.keychain.keychain.clear() - // signClient?.core.relayer.messages.messages.clear() - // signClient?.core.pairing.pairings.map.clear() - // signClient?.core.relayer.subscriber.subscriptions.clear() - // } - private async closePairings() { await this.closeSessions() const signClient = await this.getSignClient() @@ -916,11 +917,18 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const pairings = signClient.pairing.getAll() ?? [] pairings.length && (await Promise.allSettled( - pairings.map((pairing) => signClient.core.pairing.disconnect({ topic: pairing.topic })) + pairings.map((pairing) => + signClient.disconnect({ + topic: pairing.topic, + reason: { + code: 0, // TODO: Use constants + message: 'Force new connection' + } + }) + ) )) } - // await this.clearCache() await this.storage.resetState() this.storage.notify('RESET') } @@ -947,9 +955,11 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.clearState() } - private async openSession(pairingTopic?: string): Promise { + private async openSession(): Promise { + const signClient = (await this.getSignClient())! + const pairingTopic = signClient.core.pairing.getPairings()[0]?.topic + logger.debug('Starting open session with', [pairingTopic]) - const signClient = await this.getSignClient() if (!signClient) { throw new Error('Transport error.') @@ -977,12 +987,12 @@ export class WalletConnectCommunicationClient extends CommunicationClient { optionalNamespaces: { [TEZOS_PLACEHOLDER]: this.permissionScopeParamsToNamespaces(optionalPermissionScopeParams) }, - pairingTopic: pairingTopic ?? signClient.core.pairing.getPairings()[0]?.topic + pairingTopic } logger.debug('Checking wallet readiness', [pairingTopic]) - this.checkWalletReadiness(connectParams.pairingTopic) + this.checkWalletReadiness(pairingTopic) try { logger.debug('connect', [pairingTopic]) @@ -993,7 +1003,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { // if I have successfully opened a session and I already have one opened if (session?.controller !== this.session?.controller) { logger.debug('Controller doesnt match, closing active session', [pairingTopic]) - this.activeAccount && this.closeActiveSession(this.activeAccount) + this.activeAccount && this.closeActiveSession(this.activeAccount, false) this.session = undefined // close the previous session } @@ -1019,7 +1029,6 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const fun = this.eventHandlers.get(ClientEvents.WC_ACK_NOTIFICATION) fun && fun('error') } else { - const _pairingTopic = pairingTopic ?? signClient.core.pairing.getPairings()[0]?.topic logger.debug('New pairing topic?', [pairingTopic]) const errorResponse: ErrorResponseInput = { @@ -1028,7 +1037,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { errorType: BeaconErrorType.ABORTED_ERROR } as ErrorResponse - this.notifyListeners(_pairingTopic, errorResponse) + this.notifyListeners(pairingTopic, errorResponse) } } } @@ -1174,7 +1183,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { } } - async closeActiveSession(account: string) { + async closeActiveSession(account: string, notify: boolean = true) { try { this.validateNetworkAndAccount(this.getActiveNetwork(), account) } catch (error: any) { @@ -1184,7 +1193,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { const session = this.getSession() - if (this.messageIds.length) { + if (notify && this.messageIds.length) { const errorResponse: any = { type: BeaconMessageType.Disconnect, id: this.messageIds.pop(), @@ -1308,7 +1317,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { private async getSignClient(): Promise { if (this.signClient === undefined) { try { - this.signClient = await SignClient.init(this.wcOptions.opts) + this.signClient = await Client.init(this.wcOptions.opts) this.subscribeToSessionEvents(this.signClient) } catch (error: any) { logger.error(error.message) diff --git a/packages/beacon-types/package.json b/packages/beacon-types/package.json index d4c104969..051e3f8c9 100644 --- a/packages/beacon-types/package.json +++ b/packages/beacon-types/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-types", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains types that are used throughout the Beacon SDK.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", diff --git a/packages/beacon-ui/package.json b/packages/beacon-ui/package.json index fdb2ecd1c..a8fcffee7 100644 --- a/packages/beacon-ui/package.json +++ b/packages/beacon-ui/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-ui", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains the UI part (alerts and toasts) of the Beacon SDK.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -34,10 +34,10 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0", - "@airgap/beacon-types": "4.2.0", - "@airgap/beacon-utils": "4.2.0", + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1", + "@airgap/beacon-types": "4.2.1", + "@airgap/beacon-utils": "4.2.1", "@walletconnect/utils": "2.11.2", "qrcode-svg": "^1.1.0", "solid-js": "^1.7.11" diff --git a/packages/beacon-utils/package.json b/packages/beacon-utils/package.json index cb8e5a8b8..d9aabcfee 100644 --- a/packages/beacon-utils/package.json +++ b/packages/beacon-utils/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-utils", - "version": "4.2.0", + "version": "4.2.1", "description": "This package contains utility functions that are used throughout the beacon-sdk", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", diff --git a/packages/beacon-wallet/package.json b/packages/beacon-wallet/package.json index 267b310c4..9849b68e9 100644 --- a/packages/beacon-wallet/package.json +++ b/packages/beacon-wallet/package.json @@ -1,6 +1,6 @@ { "name": "@airgap/beacon-wallet", - "version": "4.2.0", + "version": "4.2.1", "description": "Use this package in your wallet to instanciate a WalletClient object and communicate to dApps.", "author": "Andreas Gassmann ", "homepage": "https://walletbeacon.io", @@ -35,8 +35,8 @@ "url": "https://github.com/airgap-it/beacon-sdk/issues" }, "dependencies": { - "@airgap/beacon-core": "4.2.0", - "@airgap/beacon-transport-matrix": "4.2.0", - "@airgap/beacon-transport-postmessage": "4.2.0" + "@airgap/beacon-core": "4.2.1", + "@airgap/beacon-transport-matrix": "4.2.1", + "@airgap/beacon-transport-postmessage": "4.2.1" } }