Skip to content

fix: Remove unnecessary chainID check from AddressProvider #196

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

Merged
merged 2 commits into from
May 28, 2024
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
6 changes: 2 additions & 4 deletions Tests/WalletConnectSharp.Sign.Test/SignTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using WalletConnectSharp.Common.Model.Errors;
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Crypto;
using WalletConnectSharp.Network.Models;
using WalletConnectSharp.Sign.Interfaces;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine;
using WalletConnectSharp.Storage;
using WalletConnectSharp.Tests.Common;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -786,8 +784,8 @@ public async Task TestAddressProviderChainIdChange()

_ = await TestConnectMethod(ClientA, ClientB);

const string badChainId = "invalid:invalid";
await Assert.ThrowsAsync<InvalidOperationException>(() => ClientA.AddressProvider.SetDefaultChainIdAsync(badChainId));
const string badChainId = "badChainId";
await Assert.ThrowsAsync<ArgumentException>(() => ClientA.AddressProvider.SetDefaultChainIdAsync(badChainId));

// Change the default chain id
const string newChainId = "eip155:10";
Expand Down
5 changes: 3 additions & 2 deletions WalletConnectSharp.Sign/Controllers/AddressProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Core;
using WalletConnectSharp.Sign.Interfaces;
using WalletConnectSharp.Sign.Models;
using WalletConnectSharp.Sign.Models.Engine.Events;
Expand Down Expand Up @@ -220,9 +221,9 @@ public async Task SetDefaultChainIdAsync(string chainId)
throw new ArgumentNullException(nameof(chainId));
}

if (!DefaultSession.Namespaces[DefaultNamespace].Chains.Contains(chainId))
if (!Utils.IsValidChainId(chainId))
{
throw new InvalidOperationException($"Chain {chainId} is not available in the current session");
throw new ArgumentException("The format of 'chainId' is invalid. Must be in the format of 'namespace:chainId' (e.g. 'eip155:10'). See CAIP-2 for more information.");
}

DefaultChainId = chainId;
Expand Down