16
16
using UnityEngine ;
17
17
using UnityEngine . SceneManagement ;
18
18
using UnityEngine . Serialization ;
19
+ using Thirdweb ;
19
20
20
21
namespace MetaMask . Unity
21
22
{
22
23
[ RequireComponent ( typeof ( MetaMaskUnityEventHandler ) ) ]
23
24
[ RequireComponent ( typeof ( MetaMaskHttpService ) ) ]
24
25
public class MetaMaskUnity : MonoBehaviour , IMetaMaskEvents
25
26
{
26
-
27
27
#region Classes
28
28
29
29
[ Serializable ]
@@ -42,30 +42,37 @@ public class MetaMaskUnityRpcUrlConfig
42
42
/// <summary>The configuration for the MetaMask client.</summary>
43
43
[ SerializeField ]
44
44
protected MetaMaskConfig config ;
45
+
45
46
/// <summary>Whether or not to initialize the wallet on awake.</summary>
46
47
/// <remarks>This is useful for testing.</remarks>
47
- [ FormerlySerializedAs ( "initializeOnStart" ) ] [ SerializeField ]
48
+ [ FormerlySerializedAs ( "initializeOnStart" ) ]
49
+ [ SerializeField ]
48
50
protected bool initializeOnAwake = true ;
49
51
50
52
[ SerializeField ]
51
53
protected MetaMaskUnityScriptableObjectTransport _transport ;
52
54
53
-
54
55
/// <summary>Initializes the MetaMask Wallet Plugin.</summary>
55
56
protected bool initialized = false ;
56
57
57
58
/// <param name="transport">The transport to use for communication with the MetaMask backend.</param>
58
59
protected IMetaMaskTransport transport ;
60
+
59
61
/// <param name="socket">The socket wrapper to use for communication with the MetaMask backend.</param>
60
62
protected IMetaMaskSocketWrapper socket ;
63
+
61
64
/// <param name="dataManager">The data manager to use for storing data.</param>
62
65
protected MetaMaskDataManager dataManager ;
66
+
63
67
/// <param name="session">The session to use for storing data.</param>
64
68
protected MetaMaskSession session ;
69
+
65
70
/// <param name="sessionData">The session data to use for storing data.</param>
66
71
protected MetaMaskSessionData sessionData ;
72
+
67
73
/// <param name="wallet">The wallet to use for storing data.</param>
68
74
protected MetaMaskWallet wallet ;
75
+
69
76
/// <summary>
70
77
/// The RPC URL to use for web3 query requests when the MetaMask wallet is paused
71
78
/// </summary>
@@ -74,7 +81,7 @@ public class MetaMaskUnityRpcUrlConfig
74
81
internal Thread unityThread ;
75
82
76
83
#endregion
77
-
84
+
78
85
#region Events
79
86
80
87
[ Inject ]
@@ -164,7 +171,6 @@ protected void Awake()
164
171
}
165
172
}
166
173
167
-
168
174
/// <summary>Saves the current session.</summary>
169
175
protected void OnApplicationQuit ( )
170
176
{
@@ -220,18 +226,17 @@ public void Initialize(MetaMaskConfig config, IMetaMaskTransport transport, IMet
220
226
221
227
this . transport = transport ;
222
228
this . socket = socket ;
223
-
229
+
224
230
// Inject variables
225
231
UnityBinder . Inject ( this ) ;
226
232
227
233
// Validate config
228
234
if ( Config . AppName == "example" || Config . AppUrl == "example.com" )
229
235
{
230
236
if ( SceneManager . GetActiveScene ( ) . name . ToLower ( ) != "metamask main (sample)" )
231
- throw new ArgumentException (
232
- "Cannot use example App name or App URL, please update app info in Window > MetaMask > Setup Window under Credentials" ) ;
237
+ throw new ArgumentException ( "Cannot use example App name or App URL, please update app info in Window > MetaMask > Setup Window under Credentials" ) ;
233
238
}
234
-
239
+
235
240
try
236
241
{
237
242
// Check if we need to create a WebsocketDispatcher
@@ -241,49 +246,44 @@ public void Initialize(MetaMaskConfig config, IMetaMaskTransport transport, IMet
241
246
MetaMaskDebug . Log ( "No WebSocketDispatcher found in scene, creating one on " + gameObject . name ) ;
242
247
gameObject . AddComponent < WebSocketDispatcher > ( ) ;
243
248
}
244
-
249
+
245
250
this . unityThread = Thread . CurrentThread ;
246
-
251
+
247
252
// Configure persistent data manager
248
253
this . dataManager = new MetaMaskDataManager ( MetaMaskUnityStorage . Instance , this . config . Encrypt , this . config . EncryptionPassword ) ;
249
-
254
+
250
255
// Grab app name, app url and session id
251
- var appName = Config . AppName ;
252
- var appUrl = Config . AppUrl ;
256
+ var appName = ThirdwebManager . Instance . SDK . session . Options . wallet ? . appName ;
257
+ var appUrl = ThirdwebManager . Instance . SDK . session . Options . wallet ? . appUrl ;
253
258
var sessionId = this . config . SessionIdentifier ;
254
259
255
260
// Setup the wallet
256
- this . wallet = new MetaMaskWallet ( this . dataManager ,
257
- appName , appUrl , sessionId , UnityEciesProvider . Singleton ,
258
- transport , socket , this . config . SocketUrl ) ;
259
-
261
+ this . wallet = new MetaMaskWallet ( this . dataManager , appName , appUrl , sessionId , UnityEciesProvider . Singleton , transport , socket , this . config . SocketUrl ) ;
262
+
260
263
// Grab session data
261
264
this . session = this . wallet . Session ;
262
265
this . sessionData = this . wallet . Session . Data ;
263
-
266
+
264
267
this . wallet . AnalyticsPlatform = "unity" ;
265
-
268
+
266
269
// Setup the fallback provider, if set
267
270
if ( RpcUrl != null && RpcUrl . Count > 0 )
268
271
{
269
- var rpcUrlMap = RpcUrl . ToDictionary (
270
- c => c . ChainId ,
271
- c => c . RpcUrl
272
- ) ;
273
-
272
+ var rpcUrlMap = RpcUrl . ToDictionary ( c => c . ChainId , c => c . RpcUrl ) ;
273
+
274
274
this . wallet . FallbackProvider = new HttpProvider ( rpcUrlMap , this . wallet ) ;
275
275
}
276
276
277
277
if ( this . MetaMaskUnityBeforeInitialized != null )
278
278
this . MetaMaskUnityBeforeInitialized ( this , EventArgs . Empty ) ;
279
-
279
+
280
280
_eventHandler . SetupEvents ( ) ;
281
-
281
+
282
282
// Initialize the transport
283
283
transport . Initialize ( ) ;
284
284
285
285
this . initialized = true ;
286
-
286
+
287
287
if ( this . MetaMaskUnityInitialized != null )
288
288
this . MetaMaskUnityInitialized ( this , EventArgs . Empty ) ;
289
289
}
@@ -309,11 +309,11 @@ public void Disconnect(bool endSession = false)
309
309
{
310
310
if ( this . wallet . IsConnected )
311
311
this . wallet . Disconnect ( ) ;
312
-
312
+
313
313
if ( endSession )
314
314
EndSession ( ) ;
315
315
}
316
-
316
+
317
317
public void EndSession ( )
318
318
{
319
319
this . wallet . EndSession ( ) ;
@@ -335,7 +335,7 @@ internal void ForceClearSession()
335
335
{
336
336
if ( this . dataManager == null )
337
337
this . dataManager = new MetaMaskDataManager ( MetaMaskUnityStorage . Instance , this . config . Encrypt , this . config . EncryptionPassword ) ;
338
-
338
+
339
339
this . dataManager . Delete ( this . config . SessionIdentifier ) ;
340
340
}
341
341
}
@@ -378,6 +378,5 @@ protected void Release()
378
378
}
379
379
380
380
#endregion
381
-
382
381
}
383
- }
382
+ }
0 commit comments