From 60c13af8bb06680f9add3e00a97a7c41428de2e0 Mon Sep 17 00:00:00 2001 From: Jason Elie Bou Kheir <5115126+jasonboukheir@users.noreply.github.com> Date: Sun, 5 Jun 2022 16:47:31 -0700 Subject: [PATCH] feat(walletconnect): add wallet connect support to UnityEditor (#143) Add a new `WalletConnectAccount` and `WalletConnectAccountAsset` to manage WalletConnect accounts in the editor. BREAKING CHANGE: `AlgorandWalletConnectSession` flow has been changed to reflect new `JsonRpcClient`. - `StartConnection` renamed to `Connect` - `Disconnect` renamed to `DisconnectWallet` - `WaitForConnectionApproval` renamed to `WaitForWalletApproval` - `SavedSession` renamed to `SessionData` --- .../CareBoo.AlgoSdk.Editor/AddressDrawer.cs | 2 +- Editor/CareBoo.AlgoSdk.Editor/Base32Drawer.cs | 6 +- Editor/CareBoo.AlgoSdk.Editor/Base64Drawer.cs | 2 +- .../CareBoo.AlgoSdk.Editor/BytesTextDrawer.cs | 24 +- .../FixedStringDrawer.cs | 4 +- Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs | 25 ++ .../CareBoo.AlgoSdk.Editor/HexDrawer.cs.meta | 2 +- .../CareBoo.AlgoSdk.Editor/MnemonicDrawer.cs | 2 +- .../PrivateKeyDrawer.cs | 2 +- .../CareBoo.AlgoSdk.Editor/SerializedBytes.cs | 81 +++- .../CareBoo.AlgoSdk.WalletConnect.Editor.meta | 3 +- ...areBoo.AlgoSdk.WalletConnect.Editor.asmdef | 21 + ...o.AlgoSdk.WalletConnect.Editor.asmdef.meta | 7 + .../UI.meta | 8 + .../UI/WalletConnectAccountEditorWindow.uxml | 25 ++ ...WalletConnectAccountEditorWindow.uxml.meta | 10 + .../WalletConnectAccountDrawer.cs | 22 ++ .../WalletConnectAccountDrawer.cs.meta | 11 + .../WalletConnectEditorWindow.cs | 165 ++++++++ .../WalletConnectEditorWindow.cs.meta | 15 + .../JsonReader/JsonReader.String.cs | 2 +- Runtime/CareBoo.AlgoSdk.LowLevel/ByteArray.cs | 2 +- .../MessagePackReader.String.cs | 2 +- .../MessagePackWriter.String.cs | 2 +- .../AlgorandWalletConnectSession.cs | 358 +++++------------- .../JsonRpcRequest.Formatters.gen.cs | 2 +- .../IWalletConnectAccount.cs | 63 +++ .../IWalletConnectAccount.cs.meta | 11 + .../IWalletConnectSession.cs | 7 +- .../CareBoo.AlgoSdk.WalletConnect/JsonRpc.cs | 2 +- .../JsonRpcClient.cs | 195 ++++++++++ .../JsonRpcClient.cs.meta | 11 + .../Models/JsonRpcRequest.cs | 4 +- .../Models/NetworkMessage.cs | 2 +- .../{SavedSession.cs => SessionData.cs} | 22 +- ...vedSession.cs.meta => SessionData.cs.meta} | 0 .../Models/WalletConnectRpc.cs | 2 + .../SessionStatus.cs | 10 + .../SessionStatus.cs.meta | 11 + .../WalletConnectAccount.cs | 151 ++++++++ .../WalletConnectAccount.cs.meta | 11 + .../WalletConnectAccountAsset.cs | 67 ++++ .../WalletConnectAccountAsset.cs.meta | 11 + .../WalletConnectSessionEvents.cs | 13 + .../WalletConnectSessionEvents.cs.meta | 11 + .../WebSocketExtensions.cs | 24 +- Runtime/CareBoo.AlgoSdk/Accounts/Account.cs | 2 +- Runtime/CareBoo.AlgoSdk/Accounts/Address.cs | 4 +- Runtime/CareBoo.AlgoSdk/Accounts/Logic.cs | 19 +- .../CareBoo.AlgoSdk/Accounts/PrivateKey.cs | 4 +- .../Formatters/AlgoApiObjectFormatter.cs | 12 +- .../Formatters/AlgoApiSerializer.cs | 14 +- .../Formatters/ByteArrayFormatter.cs | 10 +- .../Formatters/FixedBytesFormatter.cs | 6 +- .../Formatters/Primitives/StringFormatter.cs | 8 +- .../Formatters/StateDeltaFormatter.cs | 2 +- .../Services/Algod/AlgodClient.cs | 2 +- .../Services/Algod/AlgodClientAsset.cs | 10 + .../Services/Algod/AlgodClientAsset.cs.meta | 11 + .../Services/Indexer/IndexerClientAsset.cs | 10 + .../Indexer/IndexerClientAsset.cs.meta | 11 + .../Services/Kmd/KmdAccount.cs | 16 +- .../Services/Kmd/KmdClientAsset.cs | 10 + .../Services/Kmd/KmdClientAsset.cs.meta | 11 + .../Services/Networking/AlgoApiRequest.cs | 4 +- .../SmartContracts/Abi/Contract.cs | 2 +- .../SmartContracts/Abi/MethodCallBuilder.cs | 8 +- .../SmartContracts/Abi/MethodSelector.cs | 2 +- .../SmartContracts/Abi/Values/Array.cs | 2 +- .../SmartContracts/Abi/Values/Tuple.cs | 8 +- .../SmartContracts/AppIndex.cs | 4 +- .../SmartContracts/CompiledTeal.cs | 2 +- .../Transactions/Atomic/AtomicTxn.Building.cs | 4 +- .../Transactions/Atomic/AtomicTxn.Signing.cs | 2 +- .../Transactions/Atomic/TxnIndices.cs | 6 + .../Transactions/ITransaction.cs | 6 +- .../Transactions/Signature/LogicSig.cs | 3 +- .../Transactions/Signature/Multisig.cs | 24 +- .../Transactions/TransactionGroup.cs | 4 +- Runtime/CareBoo.AlgoSdk/Util/Hex.cs | 5 + .../WalletConnect/WalletConnectManager.cs | 17 +- .../Ed25519Test.cs | 4 +- .../JsonReaderTest.cs | 2 +- .../NativeArrayUtilTest.cs | 2 +- .../Abi/Types/TupleTest.cs | 4 +- .../Abi/Types/UfixedNxMTest.cs | 6 +- .../Abi/Types/UintNTest.cs | 8 +- .../CareBoo.AlgoSdk.Tests/BlockTest.cs | 2 +- .../PendingTransactionTest.cs | 2 +- .../Transaction/Atomic/TxnIndicesTest.cs | 10 + .../Assets/TestSerialization/.gitignore | 1 + .../Assets/TestSerialization/TestComponent.cs | 7 - .../TestSerialization/TestSerialization.unity | 3 - .../ProjectSettings/ProjectVersion.txt | 4 +- 94 files changed, 1324 insertions(+), 429 deletions(-) create mode 100644 Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs rename Unity.AlgoSdk.Package/Assets/TestSerialization/TestComponent.cs.meta => Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs.meta (83%) rename Unity.AlgoSdk.Package/Assets/TestSerialization/TestSerialization.unity.meta => Editor/CareBoo.AlgoSdk.WalletConnect.Editor.meta (67%) create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef.meta create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI.meta create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml.meta create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs.meta create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectEditorWindow.cs create mode 100644 Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectEditorWindow.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/IWalletConnectAccount.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/IWalletConnectAccount.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/JsonRpcClient.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/JsonRpcClient.cs.meta rename Runtime/CareBoo.AlgoSdk.WalletConnect/Models/{SavedSession.cs => SessionData.cs} (71%) rename Runtime/CareBoo.AlgoSdk.WalletConnect/Models/{SavedSession.cs.meta => SessionData.cs.meta} (100%) create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/SessionStatus.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/SessionStatus.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectAccount.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectAccount.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectAccountAsset.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectAccountAsset.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectSessionEvents.cs create mode 100644 Runtime/CareBoo.AlgoSdk.WalletConnect/WalletConnectSessionEvents.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Algod/AlgodClientAsset.cs create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Algod/AlgodClientAsset.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Indexer/IndexerClientAsset.cs create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Indexer/IndexerClientAsset.cs.meta create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Kmd/KmdClientAsset.cs create mode 100644 Runtime/CareBoo.AlgoSdk/Services/Kmd/KmdClientAsset.cs.meta create mode 100644 Unity.AlgoSdk.Package/Assets/TestSerialization/.gitignore delete mode 100644 Unity.AlgoSdk.Package/Assets/TestSerialization/TestComponent.cs delete mode 100644 Unity.AlgoSdk.Package/Assets/TestSerialization/TestSerialization.unity diff --git a/Editor/CareBoo.AlgoSdk.Editor/AddressDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/AddressDrawer.cs index 8e5e7d92e..0511766c8 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/AddressDrawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/AddressDrawer.cs @@ -3,7 +3,7 @@ namespace AlgoSdk.Editor { [CustomPropertyDrawer(typeof(Address))] - public class AddressDrawer : BytesTextDrawer
+ public class AddressDrawer : FixedBytesTextDrawer
{ protected override Address GetByteArray(string s) { diff --git a/Editor/CareBoo.AlgoSdk.Editor/Base32Drawer.cs b/Editor/CareBoo.AlgoSdk.Editor/Base32Drawer.cs index b07a452d6..11f608ae0 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/Base32Drawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/Base32Drawer.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; -using UnityEditor; using System.Linq; using Unity.Collections; +using UnityEditor; namespace AlgoSdk.Editor { [CustomPropertyDrawer(typeof(TransactionId))] - public class Base32Drawer : BytesTextDrawer + public class Base32Drawer : FixedBytesTextDrawer { protected override List GetBytes(string s) { @@ -15,7 +15,7 @@ protected override List GetBytes(string s) protected override string GetString(List bytes) { - var t = new NativeText(Base32Encoding.ToString(bytes.ToArray()), Allocator.Temp); + var t = new NativeText(Base32Encoding.ToString(bytes.ToArray()), Allocator.Persistent); try { Base32Encoding.TrimPadding(ref t); diff --git a/Editor/CareBoo.AlgoSdk.Editor/Base64Drawer.cs b/Editor/CareBoo.AlgoSdk.Editor/Base64Drawer.cs index 94181a83e..c9340e326 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/Base64Drawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/Base64Drawer.cs @@ -11,7 +11,7 @@ namespace AlgoSdk.Editor [CustomPropertyDrawer(typeof(Sig))] [CustomPropertyDrawer(typeof(TealBytes))] [CustomPropertyDrawer(typeof(VrfPubKey))] - public class Base64Drawer : BytesTextDrawer + public class Base64Drawer : FixedBytesTextDrawer { protected override List GetBytes(string s) { diff --git a/Editor/CareBoo.AlgoSdk.Editor/BytesTextDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/BytesTextDrawer.cs index af1c70248..b20cb222f 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/BytesTextDrawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/BytesTextDrawer.cs @@ -6,12 +6,12 @@ namespace AlgoSdk.Editor { - public abstract class BytesTextDrawer : BytesTextDrawer - where T : struct, IByteArray + public abstract class BytesTextDrawer : BytesTextDrawer + where TResult : struct, IByteArray { protected override string GetString(List bytes) { - T t = default; + TResult t = default; for (var i = 0; i < bytes.Count; i++) t[i] = bytes[i]; return GetString(t); @@ -26,8 +26,14 @@ protected override List GetBytes(string s) return bytes; } - protected abstract string GetString(T bytes); - protected abstract T GetByteArray(string s); + protected abstract string GetString(TResult bytes); + protected abstract TResult GetByteArray(string s); + } + + public abstract class FixedBytesTextDrawer : BytesTextDrawer + where TResult : struct, IByteArray + { + protected override SerializedBytes GetSerializedBytes(SerializedProperty property) => new SerializedFixedBytes(property); } public abstract class BytesTextDrawer : PropertyDrawer @@ -35,7 +41,7 @@ public abstract class BytesTextDrawer : PropertyDrawer public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel(position, label); - var byteProperties = new SerializedBytes(property); + var byteProperties = GetSerializedBytes(property); var text = GetString(byteProperties.GetBytes()); text = EditorGUI.DelayedTextField(position, text); try @@ -50,5 +56,11 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten protected abstract string GetString(List bytes); protected abstract List GetBytes(string s); + protected abstract SerializedBytes GetSerializedBytes(SerializedProperty property); + } + + public abstract class FixedBytesTextDrawer : BytesTextDrawer + { + protected override SerializedBytes GetSerializedBytes(SerializedProperty property) => new SerializedFixedBytes(property); } } diff --git a/Editor/CareBoo.AlgoSdk.Editor/FixedStringDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/FixedStringDrawer.cs index 8cf3818f7..ef21a45f1 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/FixedStringDrawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/FixedStringDrawer.cs @@ -16,10 +16,10 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten { position = EditorGUI.PrefixLabel(position, label); var lengthProperty = property.FindPropertyRelative("utf8LengthInBytes"); - var byteProperties = new SerializedBytes(property); + var byteProperties = new SerializedFixedBytes(property); var bytes = byteProperties.GetBytes(); var length = math.min(lengthProperty.intValue, bytes.Count); - var text = new NativeText(length, Allocator.Temp); + var text = new NativeText(length, Allocator.Persistent); try { text.Length = length; diff --git a/Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs new file mode 100644 index 000000000..237b28930 --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; + +namespace AlgoSdk.Editor +{ + [CustomPropertyDrawer(typeof(Hex))] + public class HexDrawer : BytesTextDrawer + { + protected override List GetBytes(string s) + { + return Hex.FromString(s).Data.ToList(); + } + + protected override SerializedBytes GetSerializedBytes(SerializedProperty property) + { + return new SerializedVariableBytes(property, "data"); + } + + protected override string GetString(List bytes) + { + return new Hex(bytes.ToArray()).ToString(); + } + } +} diff --git a/Unity.AlgoSdk.Package/Assets/TestSerialization/TestComponent.cs.meta b/Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs.meta similarity index 83% rename from Unity.AlgoSdk.Package/Assets/TestSerialization/TestComponent.cs.meta rename to Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs.meta index 5e271b83f..c5c83a648 100644 --- a/Unity.AlgoSdk.Package/Assets/TestSerialization/TestComponent.cs.meta +++ b/Editor/CareBoo.AlgoSdk.Editor/HexDrawer.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ba55c9d4b4eef4da081b6404c508a0ad +guid: eb5315d3c4e054595933c71aba4e4091 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/CareBoo.AlgoSdk.Editor/MnemonicDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/MnemonicDrawer.cs index 4306967dc..adc2e6c54 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/MnemonicDrawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/MnemonicDrawer.cs @@ -5,7 +5,7 @@ namespace AlgoSdk.Editor { [CustomPropertyDrawer(typeof(Mnemonic))] - public class MnemonicDrawer : BytesTextDrawer + public class MnemonicDrawer : FixedBytesTextDrawer { protected unsafe override List GetBytes(string s) { diff --git a/Editor/CareBoo.AlgoSdk.Editor/PrivateKeyDrawer.cs b/Editor/CareBoo.AlgoSdk.Editor/PrivateKeyDrawer.cs index f0ffcb55e..ba65d1804 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/PrivateKeyDrawer.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/PrivateKeyDrawer.cs @@ -3,7 +3,7 @@ namespace AlgoSdk.Editor { [CustomPropertyDrawer(typeof(PrivateKey))] - public class PrivateKeyDrawer : BytesTextDrawer + public class PrivateKeyDrawer : FixedBytesTextDrawer { protected override PrivateKey GetByteArray(string s) { diff --git a/Editor/CareBoo.AlgoSdk.Editor/SerializedBytes.cs b/Editor/CareBoo.AlgoSdk.Editor/SerializedBytes.cs index 47b20d4e4..26cbbe533 100644 --- a/Editor/CareBoo.AlgoSdk.Editor/SerializedBytes.cs +++ b/Editor/CareBoo.AlgoSdk.Editor/SerializedBytes.cs @@ -1,14 +1,14 @@ using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; using UnityEditor; namespace AlgoSdk.Editor { - public class SerializedBytes + public abstract class SerializedBytes { - static readonly Regex byteRegex = new Regex(@"byte\d\d\d\d", RegexOptions.Compiled); - SerializedObject serializedObject; - string rootPath; + protected SerializedObject serializedObject; + protected string rootPath; public SerializedBytes(SerializedProperty root) { @@ -16,23 +16,70 @@ public SerializedBytes(SerializedProperty root) rootPath = root.propertyPath; } - public List GetBytes() + public SerializedProperty Property => serializedObject.FindProperty(rootPath); + + public abstract IEnumerable ByteProperties { get; } + + public List GetBytes() => ByteProperties + .Select(prop => (byte)prop.intValue) + .ToList() + ; + + public abstract void SetBytes(List bytes); + } + + public class SerializedFixedBytes : SerializedBytes + { + static readonly Regex byteRegex = new Regex(@"byte\d\d\d\d", RegexOptions.Compiled); + + public SerializedFixedBytes(SerializedProperty root) : base(root) { } + + public override IEnumerable ByteProperties + { + get + { + foreach (SerializedProperty child in Property) + { + if (byteRegex.IsMatch(child.name) && child.propertyType == SerializedPropertyType.Integer) + { + yield return child; + } + } + } + } + + public override void SetBytes(List bytes) + { + var props = ByteProperties.ToList(); + for (var i = 0; i < bytes.Count; i++) + props[i].intValue = bytes[i]; + } + } + + public class SerializedVariableBytes : SerializedBytes + { + readonly string byteArrayName; + public SerializedVariableBytes(SerializedProperty root, string byteArrayName) : base(root) + { + this.byteArrayName = byteArrayName; + } + + public override IEnumerable ByteProperties { - var bytes = new List(); - var root = serializedObject.FindProperty(rootPath); - foreach (SerializedProperty child in root) - if (byteRegex.IsMatch(child.name) && child.propertyType == SerializedPropertyType.Integer) - bytes.Add((byte)child.intValue); - return bytes; + get + { + var arrayProp = Property.FindPropertyRelative(byteArrayName); + for (var i = 0; i < arrayProp.arraySize; i++) + yield return arrayProp.GetArrayElementAtIndex(i); + } } - public void SetBytes(List bytes) + public override void SetBytes(List bytes) { - var i = 0; - var root = serializedObject.FindProperty(rootPath); - foreach (SerializedProperty child in root) - if (byteRegex.IsMatch(child.name) && child.propertyType == SerializedPropertyType.Integer) - child.intValue = (int)bytes[i++]; + var arrayProp = Property.FindPropertyRelative(byteArrayName); + arrayProp.arraySize = bytes.Count; + for (var i = 0; i < bytes.Count; i++) + arrayProp.GetArrayElementAtIndex(i).intValue = bytes[i]; } } } diff --git a/Unity.AlgoSdk.Package/Assets/TestSerialization/TestSerialization.unity.meta b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor.meta similarity index 67% rename from Unity.AlgoSdk.Package/Assets/TestSerialization/TestSerialization.unity.meta rename to Editor/CareBoo.AlgoSdk.WalletConnect.Editor.meta index bbff70946..9f53f29cf 100644 --- a/Unity.AlgoSdk.Package/Assets/TestSerialization/TestSerialization.unity.meta +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor.meta @@ -1,5 +1,6 @@ fileFormatVersion: 2 -guid: 84aa58409b6b740d9b2f65f910018c2e +guid: f4b2b711185e74209b4d30b0caca5133 +folderAsset: yes DefaultImporter: externalObjects: {} userData: diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef new file mode 100644 index 000000000..9543da4db --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef @@ -0,0 +1,21 @@ +{ + "name": "CareBoo.AlgoSdk.WalletConnect.Editor", + "rootNamespace": "AlgoSdk.WalletConnect.Editor", + "references": [ + "GUID:45ab5c0c2cb4a0e4ba897b731349c490", + "GUID:f0420f662311c4331b69b2075b5ab52a", + "GUID:7d7102a6f2a084a30ad9e7734dd7ec17", + "GUID:f51ebe6a0ceec4240a699833d6309b23" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef.meta b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef.meta new file mode 100644 index 000000000..88c79a515 --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/CareBoo.AlgoSdk.WalletConnect.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0cc0e8ad771124641bddf43c6a05faa2 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI.meta b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI.meta new file mode 100644 index 000000000..d7f5e082a --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8609310926b2483b8a2247db378ae52 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml new file mode 100644 index 000000000..a48eac8fc --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml.meta b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml.meta new file mode 100644 index 000000000..fa3396bc6 --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/UI/WalletConnectAccountEditorWindow.uxml.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 73f35da47f1fe4af792dc2d393579a74 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs new file mode 100644 index 000000000..3ad619c60 --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs @@ -0,0 +1,22 @@ +using UnityEditor; +using UnityEngine; + +namespace AlgoSdk.WalletConnect.Editor +{ + [CustomEditor(typeof(WalletConnectAccountAsset))] + public class WalletConnectAssetEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + EditorGUILayout.Space(); + + if (GUILayout.Button("Connect Account") + && AssetDatabase.TryGetGUIDAndLocalFileIdentifier(serializedObject.targetObject, out var assetGuid, out var _)) + { + WalletConnectEditorWindow.Show(assetGuid); + } + } + } +} diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs.meta b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs.meta new file mode 100644 index 000000000..6a073f1fe --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectAccountDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1c17537eada164c7e90986c6fba70c65 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectEditorWindow.cs b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectEditorWindow.cs new file mode 100644 index 000000000..12e8bcc31 --- /dev/null +++ b/Editor/CareBoo.AlgoSdk.WalletConnect.Editor/WalletConnectEditorWindow.cs @@ -0,0 +1,165 @@ +using System; +using Cysharp.Threading.Tasks; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; + +namespace AlgoSdk.WalletConnect.Editor +{ + public class WalletConnectEditorWindow : EditorWindow + { + [SerializeField] + WalletConnectAccountAsset asset; + + [SerializeField] + VisualTreeAsset visualTree; + + [SerializeField] + string statusText; + + VisualElement configureSessionContent; + VisualElement connectedContent; + VisualElement requestingHandshakeContent; + + Image qrCodeImage; + Button startSessionButton; + + public static void Show(string assetGuid) + { + var window = GetWindow("Connect to wallet"); + var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); + window.asset = AssetDatabase.LoadAssetAtPath(assetPath); + } + + void CreateGUI() + { + var gui = visualTree.CloneTree(); + + connectedContent = gui.Query("ConnectedContent").First(); + configureSessionContent = gui.Query("ConfigureSessionContent").First(); + requestingHandshakeContent = gui.Query("RequestingHandshakeContent").First(); + + var statusTextField = gui.Query("StatusField").First(); + + var assetField = gui.Query("AssetField").First(); + assetField.RegisterValueChangedCallback((evt) => + { + configureSessionContent.Unbind(); + if (asset) + { + configureSessionContent.Bind(new SerializedObject(asset)); + } + }); + + startSessionButton = configureSessionContent.Query