diff --git a/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs index 487a631..67c3311 100644 --- a/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs +++ b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs @@ -170,6 +170,7 @@ private async Task Register(string url) try { _socket = new WebsocketClient(new Uri(_url)); + _socket.ReconnectTimeout = null; await _socket.Start().WithTimeout(OpenTimeout, "Unavailable WS RPC url at " + _url); OnOpen(_socket); diff --git a/WalletConnectSharp.Core/Controllers/Subscriber.cs b/WalletConnectSharp.Core/Controllers/Subscriber.cs index 7da5208..effb82f 100644 --- a/WalletConnectSharp.Core/Controllers/Subscriber.cs +++ b/WalletConnectSharp.Core/Controllers/Subscriber.cs @@ -163,11 +163,11 @@ public string StorageKey } } - private IRelayer _relayer; - private bool initialized; - private string clientId; - private ILogger logger; - private ActiveSubscription[] cached = Array.Empty(); + private readonly IRelayer _relayer; + private bool _initialized; + private string _clientId; + private readonly ILogger _logger; + private ActiveSubscription[] _cached = Array.Empty(); /// /// Create a new Subscriber module using a backing Relayer @@ -179,7 +179,7 @@ public Subscriber(IRelayer relayer) Events = new EventDelegator(this); - logger = WCLogger.WithContext(Context); + _logger = WCLogger.WithContext(Context); } /// @@ -188,12 +188,12 @@ public Subscriber(IRelayer relayer) /// public async Task Init() { - if (!initialized) + if (!_initialized) { await Restart(); RegisterEventListeners(); OnEnabled(); - this.clientId = await this._relayer.Core.Crypto.GetClientId(); + this._clientId = await this._relayer.Core.Crypto.GetClientId(); } } @@ -212,12 +212,12 @@ protected virtual void RegisterEventListeners() CheckPending(); }); - _relayer.Provider.On(ProviderEvents.Connect, (sender, @event) => + _relayer.On(RelayerEvents.Connect, (sender, @event) => { OnConnect(); }); - _relayer.Provider.On(ProviderEvents.Disconnect, (sender, @event) => + _relayer.On(RelayerEvents.Disconnect, (sender, @event) => { OnDisconnect(); }); @@ -263,7 +263,7 @@ protected virtual async Task Restore() throw WalletConnectException.FromType(ErrorType.RESTORE_WILL_OVERRIDE, Name); } - cached = persisted; + _cached = persisted; } protected virtual async void CheckPending() @@ -277,9 +277,9 @@ protected virtual async void CheckPending() protected virtual async Task Reset() { - if (cached.Length > 0) + if (_cached.Length > 0) { - var batches = cached.Batch(500); + var batches = _cached.Batch(500); foreach (var batch in batches) { await this.BatchSubscribe(batch.ToArray()); @@ -324,7 +324,7 @@ protected virtual async Task RpcSubscribe(string topic, ProtocolOptions var subscribe = _relayer.Request(request); await subscribe.WithTimeout(20000); - return HashUtils.HashMessage(topic + this.clientId); + return HashUtils.HashMessage(topic + this._clientId); } protected virtual Task RpcUnsubscribe(string topic, string id, ProtocolOptions relay) @@ -345,8 +345,8 @@ protected virtual Task RpcUnsubscribe(string topic, string id, ProtocolOptions r protected virtual void OnEnabled() { - cached = Array.Empty(); - initialized = true; + _cached = Array.Empty(); + _initialized = true; if (onSubscriberReady != null) onSubscriberReady(this, EventArgs.Empty); @@ -359,11 +359,10 @@ protected virtual void OnDisconnect() protected virtual void OnDisable() { - logger.Log("OnDisable invoked"); - cached = Values; + _cached = Values; _subscriptions.Clear(); _topicMap.Clear(); - initialized = false; + _initialized = false; } protected virtual async void OnConnect() @@ -378,9 +377,9 @@ private async Task RestartToComplete() { if (!RestartInProgress) return; - logger.Log("waiting for restart"); + _logger.Log("waiting for restart"); await restartTask.Task; - logger.Log("restart completed"); + _logger.Log("restart completed"); } protected virtual void OnSubscribe(string id, PendingSubscription @params) @@ -516,7 +515,7 @@ protected virtual bool HasSubscription(string id, string topic) protected virtual void IsInitialized() { - if (!initialized) + if (!_initialized) { throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, Name); }