diff --git a/WalletConnectSharp.Core/Controllers/Relayer.cs b/WalletConnectSharp.Core/Controllers/Relayer.cs index 9b9d65b..8521705 100644 --- a/WalletConnectSharp.Core/Controllers/Relayer.cs +++ b/WalletConnectSharp.Core/Controllers/Relayer.cs @@ -78,6 +78,12 @@ public string Context /// public IJsonRpcProvider Provider { get; private set; } + /// + /// How long the should wait before throwing a during + /// the connection phase. If this field is null, then the timeout will be infinite. + /// + public TimeSpan? ConnectionTimeout { get; set; } + /// /// Whether this Relayer is connected /// @@ -133,6 +139,8 @@ public Relayer(RelayerOptions opts) } projectId = opts.ProjectId; + + ConnectionTimeout = opts.ConnectionTimeout; } /// @@ -404,7 +412,11 @@ async void Task2() this.Events.ListenForOnce(RelayerEvents.TransportClosed, RejectTransportOpen); try { - await this.Provider.Connect().WithTimeout(TimeSpan.FromSeconds(5), "socket stalled"); + var connectionTask = this.Provider.Connect(); + if (ConnectionTimeout != null) + connectionTask = connectionTask.WithTimeout((TimeSpan)ConnectionTimeout, "socket stalled"); + + await connectionTask; task2.TrySetResult(true); } finally diff --git a/WalletConnectSharp.Core/Interfaces/IRelayer.cs b/WalletConnectSharp.Core/Interfaces/IRelayer.cs index 63de1d0..d58f95e 100644 --- a/WalletConnectSharp.Core/Interfaces/IRelayer.cs +++ b/WalletConnectSharp.Core/Interfaces/IRelayer.cs @@ -51,6 +51,12 @@ public interface IRelayer : IEvents, IModule /// public IJsonRpcProvider Provider { get; } + /// + /// How long the should wait before throwing a during + /// the connection phase. If this field is null, then the timeout will be infinite. + /// + public TimeSpan? ConnectionTimeout { get; set; } + /// /// Whether this Relayer is connected to the WalletConnect relay server /// diff --git a/WalletConnectSharp.Core/Models/CoreOptions.cs b/WalletConnectSharp.Core/Models/CoreOptions.cs index 0d7ebb6..04cf6e8 100644 --- a/WalletConnectSharp.Core/Models/CoreOptions.cs +++ b/WalletConnectSharp.Core/Models/CoreOptions.cs @@ -65,6 +65,12 @@ public class CoreOptions /// with either the KeyChain option or a default keychain /// public ICrypto CryptoModule; - + + /// + /// How long the should wait before throwing a during + /// the connection phase. If this field is null, then the timeout will be infinite. + /// + public TimeSpan? ConnectionTimeout = TimeSpan.FromSeconds(30); + } } diff --git a/WalletConnectSharp.Core/Models/Relay/RelayerOptions.cs b/WalletConnectSharp.Core/Models/Relay/RelayerOptions.cs index 0a1d645..53d6577 100644 --- a/WalletConnectSharp.Core/Models/Relay/RelayerOptions.cs +++ b/WalletConnectSharp.Core/Models/Relay/RelayerOptions.cs @@ -28,5 +28,11 @@ public class RelayerOptions /// [JsonProperty("projectId")] public string ProjectId { get; set; } + + /// + /// How long the should wait before throwing a during + /// the connection phase. If this field is null, then the timeout will be infinite. + /// + public TimeSpan? ConnectionTimeout = TimeSpan.FromSeconds(30); } } diff --git a/WalletConnectSharp.Core/WalletConnectCore.cs b/WalletConnectSharp.Core/WalletConnectCore.cs index d0a14e7..f3b7692 100644 --- a/WalletConnectSharp.Core/WalletConnectCore.cs +++ b/WalletConnectSharp.Core/WalletConnectCore.cs @@ -190,7 +190,8 @@ public WalletConnectCore(CoreOptions options = null) { Core = this, ProjectId = ProjectId, - RelayUrl = options.RelayUrl + RelayUrl = options.RelayUrl, + ConnectionTimeout = options.ConnectionTimeout, }); MessageHandler = new TypedMessageHandler(this);