@@ -23,11 +23,10 @@ public class WalletConnect : IWalletConnect
2323 public static IWalletConnect Instance { get ; } = LazyInstance . Value ;
2424
2525 public static SynchronizationContext UnitySyncContext { get ; private set ; }
26-
26+
2727 public ISignClient SignClient { get ; private set ; }
2828
2929 public Linker Linker { get ; private set ; }
30-
3130
3231 public SessionStruct ActiveSession => SignClient . AddressProvider . DefaultSession ;
3332
@@ -40,7 +39,7 @@ public class WalletConnect : IWalletConnect
4039 [ Obsolete ( "Use SessionConnected or SessionUpdated instead" ) ]
4140 public event EventHandler < SessionStruct > ActiveSessionChanged ;
4241 public event EventHandler < SessionStruct > SessionConnected ;
43- public event EventHandler < SessionStruct > SessionUpdated ;
42+ public event EventHandler < SessionStruct > SessionUpdated ;
4443 public event EventHandler SessionDisconnected ;
4544
4645 private SessionStruct _activeSession ;
@@ -57,37 +56,40 @@ public async Task<IWalletConnect> InitializeAsync()
5756 Debug . LogError ( "[WalletConnectUnity] Already initialized" ) ;
5857 return this ;
5958 }
60-
59+
6160 var currentSyncContext = SynchronizationContext . Current ;
6261 if ( currentSyncContext . GetType ( ) . FullName != "UnityEngine.UnitySynchronizationContext" )
6362 throw new Exception (
64- $ "[WalletConnectUnity] SynchronizationContext is not of type UnityEngine.UnitySynchronizationContext. Current type is <i>{ currentSyncContext . GetType ( ) . FullName } </i>. Make sure to initialize WalletConnect from the main thread.") ;
63+ $ "[WalletConnectUnity] SynchronizationContext is not of type UnityEngine.UnitySynchronizationContext. Current type is <i>{ currentSyncContext . GetType ( ) . FullName } </i>. Make sure to initialize WalletConnect from the main thread."
64+ ) ;
6565 UnitySyncContext = currentSyncContext ;
66-
66+
6767 var projectConfig = ProjectConfiguration . Load ( ) ;
6868
69- Assert . IsNotNull ( projectConfig ,
70- $ "Project configuration not found. Expected to find it at <i>{ ProjectConfiguration . ConfigPath } </i>") ;
71- Assert . IsFalse ( string . IsNullOrWhiteSpace ( projectConfig . Id ) ,
72- $ "Project ID is not set in the project configuration asset ( <i> { ProjectConfiguration . ConfigPath } </i> )." ) ;
73- Assert . IsFalse ( projectConfig . Metadata == null || string . IsNullOrWhiteSpace ( projectConfig . Metadata . Name ) ,
74- $ "Project name is not set in the project configuration asset ( <i> { ProjectConfiguration . ConfigPath } </i> )." ) ;
69+ Assert . IsNotNull ( projectConfig , $ "Project configuration not found. Expected to find it at <i> { ProjectConfiguration . ConfigPath } </i>" ) ;
70+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( projectConfig . Id ) , $ "Project ID is not set in the project configuration asset ( <i>{ ProjectConfiguration . ConfigPath } </i> ). ") ;
71+ Assert . IsFalse (
72+ projectConfig . Metadata == null || string . IsNullOrWhiteSpace ( projectConfig . Metadata . Name ) ,
73+ $ "Project name is not set in the project configuration asset ( <i> { ProjectConfiguration . ConfigPath } </i> )."
74+ ) ;
7575
7676 if ( projectConfig . LoggingEnabled )
7777 WCLogger . Logger = new Logger ( ) ;
7878
7979 var storage = await BuildStorage ( ) ;
8080
81- SignClient = await WalletConnectSignClient . Init ( new SignClientOptions
82- {
83- Metadata = projectConfig . Metadata ,
84- Name = projectConfig . Metadata . Name ,
85- ProjectId = projectConfig . Id ,
86- Storage = storage ,
87- RelayUrlBuilder = new UnityRelayUrlBuilder ( ) ,
88- ConnectionBuilder = new NativeWebSocketConnectionBuilder ( )
89- } ) ;
90-
81+ SignClient = await WalletConnectSignClient . Init (
82+ new SignClientOptions
83+ {
84+ Metadata = projectConfig . Metadata ,
85+ Name = projectConfig . Metadata . Name ,
86+ ProjectId = projectConfig . Id ,
87+ Storage = storage ,
88+ RelayUrlBuilder = new UnityRelayUrlBuilder ( ) ,
89+ ConnectionBuilder = new NativeWebSocketConnectionBuilder ( )
90+ }
91+ ) ;
92+
9193 SignClient . SessionConnected += OnSessionConnected ;
9294 SignClient . SessionUpdated += OnSessionUpdated ;
9395 SignClient . SessionDeleted += OnSessionDeleted ;
@@ -114,11 +116,11 @@ public async Task<bool> TryResumeSessionAsync()
114116
115117 if ( string . IsNullOrWhiteSpace ( session . Topic ) )
116118 return false ;
117-
119+
118120 SignClient . AddressProvider . DefaultSession = session ;
119121
120122 await SignClient . Extend ( session . Topic ) ;
121-
123+
122124 return true ;
123125 }
124126
@@ -148,30 +150,39 @@ public Task DisconnectAsync()
148150
149151 private void OnSessionConnected ( object sender , SessionStruct session )
150152 {
151- UnitySyncContext . Post ( _ =>
152- {
153- SessionConnected ? . Invoke ( this , session ) ;
154- ActiveSessionChanged ? . Invoke ( this , session ) ;
155- } , null ) ;
153+ UnitySyncContext . Post (
154+ _ =>
155+ {
156+ SessionConnected ? . Invoke ( this , session ) ;
157+ ActiveSessionChanged ? . Invoke ( this , session ) ;
158+ } ,
159+ null
160+ ) ;
156161 }
157162
158163 private void OnSessionUpdated ( object sender , SessionEvent sessionEvent )
159164 {
160165 var sessionStruct = SignClient . Session . Values . First ( s => s . Topic == sessionEvent . Topic ) ;
161- UnitySyncContext . Post ( _ =>
162- {
163- SessionUpdated ? . Invoke ( this , sessionStruct ) ;
164- ActiveSessionChanged ? . Invoke ( this , sessionStruct ) ;
165- } , null ) ;
166+ UnitySyncContext . Post (
167+ _ =>
168+ {
169+ SessionUpdated ? . Invoke ( this , sessionStruct ) ;
170+ ActiveSessionChanged ? . Invoke ( this , sessionStruct ) ;
171+ } ,
172+ null
173+ ) ;
166174 }
167175
168176 private void OnSessionDeleted ( object sender , SessionEvent _ )
169177 {
170- UnitySyncContext . Post ( _ =>
171- {
172- SessionDisconnected ? . Invoke ( this , EventArgs . Empty ) ;
173- ActiveSessionChanged ? . Invoke ( this , default ) ;
174- } , null ) ;
178+ UnitySyncContext . Post (
179+ _ =>
180+ {
181+ SessionDisconnected ? . Invoke ( this , EventArgs . Empty ) ;
182+ ActiveSessionChanged ? . Invoke ( this , default ) ;
183+ } ,
184+ null
185+ ) ;
175186 }
176187
177188 private static async Task < IKeyValueStorage > BuildStorage ( )
@@ -186,13 +197,13 @@ private static async Task<IKeyValueStorage> BuildStorage()
186197 await playerPrefsStorage . Init ( ) ;
187198
188199 return playerPrefsStorage ;
189- #endif
200+ #else
190201
191202 var path = $ "{ Application . persistentDataPath } /WalletConnect/storage.json";
192203 WCLogger . Log ( $ "[WalletConnectUnity] Using storage path <i>{ path } </i>") ;
193-
204+
194205 var storage = new FileSystemStorage ( path ) ;
195-
206+
196207 try
197208 {
198209 await storage . Init ( ) ;
@@ -205,6 +216,7 @@ private static async Task<IKeyValueStorage> BuildStorage()
205216 }
206217
207218 return storage ;
219+ #endif
208220 }
209221
210222 private void ThrowIfNoActiveSession ( )
@@ -221,7 +233,8 @@ public void Dispose()
221233
222234 protected virtual void Dispose ( bool disposing )
223235 {
224- if ( disposed ) return ;
236+ if ( disposed )
237+ return ;
225238
226239 if ( disposing )
227240 {
@@ -234,4 +247,4 @@ protected virtual void Dispose(bool disposing)
234247 disposed = true ;
235248 }
236249 }
237- }
250+ }
0 commit comments