diff --git a/src/Reown.AppKit.Unity/Plugins/AppKit.jslib b/src/Reown.AppKit.Unity/Plugins/AppKit.jslib index 0defbd8..045f79a 100644 --- a/src/Reown.AppKit.Unity/Plugins/AppKit.jslib +++ b/src/Reown.AppKit.Unity/Plugins/AppKit.jslib @@ -64,30 +64,30 @@ mergeInto(LibraryManager.library, { const projectId = parameters.projectId; const metadata = parameters.metadata; - const chains = parameters.chains; - + const chains = parameters.supportedChains; + const enableEmail = parameters.enableEmail; const enableOnramp = parameters.enableOnramp; const enableAnalytics = parameters.enableAnalytics; // Load the scripts and initialize the configuration - import("https://cdn.jsdelivr.net/npm/@reown/appkit-cdn@1.6.0/dist/appkit.js").then(AppKit => { + import("https://cdn.jsdelivr.net/npm/@reown/appkit-cdn@1.6.4/dist/appkit.js").then(AppKit => { const WagmiCore = AppKit['WagmiCore']; const WagmiAdapter = AppKit['WagmiAdapter']; const Chains = AppKit['networks']; const reconnect = WagmiCore['reconnect']; const createAppKit = AppKit['createAppKit']; - const chainsArr = chains.map(chainName => Chains[chainName]); - + const networks = chains.map(c => Chains.defineChain(c)); + const wagmiAdapter = new WagmiAdapter({ - networks: chainsArr, + networks: networks, projectId }) const modal = createAppKit({ adapters: [wagmiAdapter], - networks: chainsArr, + networks: networks, metadata: metadata, projectId, features: { diff --git a/src/Reown.AppKit.Unity/Runtime/Chain.cs b/src/Reown.AppKit.Unity/Runtime/Chain.cs index a650bbb..86abb2e 100644 --- a/src/Reown.AppKit.Unity/Runtime/Chain.cs +++ b/src/Reown.AppKit.Unity/Runtime/Chain.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UnityEngine; namespace Reown.AppKit.Unity { @@ -9,6 +10,7 @@ public class Chain public virtual string Name { get; } // https://github.com/wevm/viem/blob/main/src/chains/index.ts + [Obsolete("The ViemName property will be removed")] public virtual string ViemName { get; } public virtual Currency NativeCurrency { get; } public virtual BlockExplorer BlockExplorer { get; } @@ -46,6 +48,11 @@ public Chain( IsTestnet = isTestnet; ImageUrl = imageUrl; ViemName = viemName; + + if (!string.IsNullOrWhiteSpace(viemName)) + { + Debug.LogWarning($"The ViemName property is deprecated and will be removed in the future. You don't need to set {viemName} for the chain {name} in the `Chain` constructor."); + } } } @@ -105,7 +112,6 @@ public static class References public const string Arbitrum = "42161"; public const string Celo = "42220"; public const string CeloAlfajores = "44787"; - public const string Solana = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"; public const string Polygon = "137"; public const string Avalanche = "43114"; } @@ -137,8 +143,6 @@ public static class References { References.Polygon, "41d04d42-da3b-4453-8506-668cc0727900" }, // Avalanche { References.Avalanche, "30c46e53-e989-45fb-4549-be3bd4eb3b00" }, - // Solana - { References.Solana, "a1b58899-f671-4276-6a5e-56ca5bd59700" } }; public static class Chains @@ -287,18 +291,6 @@ public static class Chains "avalanche" ); - public static readonly Chain Solana = new( - Namespaces.Solana, - References.Solana, - "Solana", - new Currency("Sol", "SOL", 9), - new BlockExplorer("Solana Explorer", "https://explorer.solana.com"), - "https://api.mainnet-beta.solana.com", - false, - $"{ChainImageUrl}/{ImageIds[References.Solana]}", - "solana" - ); - public static readonly IReadOnlyCollection All = new HashSet { Ethereum, @@ -312,8 +304,7 @@ public static class Chains Base, BaseGoerli, Polygon, - Avalanche, - Solana + Avalanche }; } } diff --git a/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnector.cs b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnector.cs index 58926f8..898c28d 100644 --- a/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnector.cs +++ b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnector.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Numerics; using System.Runtime.InteropServices; using System.Threading.Tasks; using AOT; @@ -7,6 +8,7 @@ using Reown.AppKit.Unity.WebGl.Modal; using Reown.AppKit.Unity.WebGl.Wagmi; using Reown.Sign.Models; +using Reown.Sign.Nethereum.Model; using Reown.Sign.Unity; namespace Reown.AppKit.Unity @@ -28,19 +30,19 @@ public WebGlConnector() protected override async Task InitializeAsyncCore(AppKitConfig appKitConfig, SignClientUnity _) { - var viemChainNames = appKitConfig.supportedChains - .Where(c => !string.IsNullOrWhiteSpace(c.ViemName)) - .Select(c => c.ViemName) + var supportedChains = appKitConfig.supportedChains + .Select(c => new WebGlChain(c)) .ToArray(); var parameters = new WebGlInitializeParameters { projectId = appKitConfig.projectId, metadata = appKitConfig.metadata, - chains = viemChainNames, + supportedChains = supportedChains, includeWalletIds = appKitConfig.includedWalletIds ?? Array.Empty(), excludeWalletIds = appKitConfig.excludedWalletIds ?? Array.Empty(), + enableEmail = appKitConfig.enableEmail, enableOnramp = appKitConfig.enableOnramp, enableAnalytics = appKitConfig.enableAnalytics, @@ -169,20 +171,5 @@ public static void InitializationCallback() _initializationTaskCompletionSource.SetResult(true); } } - - [Serializable] - internal class WebGlInitializeParameters - { - public string projectId; - public Core.Metadata metadata; - public string[] chains; - public string[] includeWalletIds; - public string[] excludeWalletIds; - - public bool enableEmail; - public bool enableOnramp; - public bool enableAnalytics; - public bool enableCoinbaseWallet; - } #endif } \ No newline at end of file diff --git a/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs new file mode 100644 index 0000000..661be55 --- /dev/null +++ b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs @@ -0,0 +1,85 @@ +using System; +using Newtonsoft.Json; + +namespace Reown.AppKit.Unity +{ +#if UNITY_WEBGL + [Serializable] + internal class WebGlInitializeParameters + { + public string projectId; + public Core.Metadata metadata; + public WebGlChain[] supportedChains; + public string[] includeWalletIds; + public string[] excludeWalletIds; + + public bool enableEmail; + public bool enableOnramp; + public bool enableAnalytics; + public bool enableCoinbaseWallet; + } + + [Serializable] + internal class WebGlChain + { + [JsonProperty("id")] + public long Id { get; } + + [JsonProperty("caipNetworkId")] + public string CaipNetworkId { get; } + + [JsonProperty("chainNamespace")] + public string ChainNamespace { get; } + + [JsonProperty("name")] + public string Name { get; } + + [JsonProperty("nativeCurrency")] + public Currency NativeCurrency { get; } + + [JsonProperty("rpcUrls")] + public GenericDefault RpcUrls { get; } + + [JsonProperty("blockExplorers")] + public GenericDefault BlockExplorers { get; } + + + public WebGlChain(Chain chain) + { + Id = long.Parse(chain.ChainReference); + CaipNetworkId = chain.ChainId; + ChainNamespace = chain.ChainNamespace; + Name = chain.Name; + NativeCurrency = chain.NativeCurrency; + RpcUrls = new GenericDefault + { + @default = new RpcUrls + { + http = new[] + { + chain.RpcUrl + } + } + }; + BlockExplorers = new GenericDefault + { + @default = chain.BlockExplorer + }; + } + } + + [Serializable] + internal class GenericDefault + { + [JsonProperty("default")] + public T @default; + } + + [Serializable] + internal class RpcUrls + { + [JsonProperty("http")] + public string[] http; + } +#endif +} \ No newline at end of file diff --git a/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs.meta b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs.meta new file mode 100644 index 0000000..1cc3190 --- /dev/null +++ b/src/Reown.AppKit.Unity/Runtime/Connectors/WebGl/WebGlConnectorModel.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 721a46203357490d92cede7984c46c17 +timeCreated: 1736928499 \ No newline at end of file