Skip to content

Commit

Permalink
WalletConnect transforms into Reown (#1199)
Browse files Browse the repository at this point in the history
* Replaced WalletConnect with Reown

* Added 'Set Primary Chain' functionality to Web3 Settings Editor

* Fixed local wallet connection

* Fixed namespace building process for Reown

* Improved Reown session management and redirection to local wallet procedure

* Added wallet filters for Desktop and Mobile for Reown

* Removed commented out code

* Added WithForceNewSession extension method for ReownConfigAsset also

* Added Reown logo

* Moved the BuildUriParameters method into HttpUtils.cs

* Updated Packages build process to include Reown

* Updated a Reown log message

* Linter fixes

* Removed commented out code

* Reown integration polishing

* Linter
  • Loading branch information
creeppak authored Oct 22, 2024
1 parent 4cf30a2 commit bad25d0
Show file tree
Hide file tree
Showing 140 changed files with 1,429 additions and 1,503 deletions.
2 changes: 1 addition & 1 deletion ChainSafe.Gaming.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChainSafe.Gaming.Unity.ThirdParty", "src\ChainSafe.Gaming.Unity.ThirdParty\ChainSafe.Gaming.Unity.ThirdParty.csproj", "{9EC71CB4-9401-4E02-AC63-FC13B3D1AA53}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChainSafe.Gaming.WalletConnect", "src\ChainSafe.Gaming.WalletConnect\ChainSafe.Gaming.WalletConnect.csproj", "{99E7A645-CAC5-441B-848D-1253405D6400}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChainSafe.Gaming.Reown", "src\ChainSafe.Gaming.Reown\ChainSafe.Gaming.Reown.csproj", "{99E7A645-CAC5-441B-848D-1253405D6400}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.InProcessSigner", "src\ChainSafe.Gaming.InProcessSigner\ChainSafe.Gaming.InProcessSigner.csproj", "{3C01FD36-4D44-4886-A971-4786D99CBFCC}"
EndProject
Expand Down
3 changes: 2 additions & 1 deletion ChainSafe.Gaming.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nethereum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Offchain/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Offchain/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Reown/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public override void OnInspectorGUI()
_allProviders.Add(newProvider);

_editorFoldouts[providerType] = true;

providersProperty.InsertArrayElementAtIndex(providersProperty.arraySize);

providersProperty.GetArrayElementAtIndex(providersProperty.arraySize - 1).objectReferenceValue = newProvider;
Expand Down
10 changes: 10 additions & 0 deletions Packages/io.chainsafe.web3-unity/Editor/Reown/ReownConfigEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using ChainSafe.Gaming.Reown;
using UnityEditor;

namespace ChainSafe.Gaming.Editor.Reown
{
[CustomEditor(typeof(ReownConfigAsset))]
public class ReownConfigEditor : ReownConfigEditorBase
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using ChainSafe.Gaming.Reown.Wallets;
using UnityEditor;
using UnityEngine;

namespace ChainSafe.Gaming.Editor.Reown
{
public class ReownConfigEditorBase : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();

GUILayout.Space(10);

using (new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button("List Wallet Providers", GUILayout.ExpandWidth(false)))
{
ListWalletProviders();
}
}
}

private void ListWalletProviders()
{
Application.OpenURL(ReownWalletRegistry.RegistryUri);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using ChainSafe.Gaming.UnityPackage.Connection;
using UnityEditor;

namespace ChainSafe.Gaming.Editor.Reown
{
[CustomEditor(typeof(ReownConnectionProvider))]
public class ReownConnectionProviderEditor : ReownConfigEditorBase
{
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public void OnGUI()
EditorGUILayout.BeginHorizontal();
GUILayout.Label(title, EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
if (window.IsPrimaryChain(chainConfig))
{
GUI.enabled = false;
GUILayout.Button("Primary Chain");
GUI.enabled = true;
}
else if (GUILayout.Button("Set as Primary"))
{
window.SetPrimaryChain(chainConfig);
}
if (GUILayout.Button("Remove"))
{
OnRemoveClick();
Expand Down
27 changes: 24 additions & 3 deletions Packages/io.chainsafe.web3-unity/Editor/Web3SettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ private void DrawFooter()
GUILayout.Label("ChainSafe Gaming", EditorStyles.centeredGreyMiniLabel);
}

private bool IsPrimaryChain(ChainConfigEntry entry)
{
return web3Config.ChainConfigs.Any() && web3Config.ChainConfigs[0] == entry;
}

private void SetPrimaryChain(ChainConfigEntry entry)
{
var indexOf = web3Config.ChainConfigs.IndexOf(entry);

web3Config.ChainConfigs.RemoveAt(indexOf);
web3Config.ChainConfigs.Insert(0, entry);

InitializeChainItems();
chainsScrollPosition = Vector2.zero;
}

private void RemoveChainConfigEntry(string chainId)
{
var index = web3Config.ChainConfigs.FindIndex(entry => entry.ChainId == chainId);
Expand Down Expand Up @@ -315,9 +331,7 @@ private void OnChainListFetched()
{
if (web3Config.ChainConfigs.Count != 0)
{
chainSettingPanels = web3Config.ChainConfigs
.Select((chainConfig) => new ChainSettingsPanel(this, chainConfig))
.ToList();
InitializeChainItems();
}
else
{
Expand All @@ -332,6 +346,13 @@ private void OnChainListFetched()
}
}

private void InitializeChainItems()
{
chainSettingPanels = web3Config.ChainConfigs
.Select((chainConfig) => new ChainSettingsPanel(this, chainConfig))
.ToList();
}

private class ValidateProjectIDResponse
{
[JsonProperty("response")] public bool Response { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chainsafe.web3-unity.Editor",
"rootNamespace": "",
"rootNamespace": "ChainSafe.Gaming.Editor",
"references": [
"GUID:5426c6b788696eb4c88f4198b59839eb"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public ScreenRecord(IGuiScreen screen)
Visible = false;
}
}

private readonly List<ScreenRecord> activeScreens = new();
private int currentVisibleSortOrder = int.MinValue;

public void Register(IGuiScreen screen)
{
activeScreens.Add(new ScreenRecord(screen));
UpdateStackVisibility();
}

public void Unregister(IGuiScreen screen)
{
var record = activeScreens.Find(r => r.Screen == screen);
Expand All @@ -50,31 +50,31 @@ private void UpdateStackVisibility()
var opaqueScreenLayers = activeScreens
.Select(r => r.Screen.Layer)
.Where(l => !l.Transparent);

var newVisibleSortOrder = opaqueScreenLayers.Any()
? opaqueScreenLayers.Max(l => l.SortOrder)
: int.MinValue;

if (newVisibleSortOrder == currentVisibleSortOrder) return;

currentVisibleSortOrder = newVisibleSortOrder;

foreach (var activeScreen in activeScreens)
{
var show = activeScreen.Screen.Layer.SortOrder >= currentVisibleSortOrder;

if (show && !activeScreen.Visible)
{
ShowScreen(activeScreen);
continue;
}

if (!show && activeScreen.Visible)
{
HideScreen(activeScreen);
continue;
}

// ignore
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GuiInfoOverlay : MonoBehaviour
public GameObject ErrorIcon;
public GameObject LoadingIcon;
public Button CloseButton;

private bool closeOnClick;
private Action onClose;
private Action<GuiInfoOverlay> onRelease;
Expand All @@ -29,7 +29,7 @@ public void Initialize(int id, GuiOverlayType type, string message, bool closeOn
this.onClose = onClose;
this.closeOnClick = closeOnClick;
onRelease = release;

ErrorIcon.SetActive(type == GuiOverlayType.Error);
LoadingIcon.SetActive(type == GuiOverlayType.Loading);
Message.text = message;
Expand All @@ -41,7 +41,7 @@ private void OnScreenClick()
{
return;
}

Hide();
}

Expand Down
4 changes: 2 additions & 2 deletions Packages/io.chainsafe.web3-unity/Runtime/GUI/GuiLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
[CreateAssetMenu(menuName = "ChainSafe/Misc/GUI Layer", fileName = "New GUI Layer", order = 1000)]
public class GuiLayer : ScriptableObject
{
[field:SerializeField] public int SortOrder { get; private set; }
[field:SerializeField] public bool Transparent { get; private set; }
[field: SerializeField] public int SortOrder { get; private set; }
[field: SerializeField] public bool Transparent { get; private set; }
}
12 changes: 6 additions & 6 deletions Packages/io.chainsafe.web3-unity/Runtime/GUI/GuiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ private static GuiManager LoadPrefab()
{
var prefab = Resources.Load<GuiManager>(ResourceName);
var manager = Instantiate(prefab);

if (manager.HideInHierarchy)
{
manager.gameObject.hideFlags = HideFlags.HideInHierarchy;
}

DontDestroyOnLoad(manager);
return manager;
}

[SerializeField] private bool HideInHierarchy = true;

[field:SerializeField] public GuiOrientationSystem Orientation { get; private set; }
[field:SerializeField] public GuiOverlayManager Overlays { get; private set; }
[field: SerializeField] public GuiOrientationSystem Orientation { get; private set; }
[field: SerializeField] public GuiOverlayManager Overlays { get; private set; }

public GuiCoordinationSystem Coordination { get; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GuiOrientationSystem : MonoBehaviour
public float AspectRatioThreshold = 1f;
public bool Debug;
public GuiOrientation DebugOrientationValue;

public GuiOrientation Initial { get; private set; }

private void Awake()
Expand Down
Loading

0 comments on commit bad25d0

Please sign in to comment.