Skip to content

Commit 32c35b9

Browse files
authored
AppKit is now part of the core solution (#1259)
* Everything is broken * Added AppKit directly inside of our package. * Merges from dev * Small tweaks * Starting the process of creation of the app kit package * REsuming the work * Package successfully created! * Upgraded our Reown in core project to the newer version Added ViemName to the Chain Setting so that people that are using the AppKit can configure their viemName properly. * Removed AppKit, made it part of the core package! Yay! * Cleaning things up. * Fixing bugs! * Adding debug log * Added loader package. * Added newget dependency * More testing * Hmm * MOre * Final test! * dont remove the loader one * Fix * Fixing import bugs * Removing anything related to the new input system because it can cause a lot of issues on importing the packages and we don't have anything related to pasting in our SDK so it doesn't make sense to have it here. * Removing metamask provider Making sure all providers are now adding/switching their chains if the user is on a wrong one. * moved the playerprefs check to the constructor, if the user wants to manually install all the dependencies. * Fixing compiler errors * Run setup.sh * Fixing All the PR suggestions * Fixing signmessage bug. * More descriptive names for classes. * Fixing error Juan got. * Reverted this since we're already in editor * Prebuild process for webgl. * Fixing compiler errors with non-webgl platforms * Fixing build errors finally. * Fixing the switch network bug. * Addressing Oleks comments, fixing web3 unity prefab * Updated appkit to 1.2.0 * Fixing errors. * Fixing Merge Conflicts
1 parent d8846e5 commit 32c35b9

File tree

102 files changed

+2955
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2955
-379
lines changed

Packages/io.chainsafe.web3-unity.loader/Editor.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using Newtonsoft.Json.Linq;
7+
8+
[InitializeOnLoad]
9+
public static class ScopedRegistryAndDependencyInstaller
10+
{
11+
private static readonly string RegistryName = "package.openupm.com";
12+
private static readonly string RegistryUrl = "https://package.openupm.com";
13+
private static readonly string[] RequiredScopes =
14+
{
15+
"com.reown",
16+
"com.nethereum.unity"
17+
};
18+
19+
// The Git dependency to add
20+
private const string ChainsafeDependencyKey = "io.chainsafe.web3-unity";
21+
private const string ChainsafeLoaderDependencyKey = "io.chainsafe.web3-unity.loader";
22+
private const string ChainsafeDependencyUrl = "https://github.com/ChainSafe/web3.unity.git?path=/Packages/io.chainsafe.web3-unity#nikola/appkit-implementation-1210";
23+
private const string DependenciesKey = "Dependencies Installed";
24+
static ScopedRegistryAndDependencyInstaller()
25+
{
26+
// Check if we've already installed the registry and dependencies
27+
if (PlayerPrefs.GetInt(DependenciesKey, 0) == 1)
28+
return;
29+
30+
InstallDependencies();
31+
}
32+
33+
[MenuItem("Edit/Install dependencies")]
34+
public static void InstallDependencies()
35+
{
36+
37+
try
38+
{
39+
// Set EditorPref so we don't run again if we run into an error.
40+
PlayerPrefs.SetInt(DependenciesKey, 1);
41+
string manifestPath = Path.Combine(Application.dataPath, "../Packages/manifest.json");
42+
string manifestJson = File.ReadAllText(manifestPath, Encoding.UTF8);
43+
JObject manifest = JObject.Parse(manifestJson);
44+
45+
// Ensure scopedRegistries node exists
46+
if (manifest["scopedRegistries"] == null)
47+
{
48+
manifest["scopedRegistries"] = new JArray();
49+
}
50+
51+
var scopedRegistries = (JArray)manifest["scopedRegistries"];
52+
53+
// Find if our registry already exists
54+
var existingRegistry = scopedRegistries
55+
.OfType<JObject>()
56+
.FirstOrDefault(r =>
57+
r["name"] != null &&
58+
r["name"].Value<string>().Equals(RegistryName, System.StringComparison.OrdinalIgnoreCase));
59+
60+
if (existingRegistry == null)
61+
{
62+
// Create a new registry entry
63+
existingRegistry = new JObject
64+
{
65+
["name"] = RegistryName,
66+
["url"] = RegistryUrl,
67+
["scopes"] = new JArray(RequiredScopes)
68+
};
69+
scopedRegistries.Add(existingRegistry);
70+
}
71+
else
72+
{
73+
// Registry exists, ensure scopes are present
74+
JArray scopesArray = (JArray)existingRegistry["scopes"];
75+
var currentScopes = scopesArray.Select(s => s.Value<string>()).ToList();
76+
77+
foreach (var scope in RequiredScopes)
78+
{
79+
if (!currentScopes.Contains(scope))
80+
{
81+
scopesArray.Add(scope);
82+
}
83+
}
84+
}
85+
86+
// Add the Chainsafe Git dependency
87+
if (manifest["dependencies"] == null)
88+
{
89+
manifest["dependencies"] = new JObject();
90+
}
91+
92+
JObject dependencies = (JObject)manifest["dependencies"];
93+
94+
// If not present or differs, add/update it
95+
if (dependencies[ChainsafeDependencyKey] == null || dependencies[ChainsafeDependencyKey].Value<string>() != ChainsafeDependencyUrl)
96+
{
97+
dependencies[ChainsafeDependencyKey] = ChainsafeDependencyUrl;
98+
}
99+
100+
dependencies.Remove(ChainsafeLoaderDependencyKey);
101+
102+
// Write changes back
103+
File.WriteAllText(manifestPath, manifest.ToString(), Encoding.UTF8);
104+
105+
106+
// Refresh to ensure Unity sees the new dependencies
107+
AssetDatabase.Refresh();
108+
// Clear the key because maybe some other project you get will have the same name so since all the things inside of the editor
109+
// have been installed, you can be safely removed.
110+
PlayerPrefs.DeleteKey(DependenciesKey);
111+
}
112+
catch (System.Exception ex)
113+
{
114+
Debug.LogError($"Failed to install scoped registries or Chainsafe dependency: {ex.Message}\n{ex.StackTrace}");
115+
}
116+
}
117+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "io.chainsafe.web3-unity.loader.editor",
3+
"rootNamespace": "",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

src/UnitySampleProject/Assets/Resources/MetamaskConnectionProvider.asset.meta renamed to Packages/io.chainsafe.web3-unity.loader/Editor/io.chainsafe.web3-unity.loader.editor.asmdef.meta

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "io.chainsafe.web3-unity.loader",
3+
"version": "3.1.0",
4+
"displayName": "web3.unity SDK Loader",
5+
"description": "Loads chaisnafe sdk in unity from git.",
6+
"license": "LGPL-3.0-only",
7+
"licensesUrl": "https://github.com/ChainSafe/web3.unity/blob/main/LICENSE",
8+
"documentationUrl": "https://docs.gaming.chainsafe.io/",
9+
"dependencies": {
10+
"com.unity.nuget.newtonsoft-json": "3.0.2"
11+
},
12+
"keywords": [
13+
"web3",
14+
"ethereum",
15+
"evm"
16+
],
17+
"author": {
18+
"name": "ChainSafe Gaming",
19+
"email": "[email protected]",
20+
"url": "https://gaming.chainsafe.io/"
21+
}
22+
}

Packages/io.chainsafe.web3-unity.loader/package.json.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)