Skip to content

Commit

Permalink
chore: update rpc not allowed message
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaisailovic committed Feb 23, 2024
1 parent 429d65c commit ea25974
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------------------------
Expand Down Expand Up @@ -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)
}
})
Expand Down
7 changes: 5 additions & 2 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
}
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/src/W3mFrameConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
8 changes: 6 additions & 2 deletions packages/wallet/src/W3mFrameHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ 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) ||
W3mFrameRpcConstants.SAFE_RPC_METHODS.includes(method)
)
},

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)
},
Expand Down

0 comments on commit ea25974

Please sign in to comment.