From c50a242c00919dd0b21d9a42a58b4337b07a9745 Mon Sep 17 00:00:00 2001 From: Dmitry Bespalov Date: Thu, 14 Mar 2024 18:03:10 +0100 Subject: [PATCH] GH-3262 guard for the same chainid in incoming request --- .../WalletConnectManager.swift | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Multisig/UI/WalletConnectV2/WalletConnectManager.swift b/Multisig/UI/WalletConnectV2/WalletConnectManager.swift index 34d503473..7a4947fd2 100644 --- a/Multisig/UI/WalletConnectV2/WalletConnectManager.swift +++ b/Multisig/UI/WalletConnectV2/WalletConnectManager.swift @@ -149,13 +149,13 @@ class WalletConnectManager { } } - func reject(request: Request) { + func reject(request: Request, error: JSONRPCError = JSONRPCError(code: 0, message: "")) { Task { do { try await Web3Wallet.instance.respond( topic: request.topic, requestId: request.id, - response: .error(.init(code: 0, message: "")) + response: .error(error) ) } catch { print("DAPP: Respond Error: \(error.localizedDescription)") @@ -165,7 +165,9 @@ class WalletConnectManager { } } } - + + let NAMESPACE_ID = "eip155" + // Approves required chains and a chain where selected safe resides. // // For reference: @@ -178,8 +180,6 @@ class WalletConnectManager { // - connection approved if safe's chain is in the proposal // - if no such chain found in proposal, connection will fail func approveSession(proposal: Session.Proposal) { - let NAMESPACE_ID = "eip155" - guard let address = approver.safe?.address, let chainId = approver.safe?.chain, @@ -363,6 +363,19 @@ class WalletConnectManager { } if request.method == "eth_sendTransaction" { + guard + let idString = safe.chain?.id, + let safeChainId = Blockchain(namespace: NAMESPACE_ID, reference: safe.chain!.id!), + request.chainId == safeChainId + else { + DispatchQueue.main.async { + App.shared.snackbar.show(message: "Please select dApp chain matching with the safe's chain") + } + reject(request: request, + error: JSONRPCError(code: -33012, message: "Please select a different chain")) + return + } + // make transformation of incoming request into internal data types // and fetch information about Safe Accout from the request DispatchQueue.global(qos: .background).async { [weak self] in