Skip to content

Commit

Permalink
MOB-2102 - Handle unsupported WC requests for ULW (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-Pecheneg authored Jul 8, 2024
1 parent 9bf5bc7 commit f41f7bf
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,9 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
throw WalletConnectRequestError.failedBuildParams
}
let messageString = paramsAny[1]
let address = try parseAddress(from: paramsAny[0])

let (_, udWallet) = try await getClientAfterConfirmationIfNeeded(address: address,
let walletAddress = try parseAddress(from: paramsAny[0])
try throwUnsupportedMethodIfMPCWallet(walletAddress: walletAddress)
let (_, udWallet) = try await getClientAfterConfirmationIfNeeded(address: walletAddress,
request: request,
messageString: messageString)

Expand All @@ -674,7 +674,7 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
let sigTyped = try await udWallet.getEthSignature(messageString: messageString)
sig = WCAnyCodable(sigTyped)
} catch {
Debugger.printFailure("Failed to sign message: \(messageString) by wallet:\(address)", critical: false)
Debugger.printFailure("Failed to sign message: \(messageString) by wallet:\(walletAddress)", critical: false)
throw WalletConnectRequestError.failedToSignMessage
}

Expand All @@ -686,6 +686,7 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
guard let walletAddress = tx.from?.hex(eip55: true).normalized else {
throw WalletConnectRequestError.failedToFindWalletToSign
}
try throwUnsupportedMethodIfMPCWallet(walletAddress: walletAddress)
let udWallet = try detectWallet(by: walletAddress).udWallet
let chainIdInt = try request.getChainId()
let completedTx = try await completeTx(transaction: tx, chainId: chainIdInt)
Expand Down Expand Up @@ -735,6 +736,7 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
guard let walletAddress = tx.from?.hex(eip55: true) else {
throw WalletConnectRequestError.failedToFindWalletToSign
}
try throwUnsupportedMethodIfMPCWallet(walletAddress: walletAddress)
let udWallet = try detectWallet(by: walletAddress).udWallet
let chainIdInt = try request.getChainId()
let completedTx = try await completeTx(transaction: tx, chainId: chainIdInt)
Expand All @@ -747,10 +749,8 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
case .externalLinked:
let response = try await udWallet.sendTxViaWalletConnect(request: request, chainId: chainIdInt)
return response

case .mpc: print("sign with mpc")
return .error(.internalError) // TODO: mpc

case .mpc:
throw WalletConnectRequestError.methodUnsupported
default: // locally verified wallet
let hash = try await JRPC_Client.instance.sendTx(transaction: completedTx,
udWallet: udWallet,
Expand Down Expand Up @@ -874,6 +874,13 @@ extension WalletConnectServiceV2: WalletConnectV2RequestHandlingServiceProtocol
guard let addressString = transaction.from?.hex() else { throw WalletConnectRequestError.failedFetchNonce }
return try await JRPC_Client.instance.fetchNonce(address: addressString, chainId: chainId)
}

private func throwUnsupportedMethodIfMPCWallet(walletAddress: String) throws {
let udWallet = try detectWallet(by: walletAddress).udWallet
if case .mpc = udWallet.type {
throw WalletConnectRequestError.methodUnsupported
}
}
}

// MARK: - Private methods
Expand Down

0 comments on commit f41f7bf

Please sign in to comment.