Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: WalletConnect/WalletConnectSharp#79 #141

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private async Task<WebsocketClient> 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);
Expand Down
43 changes: 21 additions & 22 deletions WalletConnectSharp.Core/Controllers/Subscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@
}
}

private IRelayer _relayer;
private bool initialized;
private string clientId;
private ILogger logger;
private ActiveSubscription[] cached = Array.Empty<ActiveSubscription>();
private readonly IRelayer _relayer;
private bool _initialized;
private string _clientId;
private readonly ILogger _logger;
private ActiveSubscription[] _cached = Array.Empty<ActiveSubscription>();

/// <summary>
/// Create a new Subscriber module using a backing Relayer
Expand All @@ -179,7 +179,7 @@

Events = new EventDelegator(this);

logger = WCLogger.WithContext(Context);
_logger = WCLogger.WithContext(Context);
}

/// <summary>
Expand All @@ -188,12 +188,12 @@
/// </summary>
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();
}
}

Expand All @@ -212,12 +212,12 @@
CheckPending();
});

_relayer.Provider.On<object>(ProviderEvents.Connect, (sender, @event) =>
_relayer.On<object>(RelayerEvents.Connect, (sender, @event) =>
{
OnConnect();
});

_relayer.Provider.On<object>(ProviderEvents.Disconnect, (sender, @event) =>
_relayer.On<object>(RelayerEvents.Disconnect, (sender, @event) =>
{
OnDisconnect();
});
Expand Down Expand Up @@ -263,7 +263,7 @@
throw WalletConnectException.FromType(ErrorType.RESTORE_WILL_OVERRIDE, Name);
}

cached = persisted;
_cached = persisted;
}

protected virtual async void CheckPending()
Expand All @@ -277,9 +277,9 @@

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());
Expand Down Expand Up @@ -324,7 +324,7 @@
var subscribe = _relayer.Request<JsonRpcSubscriberParams, string>(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)
Expand All @@ -345,8 +345,8 @@

protected virtual void OnEnabled()
{
cached = Array.Empty<ActiveSubscription>();
initialized = true;
_cached = Array.Empty<ActiveSubscription>();
_initialized = true;

if (onSubscriberReady != null)
onSubscriberReady(this, EventArgs.Empty);
Expand All @@ -359,11 +359,10 @@

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()
Expand All @@ -378,9 +377,9 @@
{
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)
Expand Down Expand Up @@ -516,7 +515,7 @@

protected virtual void IsInitialized()
{
if (!initialized)
if (!_initialized)
{
throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, Name);
}
Expand Down Expand Up @@ -624,7 +623,7 @@
return await this._relayer.Request<BatchSubscribeParams, string[]>(request)
.WithTimeout(TimeSpan.FromSeconds(45));
}
catch (Exception e)

Check warning on line 626 in WalletConnectSharp.Core/Controllers/Subscriber.cs

View workflow job for this annotation

GitHub Actions / build (unit-tests)

The variable 'e' is declared but never used

Check warning on line 626 in WalletConnectSharp.Core/Controllers/Subscriber.cs

View workflow job for this annotation

GitHub Actions / build (integration-tests)

The variable 'e' is declared but never used
{
this._relayer.Events.Trigger(RelayerEvents.ConnectionStalled, new object());
throw;
Expand Down
Loading