From b94d166fa95d48dcb85abc14cece7eefabbef830 Mon Sep 17 00:00:00 2001 From: Leonidas Conde <80922146+LeonardoDizConde@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:06:35 -0300 Subject: [PATCH] CU-86dt9hnuv --- common/config/rush/pnpm-lock.yaml | 3 -- examples/wc-wallet-react/package.json | 1 + examples/wc-wallet-react/src/index.tsx | 9 ++-- .../package.json | 1 - .../wallet-connect-sdk-wallet-core/src/sdk.ts | 44 +++++++++---------- .../src/types.ts | 4 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b07fa32..36c99fc 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -169,9 +169,6 @@ importers: '@walletconnect/jsonrpc-utils': specifier: ^1.0.8 version: 1.0.8 - '@walletconnect/sign-client': - specifier: 2.13.0 - version: 2.13.0 '@walletconnect/types': specifier: 2.13.0 version: 2.13.0 diff --git a/examples/wc-wallet-react/package.json b/examples/wc-wallet-react/package.json index f9e818d..6bdd292 100644 --- a/examples/wc-wallet-react/package.json +++ b/examples/wc-wallet-react/package.json @@ -30,6 +30,7 @@ "@types/react-dom": "^16.9.8", "@types/react-qr-reader": "^2.1.6", "@types/styled-components": "^5.1.2", + "@walletconnect/core": "^2.13.2", "axios": "^0.21.1", "crypto-browserify": "^3.12.0", "events": "^3.3.0", diff --git a/examples/wc-wallet-react/src/index.tsx b/examples/wc-wallet-react/src/index.tsx index 291f05e..bcab844 100644 --- a/examples/wc-wallet-react/src/index.tsx +++ b/examples/wc-wallet-react/src/index.tsx @@ -15,13 +15,16 @@ import { WalletConnectWalletProvider, } from '@cityofzion/wallet-connect-sdk-wallet-react' import { AccountContextProvider } from './context/AccountContext' +import Core from '@walletconnect/core' const wcOptions: TInitOptions = { clientOptions: { - projectId: DEFAULT_PROJECT_ID, + core: new Core({ + projectId: DEFAULT_PROJECT_ID, + logger: DEFAULT_LOGGER, + relayUrl: DEFAULT_RELAY_PROVIDER, + }), metadata: DEFAULT_APP_METADATA, - logger: DEFAULT_LOGGER, - relayUrl: DEFAULT_RELAY_PROVIDER, }, blockchains: { neo3: { diff --git a/packages/wallet-connect-sdk-wallet-core/package.json b/packages/wallet-connect-sdk-wallet-core/package.json index 2748594..395431f 100644 --- a/packages/wallet-connect-sdk-wallet-core/package.json +++ b/packages/wallet-connect-sdk-wallet-core/package.json @@ -36,7 +36,6 @@ "@cityofzion/wallet-connect-sdk-core": "workspace:*", "@walletconnect/core": "^2.13.1", "@walletconnect/jsonrpc-utils": "^1.0.8", - "@walletconnect/sign-client": "2.13.0", "@walletconnect/types": "2.13.0", "@walletconnect/web3wallet": "^1.12.1", "moment": "^2.29.4", diff --git a/packages/wallet-connect-sdk-wallet-core/src/sdk.ts b/packages/wallet-connect-sdk-wallet-core/src/sdk.ts index 0480a31..96dd72f 100644 --- a/packages/wallet-connect-sdk-wallet-core/src/sdk.ts +++ b/packages/wallet-connect-sdk-wallet-core/src/sdk.ts @@ -22,8 +22,6 @@ import { import { COMPATIBILITY_VERSION } from '@cityofzion/wallet-connect-sdk-core' import { sleep } from './utils' import Web3Wallet from '@walletconnect/web3wallet' -import { Core } from '@walletconnect/core' -import { Web3WalletTypes } from '@walletconnect/web3wallet/dist/types/types' const SESSION_EXTENDED_STORAGE_KEY = 'wc-sdk:extended-session' const INIT_TIMEOUT = 7000 @@ -33,7 +31,7 @@ export class WcWalletSDK { /** * The WalletConnect Library */ - public web3wallet: Web3Wallet | undefined + public wallet: Web3Wallet | undefined /** * The EventEmitter to listen for some property changes */ @@ -102,7 +100,7 @@ export class WcWalletSDK { approvalUnix, wccv, })) - this.web3wallet?.core.storage.setItem(SESSION_EXTENDED_STORAGE_KEY, extendedSession) + this.wallet?.core.storage.setItem(SESSION_EXTENDED_STORAGE_KEY, extendedSession) } /** @@ -119,10 +117,10 @@ export class WcWalletSDK { /** * It will get WalletConnect Library or throw error */ - private get signClient() { - if (!this.web3wallet || this.status !== EStatus.STARTED) throw new Error('Client not started') + private get web3wallet() { + if (!this.wallet || this.status !== EStatus.STARTED) throw new Error('Client not started') - return this.web3wallet + return this.wallet } /** @@ -144,14 +142,14 @@ export class WcWalletSDK { throw new Error('Initialization timeout has been reached') }) - const core = new Core({ - projectId: this.clientOptions.projectId, - }) - const web3wallet = await Web3Wallet.init({ - ...(this.clientOptions as unknown as Web3WalletTypes.Options), - core, + ...this.clientOptions, + signConfig: { + ...this.clientOptions.signConfig, + disableRequestQueue: true, + }, }) + clearTimeout(timeout) web3wallet.events.removeAllListeners('session_proposal') @@ -195,7 +193,7 @@ export class WcWalletSDK { : [] this.status = EStatus.STARTED - this.web3wallet = web3wallet + this.wallet = web3wallet } catch (error) { this.status = EStatus.ERROR throw error @@ -217,11 +215,9 @@ export class WcWalletSDK { if (wccv > COMPATIBILITY_VERSION) throw new Error('Incompatible WCCV. Update your wallet to use new features.') } - await this.web3wallet?.pair({ + await this.wallet?.pair({ uri, }) - - //wccv && this.wccvs.set(topic, wccv) } /** @@ -231,7 +227,7 @@ export class WcWalletSDK { * @return {Promise.void} */ public async disconnect(session: TSession, reason?: TRejectReason): Promise { - await this.signClient.disconnectSession({ + await this.web3wallet.disconnectSession({ topic: session.topic, reason: reason ?? { code: ResponseErrorCode.DISCONNECT, @@ -266,7 +262,7 @@ export class WcWalletSDK { }, } - const session = await this.signClient.approveSession({ + const session = await this.web3wallet.approveSession({ id: proposal.id, namespaces, }) @@ -299,7 +295,7 @@ export class WcWalletSDK { */ public async rejectProposal(proposal: TSessionProposal, reason?: TRejectReason): Promise { try { - await this.signClient.rejectSession({ + await this.web3wallet.rejectSession({ id: proposal.id, reason: reason ?? { code: ResponseErrorCode.REJECT, @@ -365,7 +361,7 @@ export class WcWalletSDK { const filteredRequests = this.requests.filter(({ id }) => id !== request.id) this.requests = filteredRequests - await this.signClient.respondSessionRequest({ + await this.web3wallet.respondSessionRequest({ topic: request.topic, response, }) @@ -380,7 +376,7 @@ export class WcWalletSDK { */ public async rejectRequest(request: TSessionRequest, reason?: TRejectReason): Promise { try { - await this.signClient.respondSessionRequest({ + await this.web3wallet.respondSessionRequest({ topic: request.topic, response: formatJsonRpcError( request.id, @@ -405,7 +401,7 @@ export class WcWalletSDK { await Promise.all( dappRequests.map(async (dappRequest) => { try { - await this.signClient.respondSessionRequest({ + await this.web3wallet.respondSessionRequest({ topic: dappRequest.topic, response: formatJsonRpcError(dappRequest.id, { code: ResponseErrorCode.REJECT, @@ -418,6 +414,8 @@ export class WcWalletSDK { }), ) + //this.web3wallet. + this.requests = this.requests.filter((dappRequest: TSessionRequest) => dappRequest.topic !== session.topic) return wipedRequests diff --git a/packages/wallet-connect-sdk-wallet-core/src/types.ts b/packages/wallet-connect-sdk-wallet-core/src/types.ts index d6c5590..b1745c4 100644 --- a/packages/wallet-connect-sdk-wallet-core/src/types.ts +++ b/packages/wallet-connect-sdk-wallet-core/src/types.ts @@ -1,6 +1,7 @@ import WalletConnectTypes from '@walletconnect/types' import { JsonRpcResult, ErrorResponse, JsonRpcError } from '@walletconnect/jsonrpc-utils' import { AbstractWalletConnectEIP155Adapter, AbstractWalletConnectNeonAdapter } from './adapters' +import { Web3WalletTypes } from '@walletconnect/web3wallet' export type TSession = WalletConnectTypes.SessionTypes.Struct & { approvalUnix: number @@ -30,8 +31,9 @@ export type TBaseBlockchainOptions = { autoAcceptMethods?: string[] adapter?: T } +export type TInitClientOptions = Web3WalletTypes.Options export type TInitOptions = { - clientOptions: WalletConnectTypes.SignClientTypes.Options + clientOptions: TInitClientOptions blockchains: { neo3?: TBaseBlockchainOptions eip155?: TBaseBlockchainOptions