-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
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`
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<byte> 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<byte> bytes) | ||
{ | ||
return new Hex(bytes.ToArray()).ToString(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,38 +1,85 @@ | ||
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) | ||
{ | ||
serializedObject = root.serializedObject; | ||
rootPath = root.propertyPath; | ||
} | ||
|
||
public List<byte> GetBytes() | ||
public SerializedProperty Property => serializedObject.FindProperty(rootPath); | ||
|
||
public abstract IEnumerable<SerializedProperty> ByteProperties { get; } | ||
|
||
public List<byte> GetBytes() => ByteProperties | ||
.Select(prop => (byte)prop.intValue) | ||
.ToList() | ||
; | ||
|
||
public abstract void SetBytes(List<byte> 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<SerializedProperty> ByteProperties | ||
{ | ||
get | ||
{ | ||
foreach (SerializedProperty child in Property) | ||
{ | ||
if (byteRegex.IsMatch(child.name) && child.propertyType == SerializedPropertyType.Integer) | ||
{ | ||
yield return child; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public override void SetBytes(List<byte> 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<SerializedProperty> ByteProperties | ||
{ | ||
var bytes = new List<byte>(); | ||
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<byte> bytes) | ||
public override void SetBytes(List<byte> 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]; | ||
} | ||
} | ||
} |
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,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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,25 @@ | ||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True"> | ||
<ui:Label text="Connect Account via WalletConnect" display-tooltip-when-elided="true" name="Title" style="-unity-text-align: upper-center; padding-bottom: 10px; padding-top: 5px; font-size: 14px;" /> | ||
<ui:VisualElement name="AssetReferenceContent" style="margin-top: 5px; margin-bottom: 5px;"> | ||
<uie:ObjectField label="Account Asset" allow-scene-objects="true" binding-path="asset" type="AlgoSdk.WalletConnect.WalletConnectAccountAsset, CareBoo.AlgoSdk.WalletConnect" focusable="true" name="AssetField" style="display: flex; visibility: visible;" /> | ||
<ui:TextField picking-mode="Ignore" label="Connection Status" value="filler text" text="No Connection" name="StatusField" readonly="true" binding-path="statusText" /> | ||
</ui:VisualElement> | ||
<ui:VisualElement name="ConnectedContent" style="align-items: center; display: flex; visibility: visible; margin-top: 5px; margin-bottom: 5px;"> | ||
<ui:Button text="Connect New Wallet" display-tooltip-when-elided="true" name="ConnectNewWalletButton" /> | ||
</ui:VisualElement> | ||
<ui:VisualElement name="ConfigureSessionContent" style="visibility: visible; display: flex; margin-top: 5px; margin-bottom: 5px;"> | ||
<ui:TextField picking-mode="Ignore" label="WalletConnect Bridge URL" value="filler text" text="https://bridge.walletconnect.org" name="BridgeUrlField" binding-path="account.sessionData.bridgeUrl" is-delayed="true" readonly="false" style="justify-content: flex-start;"> | ||
<ui:Button display-tooltip-when-elided="true" name="RandomizeButton" tooltip="Get a random, WalletConnect bridge url." /> | ||
</ui:TextField> | ||
<uie:PropertyField name="DappMetaField" binding-path="account.sessionData.dappMeta" label="Dapp Information" /> | ||
<ui:VisualElement name="ButtonContent" style="align-items: center; margin-top: 5px; margin-bottom: 5px;"> | ||
<ui:Button text="Connect" display-tooltip-when-elided="true" name="StartSessionButton" /> | ||
</ui:VisualElement> | ||
</ui:VisualElement> | ||
<ui:VisualElement name="RequestingHandshakeContent" style="display: flex; margin-top: 5px; margin-bottom: 5px;"> | ||
<ui:VisualElement name="QrCodeContent" /> | ||
<ui:VisualElement name="HandshakeStatusContent" style="align-items: center; justify-content: center; flex-direction: column;"> | ||
<ui:Button text="Cancel" display-tooltip-when-elided="true" name="CancelHandshakeButton" style="max-width: 50%; flex-grow: 0;" /> | ||
</ui:VisualElement> | ||
</ui:VisualElement> | ||
</ui:UXML> |
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,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<Object>(serializedObject.targetObject, out var assetGuid, out var _)) | ||
{ | ||
WalletConnectEditorWindow.Show(assetGuid); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.