diff --git a/Directory.Packages.props b/Directory.Packages.props
index f8f3d8e..fc3e048 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -3,16 +3,17 @@
true
-
+
-
-
-
-
-
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
-
\ No newline at end of file
diff --git a/Tests/WalletConnectSharp.Auth.Tests/WalletConnectSharp.Auth.Tests.csproj b/Tests/WalletConnectSharp.Auth.Tests/WalletConnectSharp.Auth.Tests.csproj
index 9f3749c..d612457 100644
--- a/Tests/WalletConnectSharp.Auth.Tests/WalletConnectSharp.Auth.Tests.csproj
+++ b/Tests/WalletConnectSharp.Auth.Tests/WalletConnectSharp.Auth.Tests.csproj
@@ -14,10 +14,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
diff --git a/Tests/WalletConnectSharp.Crypto.Tests/WalletConnectSharp.Crypto.Tests.csproj b/Tests/WalletConnectSharp.Crypto.Tests/WalletConnectSharp.Crypto.Tests.csproj
index ae51b03..4183b5f 100644
--- a/Tests/WalletConnectSharp.Crypto.Tests/WalletConnectSharp.Crypto.Tests.csproj
+++ b/Tests/WalletConnectSharp.Crypto.Tests/WalletConnectSharp.Crypto.Tests.csproj
@@ -14,10 +14,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
diff --git a/Tests/WalletConnectSharp.Network.Tests/WalletConnectSharp.Network.Tests.csproj b/Tests/WalletConnectSharp.Network.Tests/WalletConnectSharp.Network.Tests.csproj
index 8c72a4b..4fb375d 100644
--- a/Tests/WalletConnectSharp.Network.Tests/WalletConnectSharp.Network.Tests.csproj
+++ b/Tests/WalletConnectSharp.Network.Tests/WalletConnectSharp.Network.Tests.csproj
@@ -14,10 +14,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
diff --git a/Tests/WalletConnectSharp.Sign.Test/WalletConnectSharp.Sign.Test.csproj b/Tests/WalletConnectSharp.Sign.Test/WalletConnectSharp.Sign.Test.csproj
index eefa15c..7cbc5f4 100644
--- a/Tests/WalletConnectSharp.Sign.Test/WalletConnectSharp.Sign.Test.csproj
+++ b/Tests/WalletConnectSharp.Sign.Test/WalletConnectSharp.Sign.Test.csproj
@@ -14,10 +14,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
diff --git a/Tests/WalletConnectSharp.Storage.Test/WalletConnectSharp.Storage.Test.csproj b/Tests/WalletConnectSharp.Storage.Test/WalletConnectSharp.Storage.Test.csproj
index be8fbda..2aaba23 100644
--- a/Tests/WalletConnectSharp.Storage.Test/WalletConnectSharp.Storage.Test.csproj
+++ b/Tests/WalletConnectSharp.Storage.Test/WalletConnectSharp.Storage.Test.csproj
@@ -17,7 +17,6 @@
-
diff --git a/Tests/WalletConnectSharp.Web3Wallet.Tests/WalletConnectSharp.Web3Wallet.Tests.csproj b/Tests/WalletConnectSharp.Web3Wallet.Tests/WalletConnectSharp.Web3Wallet.Tests.csproj
index ed02976..f07c3ac 100644
--- a/Tests/WalletConnectSharp.Web3Wallet.Tests/WalletConnectSharp.Web3Wallet.Tests.csproj
+++ b/Tests/WalletConnectSharp.Web3Wallet.Tests/WalletConnectSharp.Web3Wallet.Tests.csproj
@@ -15,10 +15,6 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
diff --git a/WalletConnectSharp.Core/Controllers/HeartBeat.cs b/WalletConnectSharp.Core/Controllers/HeartBeat.cs
index e327945..e55fc1e 100644
--- a/WalletConnectSharp.Core/Controllers/HeartBeat.cs
+++ b/WalletConnectSharp.Core/Controllers/HeartBeat.cs
@@ -1,3 +1,4 @@
+using WalletConnectSharp.Common.Logging;
using WalletConnectSharp.Core.Interfaces;
namespace WalletConnectSharp.Core.Controllers
@@ -76,7 +77,14 @@ public Task InitAsync(CancellationToken cancellationToken = default)
{
while (!token.IsCancellationRequested)
{
- Pulse();
+ try
+ {
+ Pulse();
+ }
+ catch (Exception ex)
+ {
+ WCLogger.LogError(ex);
+ }
await Task.Delay(Interval, token);
}
diff --git a/WalletConnectSharp.Core/Controllers/Relayer.cs b/WalletConnectSharp.Core/Controllers/Relayer.cs
index 696cf34..f82b6b2 100644
--- a/WalletConnectSharp.Core/Controllers/Relayer.cs
+++ b/WalletConnectSharp.Core/Controllers/Relayer.cs
@@ -277,7 +277,11 @@ protected virtual async void OnProviderPayload(string payloadJson)
protected virtual async Task ShouldIgnoreMessageEvent(MessageEvent messageEvent)
{
- if (!(await Subscriber.IsSubscribed(messageEvent.Topic))) return true;
+ var isSubscribed = await Subscriber.IsSubscribed(messageEvent.Topic);
+ if (!isSubscribed)
+ {
+ return true;
+ }
var exists = Messages.Has(messageEvent.Topic, messageEvent.Message);
return exists;
diff --git a/WalletConnectSharp.Core/Controllers/Subscriber.cs b/WalletConnectSharp.Core/Controllers/Subscriber.cs
index 0ee973e..9c1c38c 100644
--- a/WalletConnectSharp.Core/Controllers/Subscriber.cs
+++ b/WalletConnectSharp.Core/Controllers/Subscriber.cs
@@ -276,22 +276,6 @@ protected virtual async Task Reset()
this.Resubscribed?.Invoke(this, EventArgs.Empty);
}
- protected virtual async Task Resubscribe(ActiveSubscription subscription)
- {
- if (!Ids.Contains(subscription.Id))
- {
- var @params = new PendingSubscription() { Relay = subscription.Relay, Topic = subscription.Topic };
-
- if (pending.ContainsKey(@params.Topic))
- pending.Remove(@params.Topic);
-
- pending.Add(@params.Topic, @params);
-
- var id = await RpcSubscribe(@params.Topic, @params.Relay);
- OnResubscribe(id, @params);
- }
- }
-
protected virtual async Task RpcSubscribe(string topic, ProtocolOptions relay)
{
var api = RelayProtocols.GetRelayProtocol(relay.Protocol);
@@ -522,31 +506,43 @@ public async Task Unsubscribe(string topic, UnsubscribeOptions opts = null)
/// Determines whether the given topic is subscribed or not
///
/// The topic to check
+ /// A token to cancel the operation.
/// Return true if the topic is subscribed, false otherwise
- public Task IsSubscribed(string topic)
+ public async Task IsSubscribed(string topic, CancellationToken cancellationToken = default)
{
- if (Topics.Contains(topic)) return Task.FromResult(true);
-
- return Task.Run(async delegate()
+ if (Topics.Contains(topic))
{
- var startTime = DateTimeOffset.Now.ToUnixTimeSeconds();
+ return true;
+ }
+
+ var startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+ const int timeoutMilliseconds = 5_000;
+ const int delayMilliseconds = 20;
- while (true)
+ try
+ {
+ while (!cancellationToken.IsCancellationRequested)
{
if (!pending.ContainsKey(topic) && Topics.Contains(topic))
{
return true;
}
- var currentTime = DateTimeOffset.Now.ToUnixTimeSeconds();
- if (currentTime - startTime >= 5)
+ var elapsedMilliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds() - startTime;
+ if (elapsedMilliseconds >= timeoutMilliseconds)
{
return false;
}
- await Task.Delay(20);
+ await Task.Delay(delayMilliseconds, cancellationToken);
}
- });
+ }
+ catch (OperationCanceledException)
+ {
+ return false;
+ }
+
+ return false;
}
protected virtual async Task RpcBatchSubscribe(string[] topics, ProtocolOptions relay)
diff --git a/WalletConnectSharp.Core/Interfaces/ISubscriber.cs b/WalletConnectSharp.Core/Interfaces/ISubscriber.cs
index b2837c4..6062ebc 100644
--- a/WalletConnectSharp.Core/Interfaces/ISubscriber.cs
+++ b/WalletConnectSharp.Core/Interfaces/ISubscriber.cs
@@ -71,7 +71,8 @@ public interface ISubscriber : IModule
/// Determines whether the given topic is subscribed or not
///
/// The topic to check
+ /// /// A token to cancel the operation.
/// Return true if the topic is subscribed, false otherwise
- public Task IsSubscribed(string topic);
+ public Task IsSubscribed(string topic, CancellationToken cancellationToken = default);
}
}