Skip to content

Commit

Permalink
Merge pull request #55 from reown-com/develop
Browse files Browse the repository at this point in the history
release: 1.2.2
  • Loading branch information
skibitsky authored Feb 12, 2025
2 parents 1a1ba69 + de1c2ce commit 13f462d
Show file tree
Hide file tree
Showing 36 changed files with 238 additions and 114 deletions.
1 change: 1 addition & 0 deletions sample/Reown.AppKit.Unity/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"com.skibitsky.scene-reference": "1.1.1",
"com.unity.ide.rider": "3.0.34",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.mobile.android-logcat": "1.4.4",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.test-framework": "1.4.5",
"com.unity.ugui": "2.0.0",
Expand Down
47 changes: 27 additions & 20 deletions sample/Reown.AppKit.Unity/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.sign.nethereum.unity": "1.2.1",
"com.reown.sign.unity": "1.2.1",
"com.reown.core": "1.2.1",
"com.reown.unity.dependencies": "1.2.1",
"com.reown.sign.nethereum.unity": "1.2.2",
"com.reown.sign.unity": "1.2.2",
"com.reown.core": "1.2.2",
"com.reown.unity.dependencies": "1.2.2",
"com.unity.vectorgraphics": "2.0.0-preview.24"
}
},
Expand All @@ -38,11 +38,11 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.core.common": "1.2.1",
"com.reown.core.network": "1.2.1",
"com.reown.core.storage": "1.2.1",
"com.reown.core.crypto": "1.2.1",
"com.reown.unity.dependencies": "1.2.1"
"com.reown.core.common": "1.2.2",
"com.reown.core.network": "1.2.2",
"com.reown.core.storage": "1.2.2",
"com.reown.core.crypto": "1.2.2",
"com.reown.unity.dependencies": "1.2.2"
}
},
"com.reown.core.common": {
Expand All @@ -58,42 +58,42 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.core.common": "1.2.1",
"com.reown.core.network": "1.2.1",
"com.reown.core.storage": "1.2.1",
"com.reown.unity.dependencies": "1.2.1"
"com.reown.core.common": "1.2.2",
"com.reown.core.network": "1.2.2",
"com.reown.core.storage": "1.2.2",
"com.reown.unity.dependencies": "1.2.2"
}
},
"com.reown.core.network": {
"version": "file:./../../../src/Reown.Core.Network",
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.core.common": "1.2.1"
"com.reown.core.common": "1.2.2"
}
},
"com.reown.core.storage": {
"version": "file:./../../../src/Reown.Core.Storage",
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.core.common": "1.2.1"
"com.reown.core.common": "1.2.2"
}
},
"com.reown.sign": {
"version": "file:./../../../src/Reown.Sign",
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.core": "1.2.1"
"com.reown.core": "1.2.2"
}
},
"com.reown.sign.nethereum": {
"version": "file:./../../../src/Reown.Sign.Nethereum",
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.sign": "1.2.1",
"com.reown.sign": "1.2.2",
"com.nethereum.unity": "4.26.0"
}
},
Expand All @@ -102,16 +102,16 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.sign.nethereum": "1.2.1",
"com.reown.sign.unity": "1.2.1"
"com.reown.sign.nethereum": "1.2.2",
"com.reown.sign.unity": "1.2.2"
}
},
"com.reown.sign.unity": {
"version": "file:./../../../src/Reown.Sign.Unity",
"depth": 0,
"source": "local",
"dependencies": {
"com.reown.sign": "1.2.1"
"com.reown.sign": "1.2.2"
}
},
"com.reown.unity.dependencies": {
Expand Down Expand Up @@ -160,6 +160,13 @@
},
"url": "https://packages.unity.com"
},
"com.unity.mobile.android-logcat": {
"version": "1.4.4",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.2.1",
"depth": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ PlayerSettings:
loadStoreDebugModeEnabled: 0
visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0
bundleVersion: 1.2.1
bundleVersion: 1.2.2
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefaultVersion>1.2.1</DefaultVersion>
<DefaultVersion>1.2.2</DefaultVersion>
<DefaultTargetFrameworks>net7.0;net8.0;netstandard2.1;</DefaultTargetFrameworks>
<Copyright>reown inc.</Copyright>
<PackageProjectUrl>https://reown.com/</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Reown.AppKit.Unity/Plugins/AppKit.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mergeInto(LibraryManager.library, {
const enableAnalytics = parameters.enableAnalytics;

// Load the scripts and initialize the configuration
import("https://cdn.jsdelivr.net/npm/@reown/[email protected].5/dist/appkit.js").then(AppKit => {
import("https://cdn.jsdelivr.net/npm/@reown/[email protected].8/dist/appkit.js").then(AppKit => {
const WagmiCore = AppKit['WagmiCore'];
const WagmiAdapter = AppKit['WagmiAdapter'];
const Chains = AppKit['networks'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}

.modal--landscape #wallet-view__get-wallet-container {
margin-top: 16;
margin-top: 16px;
}

#wallet-view__get-wallet-container {
Expand All @@ -58,7 +58,7 @@
}

#wallet-view__landscape-continue-in-label {
margin-bottom: 8;
margin-bottom: 8px;
-unity-text-align: middle-center;
color: var(--ro-color-fg-100);
}
Expand All @@ -68,3 +68,7 @@
color: var(--ro-color-fg-200);
}

#wallet-view__landscape-try-again-link-container {
margin-top: 8px;
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@
<ui:VisualElement class="landscape-visible cell">
<ui:Label name="wallet-view__landscape-continue-in-label" text="Continue in --wallet name--" class="text-paragraph"/>
<ui:Label name="wallet-view__landscape-message" text="Accept connection request in your wallet app" class="text-small"/>
<ui:VisualElement name="wallet-view__landscape-try-again-link-container">
<Reown.AppKit.Unity.Components.Link name="wallet-view__landscape-try-again-link"
text="&lt;font-weight=600&gt;Try again&lt;/font-weight&gt;"
size="Small"
variant="Main"
icon="Reown/AppKit/Icons/icon_bold_reload"
/>
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>
2 changes: 1 addition & 1 deletion src/Reown.AppKit.Unity/Runtime/AppKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Reown.AppKit.Unity
public abstract class AppKit : MonoBehaviour
{
[VersionMarker]
public const string Version = "unity-appkit-v1.2.1";
public const string Version = "unity-appkit-v1.2.2";

public static AppKit Instance { get; protected set; }

Expand Down
3 changes: 0 additions & 3 deletions src/Reown.AppKit.Unity/Runtime/Connectors/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public async Task DisconnectAsync()

public async Task ChangeActiveChainAsync(Chain chain)
{
if (!IsAccountConnected)
throw new Exception("No account connected"); // TODO: use custom ex type

await ChangeActiveChainAsyncCore(chain);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Reown.Core.Common.Logging;
using Reown.Core.Common.Model.Errors;
using Reown.Sign.Models;
using Reown.Sign.Models.Engine;
using Reown.Sign.Models.Engine.Methods;
using Reown.Sign.Nethereum;
using Reown.Sign.Nethereum.Model;
using Reown.Sign.Unity;
using UnityEngine;
Expand Down Expand Up @@ -176,9 +177,25 @@ protected override async Task DisconnectAsyncCore()
}
}

private async Task WaitForSessionUpdateAsync(TimeSpan timeout)
{
var tcs = new TaskCompletionSource<bool>();
var sessionUpdateHandler = new EventHandler<Session>((s, session) => { tcs.TrySetResult(true); });

_signClient.SessionUpdatedUnity += sessionUpdateHandler;
try
{
await Task.WhenAny(tcs.Task, Task.Delay(timeout));
}
finally
{
_signClient.SessionUpdatedUnity -= sessionUpdateHandler;
}
}

protected override async Task ChangeActiveChainAsyncCore(Chain chain)
{
if (ActiveSessionSupportsMethod("wallet_switchEthereumChain") && !ActiveSessionIncludesChain(chain.ChainId))
if (ActiveSessionSupportsMethod("wallet_addEthereumChain") && !ActiveSessionIncludesChain(chain.ChainId))
{
var ethereumChain = new EthereumChain(
chain.ChainReference,
Expand All @@ -193,7 +210,41 @@ protected override async Task ChangeActiveChainAsyncCore(Chain chain)
chain.BlockExplorer.url
}
);
await _signClient.SwitchEthereumChainAsync(ethereumChain);

var caip2ChainId = $"eip155:{ethereumChain.chainIdDecimal}";
if (!_signClient.AddressProvider.DefaultSession.Namespaces.TryGetValue("eip155", out var @namespace)
|| !@namespace.Chains.Contains(caip2ChainId))
{
try
{
await AppKit.Evm.RpcRequestAsync<string>("wallet_addEthereumChain", ethereumChain);

await _signClient.AddressProvider.SetDefaultChainIdAsync(chain.ChainId);

await WaitForSessionUpdateAsync(TimeSpan.FromSeconds(5));

OnChainChanged(new ChainChangedEventArgs(chain.ChainId));
OnAccountChanged(new AccountChangedEventArgs(GetCurrentAccount()));
}
catch (ReownNetworkException e)
{
try
{
var metaMaskError = JsonConvert.DeserializeObject<MetaMaskError>(e.Message);
ReownLogger.LogError($"[MetaMask Error] {metaMaskError.Message}");
}
catch (Exception ex)
{
Debug.LogException(ex);
}

throw;
}
catch (Exception e)
{
Debug.LogException(e);
}
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ protected override async Task DisconnectAsyncCore()

protected override Task ChangeActiveChainAsyncCore(Chain chain)
{
return ActiveConnector.ChangeActiveChainAsync(chain);
// On WebGL ActiveConnector is always set to WebGlConnector.
// On Native platforms ActiveConnector is set to the last used connector after session resumption
// or to the connector that was used to connect the account. So, on Native ActiveConnector is null when
// no account is connected. In this case, we don't change the chain in the connector.
return ActiveConnector == null
? Task.CompletedTask
: ActiveConnector.ChangeActiveChainAsync(chain);
}

protected override Task<Account> GetAccountAsyncCore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;

namespace Reown.AppKit.Unity
{
Expand All @@ -19,20 +20,13 @@ protected override Task InitializeAsyncCore(IEnumerable<Chain> supportedChains)

protected override async Task ChangeActiveChainAsyncCore(Chain chain)
{
if (AppKit.ConnectorController.IsAccountConnected)
{
// Request connector to change active chain.
// If connector approves the change, it will trigger the ChainChanged event.
await AppKit.ConnectorController.ChangeActiveChainAsync(chain);
// Request connector to change active chain.
// If connector approves the change, it will trigger the ChainChanged event.
await AppKit.ConnectorController.ChangeActiveChainAsync(chain);

var previousChain = ActiveChain;
ActiveChain = chain;
OnChainChanged(new ChainChangedEventArgs(previousChain, chain));
}
else
{
ActiveChain = chain;
}
var previousChain = ActiveChain;
ActiveChain = chain;
OnChainChanged(new ChainChangedEventArgs(previousChain, chain));

AppKit.EventsController.SendEvent(new Event
{
Expand Down
12 changes: 12 additions & 0 deletions src/Reown.AppKit.Unity/Runtime/Evm/EvmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ public Task<BigInteger> GetGasPriceAsync()
{
return GetGasPriceAsyncCore();
}


// -- RPC Request ----------------------------------------------

public Task<T> RpcRequestAsync<T>(string method, params object[] parameters)
{
if (string.IsNullOrWhiteSpace(method))
throw new ArgumentNullException(nameof(method));

return RpcRequestAsyncCore<T>(method, parameters);
}


protected abstract Task InitializeAsyncCore(SignClientUnity signClient);
Expand All @@ -176,5 +187,6 @@ public Task<BigInteger> GetGasPriceAsync()
protected abstract Task<BigInteger> EstimateGasAsyncCore(string addressTo, BigInteger value, string data = null);
protected abstract Task<BigInteger> EstimateGasAsyncCore(string contractAddress, string contractAbi, string methodName, BigInteger value = default, params object[] arguments);
protected abstract Task<BigInteger> GetGasPriceAsyncCore();
protected abstract Task<T> RpcRequestAsyncCore<T>(string method, params object[] parameters);
}
}
8 changes: 8 additions & 0 deletions src/Reown.AppKit.Unity/Runtime/Evm/NethereumEvmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,13 @@ protected override async Task<BigInteger> GetGasPriceAsyncCore()
var hexBigInt = await Web3.Eth.GasPrice.SendRequestAsync();
return hexBigInt.Value;
}


// -- RPC Request ----------------------------------------------

protected override Task<T> RpcRequestAsyncCore<T>(string method, params object[] parameters)
{
return Web3.Client.SendRequestAsync<T>(method, null, parameters);
}
}
}
5 changes: 5 additions & 0 deletions src/Reown.AppKit.Unity/Runtime/Evm/WagmiEvmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ protected override async Task<BigInteger> GetGasPriceAsyncCore()
var result = await WagmiInterop.GetGasPriceAsync();
return BigInteger.Parse(result);
}

protected override Task<T> RpcRequestAsyncCore<T>(string method, params object[] parameters)
{
throw new System.NotImplementedException();
}
}
#endif
}
Loading

0 comments on commit 13f462d

Please sign in to comment.