Skip to content

Commit

Permalink
Merge pull request #196 from WalletConnect/fix/remove-chainid-check
Browse files Browse the repository at this point in the history
fix: Remove unnecessary chainID check from AddressProvider
  • Loading branch information
skibitsky authored May 28, 2024
2 parents 0a04d93 + ec4ce64 commit a1cebf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
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

0 comments on commit a1cebf4

Please sign in to comment.