Skip to content

Commit 354dd67

Browse files
committed
Use dappMetadata with Metamask
1 parent f743388 commit 354dd67

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

Assets/Thirdweb/Plugins/MetaMask/Scripts/MetaMaskUnity.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
using UnityEngine;
1717
using UnityEngine.SceneManagement;
1818
using UnityEngine.Serialization;
19+
using Thirdweb;
1920

2021
namespace MetaMask.Unity
2122
{
2223
[RequireComponent(typeof(MetaMaskUnityEventHandler))]
2324
[RequireComponent(typeof(MetaMaskHttpService))]
2425
public class MetaMaskUnity : MonoBehaviour, IMetaMaskEvents
2526
{
26-
2727
#region Classes
2828

2929
[Serializable]
@@ -42,30 +42,37 @@ public class MetaMaskUnityRpcUrlConfig
4242
/// <summary>The configuration for the MetaMask client.</summary>
4343
[SerializeField]
4444
protected MetaMaskConfig config;
45+
4546
/// <summary>Whether or not to initialize the wallet on awake.</summary>
4647
/// <remarks>This is useful for testing.</remarks>
47-
[FormerlySerializedAs("initializeOnStart")] [SerializeField]
48+
[FormerlySerializedAs("initializeOnStart")]
49+
[SerializeField]
4850
protected bool initializeOnAwake = true;
4951

5052
[SerializeField]
5153
protected MetaMaskUnityScriptableObjectTransport _transport;
5254

53-
5455
/// <summary>Initializes the MetaMask Wallet Plugin.</summary>
5556
protected bool initialized = false;
5657

5758
/// <param name="transport">The transport to use for communication with the MetaMask backend.</param>
5859
protected IMetaMaskTransport transport;
60+
5961
/// <param name="socket">The socket wrapper to use for communication with the MetaMask backend.</param>
6062
protected IMetaMaskSocketWrapper socket;
63+
6164
/// <param name="dataManager">The data manager to use for storing data.</param>
6265
protected MetaMaskDataManager dataManager;
66+
6367
/// <param name="session">The session to use for storing data.</param>
6468
protected MetaMaskSession session;
69+
6570
/// <param name="sessionData">The session data to use for storing data.</param>
6671
protected MetaMaskSessionData sessionData;
72+
6773
/// <param name="wallet">The wallet to use for storing data.</param>
6874
protected MetaMaskWallet wallet;
75+
6976
/// <summary>
7077
/// The RPC URL to use for web3 query requests when the MetaMask wallet is paused
7178
/// </summary>
@@ -74,7 +81,7 @@ public class MetaMaskUnityRpcUrlConfig
7481
internal Thread unityThread;
7582

7683
#endregion
77-
84+
7885
#region Events
7986

8087
[Inject]
@@ -164,7 +171,6 @@ protected void Awake()
164171
}
165172
}
166173

167-
168174
/// <summary>Saves the current session.</summary>
169175
protected void OnApplicationQuit()
170176
{
@@ -220,18 +226,17 @@ public void Initialize(MetaMaskConfig config, IMetaMaskTransport transport, IMet
220226

221227
this.transport = transport;
222228
this.socket = socket;
223-
229+
224230
// Inject variables
225231
UnityBinder.Inject(this);
226232

227233
// Validate config
228234
if (Config.AppName == "example" || Config.AppUrl == "example.com")
229235
{
230236
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");
233238
}
234-
239+
235240
try
236241
{
237242
// Check if we need to create a WebsocketDispatcher
@@ -241,49 +246,44 @@ public void Initialize(MetaMaskConfig config, IMetaMaskTransport transport, IMet
241246
MetaMaskDebug.Log("No WebSocketDispatcher found in scene, creating one on " + gameObject.name);
242247
gameObject.AddComponent<WebSocketDispatcher>();
243248
}
244-
249+
245250
this.unityThread = Thread.CurrentThread;
246-
251+
247252
// Configure persistent data manager
248253
this.dataManager = new MetaMaskDataManager(MetaMaskUnityStorage.Instance, this.config.Encrypt, this.config.EncryptionPassword);
249-
254+
250255
// 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;
253258
var sessionId = this.config.SessionIdentifier;
254259

255260
// 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+
260263
// Grab session data
261264
this.session = this.wallet.Session;
262265
this.sessionData = this.wallet.Session.Data;
263-
266+
264267
this.wallet.AnalyticsPlatform = "unity";
265-
268+
266269
// Setup the fallback provider, if set
267270
if (RpcUrl != null && RpcUrl.Count > 0)
268271
{
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+
274274
this.wallet.FallbackProvider = new HttpProvider(rpcUrlMap, this.wallet);
275275
}
276276

277277
if (this.MetaMaskUnityBeforeInitialized != null)
278278
this.MetaMaskUnityBeforeInitialized(this, EventArgs.Empty);
279-
279+
280280
_eventHandler.SetupEvents();
281-
281+
282282
// Initialize the transport
283283
transport.Initialize();
284284

285285
this.initialized = true;
286-
286+
287287
if (this.MetaMaskUnityInitialized != null)
288288
this.MetaMaskUnityInitialized(this, EventArgs.Empty);
289289
}
@@ -309,11 +309,11 @@ public void Disconnect(bool endSession = false)
309309
{
310310
if (this.wallet.IsConnected)
311311
this.wallet.Disconnect();
312-
312+
313313
if (endSession)
314314
EndSession();
315315
}
316-
316+
317317
public void EndSession()
318318
{
319319
this.wallet.EndSession();
@@ -335,7 +335,7 @@ internal void ForceClearSession()
335335
{
336336
if (this.dataManager == null)
337337
this.dataManager = new MetaMaskDataManager(MetaMaskUnityStorage.Instance, this.config.Encrypt, this.config.EncryptionPassword);
338-
338+
339339
this.dataManager.Delete(this.config.SessionIdentifier);
340340
}
341341
}
@@ -378,6 +378,5 @@ protected void Release()
378378
}
379379

380380
#endregion
381-
382381
}
383-
}
382+
}

0 commit comments

Comments
 (0)