From 20854e60f7d1977db9f34c965a3535b6d331126c Mon Sep 17 00:00:00 2001 From: Luka Isailovic Date: Fri, 23 Feb 2024 19:19:22 +0100 Subject: [PATCH] chore: update rpc not allowed message (#1969) --- packages/ethers/src/client.ts | 7 +++++-- packages/wagmi/src/client.ts | 7 +++++-- packages/wallet/src/W3mFrameConstants.ts | 4 +++- packages/wallet/src/W3mFrameHelpers.ts | 8 ++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index 779ad0aa32..2539dd2372 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -35,7 +35,7 @@ import { } from '@web3modal/scaffold-utils/ethers' import type { EthereumProviderOptions } from '@walletconnect/ethereum-provider' import type { Eip1193Provider } from 'ethers' -import { W3mFrameProvider, W3mFrameHelpers } from '@web3modal/wallet' +import { W3mFrameProvider, W3mFrameHelpers, W3mFrameRpcConstants } from '@web3modal/wallet' import type { CombinedProvider } from '@web3modal/scaffold-utils/ethers' // -- Types --------------------------------------------------------------------- @@ -763,8 +763,11 @@ export class Web3Modal extends Web3ModalScaffold { } else { this.emailProvider?.rejectRpcRequest() super.open() + const method = W3mFrameHelpers.getRequestMethod(request) + // eslint-disable-next-line no-console + console.error(W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_MESSAGE, { method }) setTimeout(() => { - this.showErrorMessage('This RPC method is not supported') + this.showErrorMessage(W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_UI_MESSAGE) }, 300) } }) diff --git a/packages/wagmi/src/client.ts b/packages/wagmi/src/client.ts index 2348e99b4b..2ed3cdc767 100644 --- a/packages/wagmi/src/client.ts +++ b/packages/wagmi/src/client.ts @@ -34,7 +34,7 @@ import { getEmailCaipNetworks, getWalletConnectCaipNetworks } from './utils/helpers.js' -import { W3mFrameHelpers } from '@web3modal/wallet' +import { W3mFrameHelpers, W3mFrameRpcConstants } 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' @@ -400,8 +400,11 @@ export class Web3Modal extends Web3ModalScaffold { } } else { super.open() + const method = W3mFrameHelpers.getRequestMethod(request) + // eslint-disable-next-line no-console + console.error(W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_MESSAGE, { method }) setTimeout(() => { - this.showErrorMessage('This RPC method is not supported') + this.showErrorMessage(W3mFrameRpcConstants.RPC_METHOD_NOT_ALLOWED_UI_MESSAGE) }, 300) provider.rejectRpcRequest() } diff --git a/packages/wallet/src/W3mFrameConstants.ts b/packages/wallet/src/W3mFrameConstants.ts index 60985febb2..c713e67f02 100644 --- a/packages/wallet/src/W3mFrameConstants.ts +++ b/packages/wallet/src/W3mFrameConstants.ts @@ -96,5 +96,7 @@ export const W3mFrameRpcConstants = { 'eth_uninstallFilter' ], NOT_SAFE_RPC_METHODS: ['personal_sign', 'eth_signTypedData_v4', 'eth_sendTransaction'], - GET_CHAIN_ID: 'eth_chainId' + GET_CHAIN_ID: 'eth_chainId', + RPC_METHOD_NOT_ALLOWED_MESSAGE: 'Requested RPC call is not allowed', + RPC_METHOD_NOT_ALLOWED_UI_MESSAGE: 'Action not allowed' } diff --git a/packages/wallet/src/W3mFrameHelpers.ts b/packages/wallet/src/W3mFrameHelpers.ts index a203d8733b..845113d99c 100644 --- a/packages/wallet/src/W3mFrameHelpers.ts +++ b/packages/wallet/src/W3mFrameHelpers.ts @@ -55,7 +55,7 @@ export const W3mFrameHelpers = { }, checkIfRequestExists(request: unknown) { - const method = (request as { payload: W3mFrameTypes.RPCRequest })?.payload?.method + const method = this.getRequestMethod(request) return ( W3mFrameRpcConstants.NOT_SAFE_RPC_METHODS.includes(method) || @@ -63,8 +63,12 @@ export const W3mFrameHelpers = { ) }, + getRequestMethod(request: unknown) { + return (request as { payload: W3mFrameTypes.RPCRequest })?.payload?.method + }, + checkIfRequestIsAllowed(request: unknown) { - const method = (request as { payload: W3mFrameTypes.RPCRequest })?.payload?.method + const method = this.getRequestMethod(request) return W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(method) },