Skip to content

Commit

Permalink
fix: naming errors
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Nov 15, 2023
1 parent 982038e commit 0e00b86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public static TypedEventHandler<T, TR> GetInstance(ICore engine)
{
var context = engine.Context;

if (Instances.ContainsKey(context)) return Instances[context];
if (Instances.TryGetValue(context, out var instance))
return instance;

var _instance = new TypedEventHandler<T, TR>(engine);
var newInstance = new TypedEventHandler<T, TR>(engine);

Instances.Add(context, _instance);
Instances.Add(context, newInstance);

return _instance;
return newInstance;
}

/// <summary>
Expand Down
43 changes: 23 additions & 20 deletions WalletConnectSharp.Sign/Models/SessionRequestEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace WalletConnectSharp.Sign.Models
/// <typeparam name="TR">The type of the response for the session request</typeparam>
public class SessionRequestEventHandler<T, TR> : TypedEventHandler<T, TR>
{
private IEnginePrivate _enginePrivate;
private readonly IEnginePrivate _enginePrivate;

/// <summary>
/// Get a singleton instance of this class for the given <see cref="IEngine"/> context. The context
/// string of the given <see cref="IEngine"/> will be used to determine the singleton instance to
Expand All @@ -24,37 +24,38 @@ public class SessionRequestEventHandler<T, TR> : TypedEventHandler<T, TR>
/// <param name="engine">The engine this singleton instance is for, and where the context string will
/// be read from</param>
/// <returns>The singleton instance to use for request/response event handlers</returns>
public static new TypedEventHandler<T, TR> GetInstance(ICore engine, IEnginePrivate _enginePrivate)
public static TypedEventHandler<T, TR> GetInstance(ICore engine, IEnginePrivate enginePrivate)
{
var context = engine.Context;

if (_instances.ContainsKey(context)) return _instances[context];

var _instance = new SessionRequestEventHandler<T, TR>(engine, _enginePrivate);

_instances.Add(context, _instance);
if (Instances.TryGetValue(context, out var instance))
return instance;

var newInstance = new SessionRequestEventHandler<T, TR>(engine, enginePrivate);

return _instance;
Instances.Add(context, newInstance);

return newInstance;
}

protected SessionRequestEventHandler(ICore engine, IEnginePrivate enginePrivate) : base(engine)
{
this._enginePrivate = enginePrivate;
}

protected override TypedEventHandler<T, TR> BuildNew(ICore _ref, Func<RequestEventArgs<T, TR>, bool> requestPredicate, Func<ResponseEventArgs<TR>, bool> responsePredicate)
protected override TypedEventHandler<T, TR> BuildNew(ICore @ref,
Func<RequestEventArgs<T, TR>, bool> requestPredicate, Func<ResponseEventArgs<TR>, bool> responsePredicate)
{
return new SessionRequestEventHandler<T, TR>(_ref, _enginePrivate)
return new SessionRequestEventHandler<T, TR>(@ref, _enginePrivate)
{
requestPredicate = requestPredicate,
responsePredicate = responsePredicate
RequestPredicate = requestPredicate, ResponsePredicate = responsePredicate
};
}

protected override void Setup()
{
var wrappedRef = TypedEventHandler<SessionRequest<T>, TR>.GetInstance(_ref);
var wrappedRef = TypedEventHandler<SessionRequest<T>, TR>.GetInstance(Ref);

wrappedRef.OnRequest += WrappedRefOnOnRequest;
wrappedRef.OnResponse += WrappedRefOnOnResponse;
}
Expand All @@ -70,17 +71,18 @@ private async Task WrappedRefOnOnRequest(RequestEventArgs<SessionRequest<T>, TR>
var method = RpcMethodAttribute.MethodForType<T>();

var sessionRequest = e.Request.Params.Request;

if (sessionRequest.Method != method) return;

//Set inner request id to match outer request id
sessionRequest.Id = e.Request.Id;

//Add to pending requests
//We can't do a simple cast, so we need to copy all the data
await _enginePrivate.SetPendingSessionRequest(new PendingRequestStruct()
{
Id = e.Request.Id, Parameters = new SessionRequest<object>()
Id = e.Request.Id,
Parameters = new SessionRequest<object>()
{
ChainId = e.Request.Params.ChainId,
Request = new JsonRpcRequest<object>()
Expand All @@ -89,7 +91,8 @@ await _enginePrivate.SetPendingSessionRequest(new PendingRequestStruct()
Method = sessionRequest.Method,
Params = sessionRequest.Params
}
}, Topic = e.Topic
},
Topic = e.Topic
});

await base.RequestCallback(e.Topic, sessionRequest);
Expand Down

0 comments on commit 0e00b86

Please sign in to comment.