Skip to content

Commit 0758fa6

Browse files
committed
Refactor editor scripts and update ReownWallet chain list
1 parent 0156363 commit 0758fa6

File tree

3 files changed

+110
-69
lines changed

3 files changed

+110
-69
lines changed

Assets/Thirdweb/Editor/ThirdwebManagerEditor.cs

Lines changed: 108 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Reflection;
23
using Thirdweb.Unity;
34
using UnityEditor;
@@ -8,61 +9,61 @@ namespace Thirdweb.Editor
89
public abstract class ThirdwebManagerBaseEditor<T> : UnityEditor.Editor
910
where T : MonoBehaviour
1011
{
11-
protected SerializedProperty initializeOnAwakeProp;
12-
protected SerializedProperty showDebugLogsProp;
13-
protected SerializedProperty autoConnectLastWalletProp;
14-
protected SerializedProperty redirectPageHtmlOverrideProp;
15-
protected SerializedProperty rpcOverridesProp;
12+
protected SerializedProperty InitializeOnAwakeProp;
13+
protected SerializedProperty ShowDebugLogsProp;
14+
protected SerializedProperty AutoConnectLastWalletProp;
15+
protected SerializedProperty RedirectPageHtmlOverrideProp;
16+
protected SerializedProperty RpcOverridesProp;
1617

17-
protected int selectedTab;
18-
protected GUIStyle buttonStyle;
19-
protected Texture2D bannerImage;
18+
protected int SelectedTab;
19+
protected GUIStyle ButtonStyle;
20+
protected Texture2D BannerImage;
2021

2122
protected virtual string[] TabTitles => new string[] { "Client/Server", "Preferences", "Misc", "Debug" };
2223

2324
protected virtual void OnEnable()
2425
{
25-
initializeOnAwakeProp = FindProp("InitializeOnAwake");
26-
showDebugLogsProp = FindProp("ShowDebugLogs");
27-
autoConnectLastWalletProp = FindProp("AutoConnectLastWallet");
28-
redirectPageHtmlOverrideProp = FindProp("RedirectPageHtmlOverride");
29-
rpcOverridesProp = FindProp("RpcOverrides");
26+
this.InitializeOnAwakeProp = this.FindProp("InitializeOnAwake");
27+
this.ShowDebugLogsProp = this.FindProp("ShowDebugLogs");
28+
this.AutoConnectLastWalletProp = this.FindProp("AutoConnectLastWallet");
29+
this.RedirectPageHtmlOverrideProp = this.FindProp("RedirectPageHtmlOverride");
30+
this.RpcOverridesProp = this.FindProp("RpcOverrides");
3031

31-
bannerImage = Resources.Load<Texture2D>("EditorBanner");
32+
this.BannerImage = Resources.Load<Texture2D>("EditorBanner");
3233
}
3334

3435
public override void OnInspectorGUI()
3536
{
36-
serializedObject.Update();
37+
this.serializedObject.Update();
3738

38-
if (buttonStyle == null)
39+
if (this.ButtonStyle == null)
3940
{
40-
InitializeStyles();
41+
this.InitializeStyles();
4142
}
4243

43-
DrawBannerAndTitle();
44-
DrawTabs();
44+
this.DrawBannerAndTitle();
45+
this.DrawTabs();
4546
GUILayout.Space(10);
46-
DrawSelectedTabContent();
47+
this.DrawSelectedTabContent();
4748

48-
serializedObject.ApplyModifiedProperties();
49+
_ = this.serializedObject.ApplyModifiedProperties();
4950
}
5051

5152
protected virtual void DrawSelectedTabContent()
5253
{
53-
switch (selectedTab)
54+
switch (this.SelectedTab)
5455
{
5556
case 0:
56-
DrawClientOrServerTab();
57+
this.DrawClientOrServerTab();
5758
break;
5859
case 1:
59-
DrawPreferencesTab();
60+
this.DrawPreferencesTab();
6061
break;
6162
case 2:
62-
DrawMiscTab();
63+
this.DrawMiscTab();
6364
break;
6465
case 3:
65-
DrawDebugTab();
66+
this.DrawDebugTab();
6667
break;
6768
default:
6869
GUILayout.Label("Unknown Tab", EditorStyles.boldLabel);
@@ -75,55 +76,92 @@ protected virtual void DrawSelectedTabContent()
7576
protected virtual void DrawPreferencesTab()
7677
{
7778
EditorGUILayout.HelpBox("Set your preferences and initialization options here.", MessageType.Info);
78-
DrawProperty(initializeOnAwakeProp, "Initialize On Awake");
79-
DrawProperty(showDebugLogsProp, "Show Debug Logs");
80-
DrawProperty(autoConnectLastWalletProp, "Auto-Connect Last Wallet");
79+
this.DrawProperty(this.InitializeOnAwakeProp, "Initialize On Awake");
80+
this.DrawProperty(this.ShowDebugLogsProp, "Show Debug Logs");
81+
this.DrawProperty(this.AutoConnectLastWalletProp, "Auto-Connect Last Wallet");
8182
}
8283

8384
protected virtual void DrawMiscTab()
8485
{
8586
EditorGUILayout.HelpBox("Configure other settings here.", MessageType.Info);
86-
DrawProperty(rpcOverridesProp, "RPC Overrides");
87+
this.DrawProperty(this.RpcOverridesProp, "RPC Overrides");
8788
GUILayout.Space(10);
8889
EditorGUILayout.LabelField("OAuth Redirect Page HTML Override", EditorStyles.boldLabel);
89-
redirectPageHtmlOverrideProp.stringValue = EditorGUILayout.TextArea(redirectPageHtmlOverrideProp.stringValue, GUILayout.MinHeight(150));
90+
this.RedirectPageHtmlOverrideProp.stringValue = EditorGUILayout.TextArea(this.RedirectPageHtmlOverrideProp.stringValue, GUILayout.MinHeight(150));
9091
}
9192

9293
protected virtual void DrawDebugTab()
9394
{
9495
EditorGUILayout.HelpBox("Debug your settings here.", MessageType.Info);
95-
DrawButton(
96+
this.DrawButton(
9697
"Log Active Wallet Info",
9798
() =>
9899
{
99-
if (Application.isPlaying)
100+
if (!Application.isPlaying)
100101
{
101-
var mgr = target as T;
102-
var method = mgr.GetType().GetMethod("GetActiveWallet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
103-
if (method != null)
102+
Debug.LogWarning("Debugging can only be done in Play Mode.");
103+
return;
104+
}
105+
106+
if (this.target is ThirdwebManagerBase manager)
107+
{
108+
var wallet = manager.ActiveWallet;
109+
if (wallet != null)
104110
{
105-
var wallet = method.Invoke(mgr, null) as IThirdwebWallet;
106-
if (wallet != null)
107-
{
108-
Debug.Log($"Active Wallet ({wallet.GetType().Name}) Address: {wallet.GetAddress().Result}");
109-
}
110-
else
111-
{
112-
Debug.LogWarning("No active wallet found.");
113-
}
111+
Debug.Log($"Active Wallet ({wallet.GetType().Name}) Address: {wallet.GetAddress().Result}");
114112
}
115113
else
116114
{
117-
Debug.LogWarning("GetActiveWallet() not found.");
115+
Debug.LogWarning("No active wallet found.");
118116
}
119117
}
120118
else
119+
{
120+
Debug.LogWarning("Active wallet information unavailable for this target.");
121+
}
122+
}
123+
);
124+
this.DrawButton(
125+
"Disconnect Active Wallet",
126+
() =>
127+
{
128+
if (!Application.isPlaying)
121129
{
122130
Debug.LogWarning("Debugging can only be done in Play Mode.");
131+
return;
132+
}
133+
134+
if (this.target is ThirdwebManagerBase manager)
135+
{
136+
var wallet = manager.ActiveWallet;
137+
if (wallet != null)
138+
{
139+
EditorApplication.delayCall += async () =>
140+
{
141+
try
142+
{
143+
await wallet.Disconnect();
144+
manager.ActiveWallet = null;
145+
Debug.Log("Active wallet disconnected.");
146+
}
147+
catch (Exception ex)
148+
{
149+
Debug.LogError($"Failed to disconnect active wallet: {ex.Message}");
150+
}
151+
};
152+
}
153+
else
154+
{
155+
Debug.LogWarning("No active wallet to disconnect.");
156+
}
157+
}
158+
else
159+
{
160+
Debug.LogWarning("Active wallet information unavailable for this target.");
123161
}
124162
}
125163
);
126-
DrawButton(
164+
this.DrawButton(
127165
"Open Documentation",
128166
() =>
129167
{
@@ -137,9 +175,9 @@ protected void DrawBannerAndTitle()
137175
GUILayout.BeginVertical();
138176
GUILayout.Space(10);
139177
GUILayout.BeginHorizontal();
140-
if (bannerImage != null)
178+
if (this.BannerImage != null)
141179
{
142-
GUILayout.Label(bannerImage, GUILayout.Width(64), GUILayout.Height(64));
180+
GUILayout.Label(this.BannerImage, GUILayout.Width(64), GUILayout.Height(64));
143181
}
144182
GUILayout.Space(10);
145183
GUILayout.BeginVertical();
@@ -154,12 +192,12 @@ protected void DrawBannerAndTitle()
154192

155193
protected void DrawTabs()
156194
{
157-
selectedTab = GUILayout.Toolbar(selectedTab, TabTitles, GUILayout.Height(25));
195+
this.SelectedTab = GUILayout.Toolbar(this.SelectedTab, this.TabTitles, GUILayout.Height(25));
158196
}
159197

160198
protected void InitializeStyles()
161199
{
162-
buttonStyle = new GUIStyle(GUI.skin.button)
200+
this.ButtonStyle = new GUIStyle(GUI.skin.button)
163201
{
164202
fontStyle = FontStyle.Bold,
165203
alignment = TextAnchor.MiddleLeft,
@@ -171,18 +209,18 @@ protected void DrawProperty(SerializedProperty property, string label)
171209
{
172210
if (property != null)
173211
{
174-
EditorGUILayout.PropertyField(property, new GUIContent(label));
212+
_ = EditorGUILayout.PropertyField(property, new GUIContent(label));
175213
}
176214
else
177215
{
178216
EditorGUILayout.HelpBox($"Property '{label}' not found.", MessageType.Error);
179217
}
180218
}
181219

182-
protected void DrawButton(string label, System.Action action)
220+
protected void DrawButton(string label, Action action)
183221
{
184222
GUILayout.FlexibleSpace();
185-
if (GUILayout.Button(label, buttonStyle, GUILayout.Height(35), GUILayout.ExpandWidth(true)))
223+
if (GUILayout.Button(label, this.ButtonStyle, GUILayout.Height(35), GUILayout.ExpandWidth(true)))
186224
{
187225
action.Invoke();
188226
}
@@ -191,36 +229,39 @@ protected void DrawButton(string label, System.Action action)
191229

192230
protected SerializedProperty FindProp(string propName)
193231
{
194-
var targetType = target.GetType();
232+
var targetType = this.target.GetType();
195233
var property = targetType.GetProperty(propName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
196234
if (property == null)
235+
{
197236
return null;
237+
}
238+
198239
var backingFieldName = $"<{propName}>k__BackingField";
199-
return serializedObject.FindProperty(backingFieldName);
240+
return this.serializedObject.FindProperty(backingFieldName);
200241
}
201242
}
202243

203244
[CustomEditor(typeof(ThirdwebManager))]
204245
public class ThirdwebManagerEditor : ThirdwebManagerBaseEditor<ThirdwebManager>
205246
{
206-
SerializedProperty clientIdProp;
207-
SerializedProperty bundleIdProp;
247+
private SerializedProperty _clientIdProp;
248+
private SerializedProperty _bundleIdProp;
208249

209250
protected override void OnEnable()
210251
{
211252
base.OnEnable();
212-
clientIdProp = FindProp("ClientId");
213-
bundleIdProp = FindProp("BundleId");
253+
this._clientIdProp = this.FindProp("ClientId");
254+
this._bundleIdProp = this.FindProp("BundleId");
214255
}
215256

216257
protected override string[] TabTitles => new string[] { "Client", "Preferences", "Misc", "Debug" };
217258

218259
protected override void DrawClientOrServerTab()
219260
{
220261
EditorGUILayout.HelpBox("Configure your client settings here.", MessageType.Info);
221-
DrawProperty(clientIdProp, "Client ID");
222-
DrawProperty(bundleIdProp, "Bundle ID");
223-
DrawButton(
262+
this.DrawProperty(this._clientIdProp, "Client ID");
263+
this.DrawProperty(this._bundleIdProp, "Bundle ID");
264+
this.DrawButton(
224265
"Create API Key",
225266
() =>
226267
{
@@ -233,21 +274,21 @@ protected override void DrawClientOrServerTab()
233274
[CustomEditor(typeof(ThirdwebManagerServer))]
234275
public class ThirdwebManagerServerEditor : ThirdwebManagerBaseEditor<ThirdwebManagerServer>
235276
{
236-
SerializedProperty secretKeyProp;
277+
private SerializedProperty _secretKeyProp;
237278

238279
protected override void OnEnable()
239280
{
240281
base.OnEnable();
241-
secretKeyProp = FindProp("SecretKey");
282+
this._secretKeyProp = this.FindProp("SecretKey");
242283
}
243284

244285
protected override string[] TabTitles => new string[] { "Client", "Preferences", "Misc", "Debug" };
245286

246287
protected override void DrawClientOrServerTab()
247288
{
248289
EditorGUILayout.HelpBox("Configure your client settings here.", MessageType.Info);
249-
DrawProperty(secretKeyProp, "Secret Key");
250-
DrawButton(
290+
this.DrawProperty(this._secretKeyProp, "Secret Key");
291+
this.DrawButton(
251292
"Create API Key",
252293
() =>
253294
{

Assets/Thirdweb/Examples/Scenes/Scene_Playground.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ MonoBehaviour:
19541954
m_Script: {fileID: 11500000, guid: f139d8153587c1d46aaf3b6bf05d2c25, type: 3}
19551955
m_Name:
19561956
m_EditorClassIdentifier: Thirdweb.Examples::ThirdwebPlayground
1957-
AlwaysUpgradeToSmartWallet: 1
1957+
AlwaysUpgradeToSmartWallet: 0
19581958
ChainId: 421614
19591959
Email:
19601960
Phone:

Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ string[] excludedWalletIds
3838

3939
var wallet = new ReownWallet();
4040

41-
var wcChains = new List<Chain>(); // ChainConstants.Chains.All.ToList();
41+
var wcChains = ChainConstants.Chains.All.ToList();
4242

4343
if (wcChains.Any(c => c.ChainReference == activeChainId.ToString()))
4444
{

0 commit comments

Comments
 (0)