From 696e8a8c7d56695a11f79c7f732e0eeb7be9a514 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Tue, 20 Feb 2024 14:01:22 +0100 Subject: [PATCH] minor change --- lib/apis/sign_api/sign_engine.dart | 89 +++++++++++++++++------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/lib/apis/sign_api/sign_engine.dart b/lib/apis/sign_api/sign_engine.dart index 56f80f50..417e2784 100644 --- a/lib/apis/sign_api/sign_engine.dart +++ b/lib/apis/sign_api/sign_engine.dart @@ -1273,49 +1273,64 @@ class SignEngine implements ISignEngine { sessionRequest, ); - final methodKey = _getRegisterKey( + final String methodKey = _getRegisterKey( request.chainId, request.request.method, ); + // print('method key: $methodKey'); + if (_methodHandlers.containsKey(methodKey)) { + final handler = _methodHandlers[methodKey]; + if (handler != null) { + try { + final result = await handler( + topic, + request.request.params, + ); + await core.pairing.sendResult( + payload.id, + topic, + MethodConstants.WC_SESSION_REQUEST, + result, + ); + } on WalletConnectError catch (e) { + await core.pairing.sendError( + payload.id, + topic, + payload.method, + JsonRpcError.fromJson( + e.toJson(), + ), + ); + } on WalletConnectErrorSilent catch (_) { + // Do nothing on silent error + } catch (err) { + await core.pairing.sendError( + payload.id, + topic, + payload.method, + JsonRpcError.invalidParams( + err.toString(), + ), + ); + } - // We send onSessionRequest event on every session request, - // the developer can decide wether to use it or just register method handlers - onSessionRequest.broadcast( - SessionRequestEvent.fromSessionRequest( - sessionRequest, - ), - ); - - final methodHandler = _methodHandlers[methodKey]; - // If a method handler has been set using registerRequestHandler we use it to process the request - if (methodHandler != null) { - try { - final result = await methodHandler(topic, request.request.params); - await core.pairing.sendResult( - payload.id, - topic, - MethodConstants.WC_SESSION_REQUEST, - result, - ); - } on WalletConnectError catch (e) { - await core.pairing.sendError( - payload.id, - topic, - payload.method, - JsonRpcError.fromJson(e.toJson()), - ); - } on WalletConnectErrorSilent catch (_) { - // Do nothing on silent error - } catch (err) { - await core.pairing.sendError( - payload.id, - topic, - payload.method, - JsonRpcError.invalidParams(err.toString()), - ); + await _deletePendingRequest(payload.id); } - await _deletePendingRequest(payload.id); + onSessionRequest.broadcast( + SessionRequestEvent.fromSessionRequest( + sessionRequest, + ), + ); + } else { + await core.pairing.sendError( + payload.id, + topic, + payload.method, + JsonRpcError.methodNotFound( + 'No handler found for chainId:method -> $methodKey', + ), + ); } } on WalletConnectError catch (err) { await core.pairing.sendError(