diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 3a602494a4..92f5571c64 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -35,8 +35,7 @@ import { } from '@web3modal/scaffold-utils/ethers' import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider' import type { Eip1193Provider } from 'ethers' -import { W3mFrameRpcConstants, W3mFrameProvider } from '@web3modal/wallet' -import type { W3mFrameTypes } from '@web3modal/wallet' +import { W3mFrameProvider, W3mFrameHelpers } from '@web3modal/wallet' import type { CombinedProvider } from '@web3modal/scaffold-utils/ethers' // -- Types --------------------------------------------------------------------- @@ -748,10 +747,8 @@ export class Web3Modal extends Web3ModalScaffold { private watchEmail() { if (this.emailProvider) { this.emailProvider.onRpcRequest(request => { - const req = request as W3mFrameTypes.AppEvent & { payload?: unknown } - const payload = req.payload as W3mFrameTypes.RPCRequest // We only open the modal if it's not a safe (auto-approve) - if (!W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(payload.method)) { + if (!W3mFrameHelpers.checkIfRequestIsAllowed(request)) { super.open({ view: 'ApproveTransaction' }) } }) diff --git a/packages/wagmi/src/client.ts b/packages/wagmi/src/client.ts index 9d07e8a4b9..68c2b521f7 100644 --- a/packages/wagmi/src/client.ts +++ b/packages/wagmi/src/client.ts @@ -34,6 +34,7 @@ import { getEmailCaipNetworks, getWalletConnectCaipNetworks } from './utils/helpers.js' +import { W3mFrameHelpers } from '@web3modal/wallet' import type { W3mFrameProvider } from '@web3modal/wallet' import { ConstantsUtil as CoreConstants } from '@web3modal/core' import type { defaultWagmiConfig as coreConfig } from './utils/defaultWagmiCoreConfig.js' @@ -390,8 +391,10 @@ export class Web3Modal extends Web3ModalScaffold { const provider = (await connector.getProvider()) as W3mFrameProvider const isLoginEmailUsed = provider.getLoginEmailUsed() super.setLoading(isLoginEmailUsed) - provider.onRpcRequest(() => { - super.open({ view: 'ApproveTransaction' }) + provider.onRpcRequest(request => { + if (!W3mFrameHelpers.checkIfRequestIsAllowed(request)) { + super.open({ view: 'ApproveTransaction' }) + } }) provider.onRpcResponse(() => { super.close() diff --git a/packages/wallet/src/W3mFrameHelpers.ts b/packages/wallet/src/W3mFrameHelpers.ts index 37f74a5be6..df217d79c2 100644 --- a/packages/wallet/src/W3mFrameHelpers.ts +++ b/packages/wallet/src/W3mFrameHelpers.ts @@ -1,5 +1,6 @@ import { W3mFrameStorage } from './W3mFrameStorage.js' -import { W3mFrameConstants } from './W3mFrameConstants.js' +import { W3mFrameConstants, W3mFrameRpcConstants } from './W3mFrameConstants.js' +import type { W3mFrameTypes } from './W3mFrameTypes.js' const RESTRICTED_TIMEZONES = [ 'ASIA/SHANGHAI', @@ -53,5 +54,11 @@ export const W3mFrameHelpers = { return 0 }, + checkIfRequestIsAllowed(request: unknown) { + const method = (request as { payload: W3mFrameTypes.RPCRequest })?.payload?.method + + return W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(method) + }, + isClient: typeof window !== 'undefined' } diff --git a/scripts/coverage.js b/scripts/coverage.js index f595d977ca..e3d1c96fd2 100644 --- a/scripts/coverage.js +++ b/scripts/coverage.js @@ -12,7 +12,7 @@ const __dirname = path.dirname(__filename) /** * Reads the coverage-summary.{XXX}.json file and returns the parsed JSON object * @param {*} pathToReport - * @returns {Object | null} parsed JSON object + * @returns {Object} parsed JSON object */ function readPreviousCoverageSummary(pathToReport) { if (!pathToReport) {