Skip to content

Commit

Permalink
feat: update EIP 5792 implementation to match updated standard (#3656)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu authored Jun 10, 2024
1 parent cca4801 commit 224d913
Show file tree
Hide file tree
Showing 12 changed files with 462 additions and 112 deletions.
4 changes: 3 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ const customJestConfig = {
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = async () => ({
...(await createJestConfig(customJestConfig)()),
transformIgnorePatterns: ['node_modules/(?!(uint8arrays|multiformats|@web3-onboard/common)/)'],
transformIgnorePatterns: [
'node_modules/(?!(uint8arrays|multiformats|@web3-onboard/common|@walletconnect/(.*)/uint8arrays)/)',
],
})
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"node": ">=16"
},
"resolutions": {
"@walletconnect/core": "^2.11.2",
"@walletconnect/ethereum-provider": "^2.11.2",
"@safe-global/safe-core-sdk-types/**/ethers": "^6.11.1",
"@safe-global/protocol-kit/**/ethers": "^6.11.1",
"@safe-global/api-kit/**/ethers": "^6.11.1",
Expand All @@ -65,8 +63,8 @@
"@sentry/react": "^7.91.0",
"@spindl-xyz/attribution-lite": "^1.4.0",
"@truffle/hdwallet-provider": "^2.1.4",
"@walletconnect/utils": "^2.11.3",
"@walletconnect/web3wallet": "^1.10.3",
"@walletconnect/utils": "^2.13.1",
"@walletconnect/web3wallet": "^1.12.1",
"@web3-onboard/coinbase": "^2.2.6",
"@web3-onboard/core": "^2.21.4",
"@web3-onboard/injected-wallets": "^2.10.14",
Expand Down Expand Up @@ -131,7 +129,7 @@
"@types/react-gtm-module": "^2.0.3",
"@types/semver": "^7.3.10",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@walletconnect/types": "^2.11.3",
"@walletconnect/types": "^2.13.1",
"cross-env": "^7.0.3",
"cypress": "^12.15.0",
"cypress-file-upload": "^5.0.8",
Expand Down
12 changes: 11 additions & 1 deletion src/features/walletconnect/components/WcSessionManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ const WcSessionManager = ({ sessions, uri }: WcSessionManagerProps) => {
setIsLoading(WCLoadingState.APPROVE)

try {
await walletConnect.approveSession(sessionProposal, chainId, safeAddress)
await walletConnect.approveSession(sessionProposal, chainId, safeAddress, {
capabilities: JSON.stringify({
[safeAddress]: {
[`0x${Number(chainId).toString(16)}`]: {
atomicBatch: {
supported: true,
},
},
},
}),
})

// Auto approve future sessions for non-malicious dApps
if (
Expand Down
7 changes: 4 additions & 3 deletions src/features/walletconnect/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const SAFE_COMPATIBLE_METHODS = [
'eth_getLogs',
'eth_gasPrice',
'wallet_switchEthereumChain',
'wallet_sendFunctionCallBundle',
'wallet_getBundleStatus',
'wallet_showBundleStatus',
'wallet_sendCalls',
'wallet_getCallsStatus',
'wallet_showCallsStatus',
'wallet_getCapabilities',
'safe_setSettings',
]

Expand Down
10 changes: 8 additions & 2 deletions src/features/walletconnect/services/WalletConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Web3Wallet } from '@walletconnect/web3wallet'
import { buildApprovedNamespaces, getSdkError } from '@walletconnect/utils'
import type Web3WalletType from '@walletconnect/web3wallet'
import type { Web3WalletTypes } from '@walletconnect/web3wallet'
import type { SessionTypes } from '@walletconnect/types'
import type { ProposalTypes, SessionTypes } from '@walletconnect/types'
import { type JsonRpcResponse } from '@walletconnect/jsonrpc-utils'
import uniq from 'lodash/uniq'

Expand Down Expand Up @@ -107,7 +107,12 @@ class WalletConnectWallet {
})
}

public async approveSession(proposal: Web3WalletTypes.SessionProposal, currentChainId: string, safeAddress: string) {
public async approveSession(
proposal: Web3WalletTypes.SessionProposal,
currentChainId: string,
safeAddress: string,
sessionProperties?: ProposalTypes.SessionProperties,
) {
assertWeb3Wallet(this.web3Wallet)

const namespaces = this.getNamespaces(proposal, currentChainId, safeAddress)
Expand All @@ -116,6 +121,7 @@ class WalletConnectWallet {
const session = await this.web3Wallet.approveSession({
id: proposal.id,
namespaces,
sessionProperties,
})

await this.chainChanged(session.topic, currentChainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ describe('WalletConnectWallet', () => {
publicKey: '123',
metadata: {} as SignClientTypes.Metadata,
},
pairingTopic: '0x3456',
requiredNamespaces: {} as ProposalTypes.RequiredNamespaces,
optionalNamespaces: {} as ProposalTypes.OptionalNamespaces,
expiryTimestamp: 2,
Expand Down Expand Up @@ -283,6 +284,7 @@ describe('WalletConnectWallet', () => {
id: 1,
expiry: 1,
relays: [],
pairingTopic: '0x3456',
proposer: {
publicKey: '123',
metadata: {} as SignClientTypes.Metadata,
Expand Down
5 changes: 5 additions & 0 deletions src/services/contracts/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getFallbackHandlerDeployment,
getProxyFactoryDeployment,
getSignMessageLibDeployment,
getCreateCallDeployment,
} from '@safe-global/safe-deployments'
import type { SingletonDeployment, DeploymentFilter } from '@safe-global/safe-deployments'
import type { ChainInfo, SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
Expand Down Expand Up @@ -79,3 +80,7 @@ export const getProxyFactoryContractDeployment = (chainId: string, safeVersion:
export const getSignMessageLibContractDeployment = (chainId: string, safeVersion: SafeInfo['version']) => {
return _tryDeploymentVersions(getSignMessageLibDeployment, chainId, safeVersion)
}

export const getCreateCallContractDeployment = (chainId: string, safeVersion: SafeInfo['version']) => {
return _tryDeploymentVersions(getCreateCallDeployment, chainId, safeVersion)
}
Loading

0 comments on commit 224d913

Please sign in to comment.