Skip to content

Commit

Permalink
Merge branch 'dev' into rob/embedded-wallet-ui-1228
Browse files Browse the repository at this point in the history
  • Loading branch information
rob1997 authored Jan 21, 2025
2 parents 2630e6a + 981d10d commit a202d79
Show file tree
Hide file tree
Showing 184 changed files with 3,126 additions and 711 deletions.
2 changes: 2 additions & 0 deletions Packages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ crashlytics-build.properties
# Ignore the build artifacts from our libraries
/io.chainsafe.web3-unity/Runtime/Libraries/*.dll
/io.chainsafe.web3-unity/Runtime/Libraries/*.dll.meta

/io.chainsafe.web3-unity/Runtime/Libraries/*.pdb
/io.chainsafe.web3-unity/Runtime/Libraries/*.pdb.meta

/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.dll
/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.dll.meta

/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.pdb
/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.pdb.meta

Expand Down
Binary file not shown.
12 changes: 12 additions & 0 deletions Packages/io.chainsafe.web3-unity.loader/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;

[InitializeOnLoad]
public static class ScopedRegistryAndDependencyInstaller
{
private static readonly string RegistryName = "package.openupm.com";
private static readonly string RegistryUrl = "https://package.openupm.com";
private static readonly string[] RequiredScopes =
{
"com.reown",
"com.nethereum.unity"
};

// The Git dependency to add
private const string ChainsafeDependencyKey = "io.chainsafe.web3-unity";
private const string ChainsafeLoaderDependencyKey = "io.chainsafe.web3-unity.loader";
private const string ChainsafeDependencyUrl = "https://github.com/ChainSafe/web3.unity.git?path=/Packages/io.chainsafe.web3-unity#nikola/appkit-implementation-1210";
private const string DependenciesKey = "Dependencies Installed";
static ScopedRegistryAndDependencyInstaller()
{
// Check if we've already installed the registry and dependencies
if (PlayerPrefs.GetInt(DependenciesKey, 0) == 1)
return;

InstallDependencies();
}

[MenuItem("Edit/Install dependencies")]
public static void InstallDependencies()
{

try
{
// Set EditorPref so we don't run again if we run into an error.
PlayerPrefs.SetInt(DependenciesKey, 1);
string manifestPath = Path.Combine(Application.dataPath, "../Packages/manifest.json");
string manifestJson = File.ReadAllText(manifestPath, Encoding.UTF8);
JObject manifest = JObject.Parse(manifestJson);

// Ensure scopedRegistries node exists
if (manifest["scopedRegistries"] == null)
{
manifest["scopedRegistries"] = new JArray();
}

var scopedRegistries = (JArray)manifest["scopedRegistries"];

// Find if our registry already exists
var existingRegistry = scopedRegistries
.OfType<JObject>()
.FirstOrDefault(r =>
r["name"] != null &&
r["name"].Value<string>().Equals(RegistryName, System.StringComparison.OrdinalIgnoreCase));

if (existingRegistry == null)
{
// Create a new registry entry
existingRegistry = new JObject
{
["name"] = RegistryName,
["url"] = RegistryUrl,
["scopes"] = new JArray(RequiredScopes)
};
scopedRegistries.Add(existingRegistry);
}
else
{
// Registry exists, ensure scopes are present
JArray scopesArray = (JArray)existingRegistry["scopes"];
var currentScopes = scopesArray.Select(s => s.Value<string>()).ToList();

foreach (var scope in RequiredScopes)
{
if (!currentScopes.Contains(scope))
{
scopesArray.Add(scope);
}
}
}

// Add the Chainsafe Git dependency
if (manifest["dependencies"] == null)
{
manifest["dependencies"] = new JObject();
}

JObject dependencies = (JObject)manifest["dependencies"];

// If not present or differs, add/update it
if (dependencies[ChainsafeDependencyKey] == null || dependencies[ChainsafeDependencyKey].Value<string>() != ChainsafeDependencyUrl)
{
dependencies[ChainsafeDependencyKey] = ChainsafeDependencyUrl;
}

dependencies.Remove(ChainsafeLoaderDependencyKey);

// Write changes back
File.WriteAllText(manifestPath, manifest.ToString(), Encoding.UTF8);


// Refresh to ensure Unity sees the new dependencies
AssetDatabase.Refresh();
// Clear the key because maybe some other project you get will have the same name so since all the things inside of the editor
// have been installed, you can be safely removed.
PlayerPrefs.DeleteKey(DependenciesKey);
}
catch (System.Exception ex)
{
Debug.LogError($"Failed to install scoped registries or Chainsafe dependency: {ex.Message}\n{ex.StackTrace}");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "io.chainsafe.web3-unity.loader.editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Packages/io.chainsafe.web3-unity.loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "io.chainsafe.web3-unity.loader",
"version": "3.1.0",
"displayName": "web3.unity SDK Loader",
"description": "Loads chaisnafe sdk in unity from git.",
"license": "LGPL-3.0-only",
"licensesUrl": "https://github.com/ChainSafe/web3.unity/blob/main/LICENSE",
"documentationUrl": "https://docs.gaming.chainsafe.io/",
"dependencies": {
"com.unity.nuget.newtonsoft-json": "3.0.2"
},
"keywords": [
"web3",
"ethereum",
"evm"
],
"author": {
"name": "ChainSafe Gaming",
"email": "[email protected]",
"url": "https://gaming.chainsafe.io/"
}
}
7 changes: 7 additions & 0 deletions Packages/io.chainsafe.web3-unity.loader/package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions Packages/io.chainsafe.web3-unity/Editor/ABICSharpConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using ChainSafe.Gaming.RPC.Events;
using Nethereum.ABI;
Expand Down Expand Up @@ -124,9 +123,10 @@ private void ConvertAbiToCSharp()
}

text = text.Replace("{CLASS_NAME}", className);
var minifiedJson = JsonDocument.Parse(_abi).RootElement.GetRawText();
var escapedJson = minifiedJson.Replace("\"", "\\\"");
text = text.Replace("{CONTRACT_ABI}", escapedJson);
string removeNewLines = _abi.Replace("\n", "");
string removeWhiteSpaces = Regex.Replace(removeNewLines, @"\s", "");
string improvedABI = removeWhiteSpaces.Replace("\"", "\\\"");
text = text.Replace("{CONTRACT_ABI}", improvedABI);
text = Regex.Replace(text, @"\s*\{CUSTOM_CLASSES\}", "\n\n" + ParseCustomClasses());
text = Regex.Replace(text, @"\s*\{EVENT_CLASSES\}", "\n\n" + ParseEventClasses());
text = Regex.Replace(text, @"\s*\{METHODS\}", "\n\n" + ParseMethods());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#if UNITY_WEBGL
using ChainSafe.Gaming.UnityPackage.Connection;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace ChainSafe.Gaming.Editor.Reown
{
public class ReownWebGLPreBuild : IPreprocessBuildWithReport
{
public int callbackOrder { get; }

public void OnPreprocessBuild(BuildReport report)
{
// Use AssetDatabase to load the TextAsset from Editor/Resources
string assetPath = "Packages/io.chainsafe.web3-unity/Editor/Resources/ViemChain.txt";
TextAsset file = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);

if (file != null)
{
ReownConnectionProvider provider = Resources.Load<ReownConnectionProvider>("ReownConnectionProvider");
provider.PopulateViemNames(file.text);
}
else
{
Debug.LogError($"Could not load ViemChain.txt from path: {assetPath}");
}
}

}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/io.chainsafe.web3-unity/Editor/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a202d79

Please sign in to comment.