Skip to content

Commit

Permalink
Merge pull request #1017 from skibitsky/master
Browse files Browse the repository at this point in the history
Fixes to signing in the `NethereumWalletConnectInterceptor`
  • Loading branch information
juanfranblanco committed Mar 26, 2024
2 parents c4bc95a + 8dd4a23 commit 50e291d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Nethereum.WalletConnect/Nethereum.WalletConnect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<ProjectReference Include="..\Nethereum.UI\Nethereum.UI.csproj" />
<ProjectReference Include="..\Nethereum.Web3\Nethereum.Web3.csproj" />
<PackageReference Include="Newtonsoft.Json" Version="[13.0.3,14)" />
<PackageReference Include="WalletConnect.Core" Version="2.2.0" />
<PackageReference Include="WalletConnect.Sign" Version="2.2.0" />
<PackageReference Include="WalletConnect.Core" Version="2.3.0" />
<PackageReference Include="WalletConnect.Sign" Version="2.3.0" />


</ItemGroup>
Expand Down
28 changes: 12 additions & 16 deletions src/Nethereum.WalletConnect/NethereumWalletConnectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task<string> PersonalSignAsync(string hexUtf8)
var connectedSession = GetWalletConnectConnectedSession();
if (connectedSession != null)
{
var request = new WCPersonalSign(connectedSession.Address, hexUtf8);
var request = new WCPersonalSign(hexUtf8, connectedSession.Address);

return await WalletConnectClient.Request<WCPersonalSign, string>(connectedSession.Session.Topic, request, connectedSession.ChainId);
}
Expand Down Expand Up @@ -232,25 +232,21 @@ private static WCNativeCurrency ConvertNativeCurrency(NativeCurrency nativeCurre

public WalletConnectConnectedSession GetWalletConnectConnectedSession()
{
var currentSession = WalletConnectClient.Session.Get(WalletConnectClient.Session.Keys[0]);

var defaultChain = currentSession.Namespaces.Keys.FirstOrDefault();

if (string.IsNullOrWhiteSpace(defaultChain))
var currentSession = WalletConnectClient.AddressProvider.DefaultSession;

if (string.IsNullOrWhiteSpace(currentSession.Topic))
return null;

var defaultNamespace = currentSession.Namespaces[defaultChain];

if (defaultNamespace.Accounts.Length == 0)
return null;
var defaultChainId = WalletConnectClient.AddressProvider.DefaultChainId;

var fullAddress = defaultNamespace.Accounts[0];
var addressParts = fullAddress.Split(":");
var caip25Address = currentSession.CurrentAddress(defaultChainId);

var address = addressParts[2];
var chainId = string.Join(':', addressParts.Take(2));

return new WalletConnectConnectedSession() { Session = currentSession, Address = address, ChainId = chainId };
return new WalletConnectConnectedSession
{
Session = currentSession,
Address = caip25Address.Address,
ChainId = caip25Address.ChainId
};
}
}

Expand Down

0 comments on commit 50e291d

Please sign in to comment.