Skip to content

Commit

Permalink
CU-86dt9hnuv
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoDizConde committed Jun 11, 2024
1 parent 53dd8a8 commit b94d166
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
3 changes: 0 additions & 3 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/wc-wallet-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions examples/wc-wallet-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 0 additions & 1 deletion packages/wallet-connect-sdk-wallet-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 21 additions & 23 deletions packages/wallet-connect-sdk-wallet-core/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -102,7 +100,7 @@ export class WcWalletSDK {
approvalUnix,
wccv,
}))
this.web3wallet?.core.storage.setItem<TSessionExtendedStorage[]>(SESSION_EXTENDED_STORAGE_KEY, extendedSession)
this.wallet?.core.storage.setItem<TSessionExtendedStorage[]>(SESSION_EXTENDED_STORAGE_KEY, extendedSession)
}

/**
Expand All @@ -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
}

/**
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

/**
Expand All @@ -231,7 +227,7 @@ export class WcWalletSDK {
* @return {Promise.void}
*/
public async disconnect(session: TSession, reason?: TRejectReason): Promise<void> {
await this.signClient.disconnectSession({
await this.web3wallet.disconnectSession({
topic: session.topic,
reason: reason ?? {
code: ResponseErrorCode.DISCONNECT,
Expand Down Expand Up @@ -266,7 +262,7 @@ export class WcWalletSDK {
},
}

const session = await this.signClient.approveSession({
const session = await this.web3wallet.approveSession({
id: proposal.id,
namespaces,
})
Expand Down Expand Up @@ -299,7 +295,7 @@ export class WcWalletSDK {
*/
public async rejectProposal(proposal: TSessionProposal, reason?: TRejectReason): Promise<void> {
try {
await this.signClient.rejectSession({
await this.web3wallet.rejectSession({
id: proposal.id,
reason: reason ?? {
code: ResponseErrorCode.REJECT,
Expand Down Expand Up @@ -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,
})
Expand All @@ -380,7 +376,7 @@ export class WcWalletSDK {
*/
public async rejectRequest(request: TSessionRequest, reason?: TRejectReason): Promise<void> {
try {
await this.signClient.respondSessionRequest({
await this.web3wallet.respondSessionRequest({
topic: request.topic,
response: formatJsonRpcError(
request.id,
Expand All @@ -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,
Expand All @@ -418,6 +414,8 @@ export class WcWalletSDK {
}),
)

//this.web3wallet.

this.requests = this.requests.filter((dappRequest: TSessionRequest) => dappRequest.topic !== session.topic)

return wipedRequests
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet-connect-sdk-wallet-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,8 +31,9 @@ export type TBaseBlockchainOptions<T> = {
autoAcceptMethods?: string[]
adapter?: T
}
export type TInitClientOptions = Web3WalletTypes.Options
export type TInitOptions = {
clientOptions: WalletConnectTypes.SignClientTypes.Options
clientOptions: TInitClientOptions
blockchains: {
neo3?: TBaseBlockchainOptions<AbstractWalletConnectNeonAdapter>
eip155?: TBaseBlockchainOptions<AbstractWalletConnectEIP155Adapter>
Expand Down

0 comments on commit b94d166

Please sign in to comment.