Skip to content

Commit

Permalink
US-1981 Edited wc to check for optional namespaces too. Also added ma…
Browse files Browse the repository at this point in the history
…innet chainId. (#808)
  • Loading branch information
Freshenext authored Nov 20, 2023
1 parent 202660b commit b6b862e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/screens/walletConnect/walletConnect2.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ export const buildRskAllowedNamespaces = ({

export const rskWalletConnectNamespace = {
eip155: {
chains: ['eip155:31'], // @TODO implement eip155:30 here -> make this dynamic according to the current chainId in the app
chains: ['eip155:31', 'eip155:30'],
methods: [
'eth_sendTransaction',
'personal_sign',
'eth_signTransaction',
'eth_sign',
'eth_signTypedData',
'eth_signTypedData_v4',
],
events: ['chainChanged', 'accountsChanged'],
},
Expand All @@ -150,23 +151,29 @@ export const getProposalErrorComparedWithRskNamespace = (
proposal: Web3WalletTypes.SessionProposal,
): WalletConnect2SdkErrorString | void => {
const {
params: { requiredNamespaces },
params: { requiredNamespaces, optionalNamespaces },
} = proposal
// Check if namespace has eip155
if (!requiredNamespaces.eip155) {
if (!requiredNamespaces.eip155 && !optionalNamespaces.eip155) {
return WalletConnect2SdkErrorEnum.UNSUPPORTED_NAMESPACE_KEY
}
// Check if chains includes EIP155:31 OR EIP155:30
if (
!requiredNamespaces.eip155.chains?.every(chain =>
!requiredNamespaces.eip155?.chains?.every(chain =>
rskWalletConnectNamespace.eip155.chains.includes(chain),
) &&
!optionalNamespaces.eip155?.chains?.every(chain =>
rskWalletConnectNamespace.eip155.chains.includes(chain),
)
) {
return WalletConnect2SdkErrorEnum.UNSUPPORTED_CHAINS
}
// Check if the methods that RSK allows are present
if (
!requiredNamespaces.eip155.methods?.every(
!requiredNamespaces.eip155?.methods?.every(
method => rskWalletConnectNamespace.eip155.methods.indexOf(method) > -1,
) &&
!optionalNamespaces.eip155?.methods?.every(
method => rskWalletConnectNamespace.eip155.methods.indexOf(method) > -1,
)
) {
Expand All @@ -176,6 +183,9 @@ export const getProposalErrorComparedWithRskNamespace = (
if (
!requiredNamespaces.eip155?.events.every(
event => rskWalletConnectNamespace.eip155.events.indexOf(event) > -1,
) &&
!optionalNamespaces.eip155?.events.every(
event => rskWalletConnectNamespace.eip155.events.indexOf(event) > -1,
)
) {
return WalletConnect2SdkErrorEnum.UNSUPPORTED_EVENTS
Expand Down

0 comments on commit b6b862e

Please sign in to comment.