Skip to content

Commit 557c132

Browse files
Update MetaMask SDK to 1.2.2 (#142)
Co-authored-by: 0xFirekeeper <0xFirekeeper@gmail.com>
1 parent bc786ee commit 557c132

File tree

211 files changed

+21138
-9542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+21138
-9542
lines changed

Assets/Thirdweb/Core/Prefabs/WalletProvider_Metamask.prefab

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ RectTransform:
3131
m_ConstrainProportionsScale: 0
3232
m_Children: []
3333
m_Father: {fileID: 2438333664808875362}
34-
m_RootOrder: 1
3534
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3635
m_AnchorMin: {x: 0.5, y: 0.5}
3736
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -107,7 +106,6 @@ RectTransform:
107106
m_ConstrainProportionsScale: 0
108107
m_Children: []
109108
m_Father: {fileID: 2438333664808875362}
110-
m_RootOrder: 2
111109
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
112110
m_AnchorMin: {x: 0.5, y: 0.5}
113111
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -185,7 +183,6 @@ RectTransform:
185183
- {fileID: 5780280198508624836}
186184
- {fileID: 3246246231219207936}
187185
m_Father: {fileID: 2438333664808875362}
188-
m_RootOrder: 5
189186
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
190187
m_AnchorMin: {x: 0, y: 0}
191188
m_AnchorMax: {x: 1, y: 1}
@@ -259,14 +256,14 @@ Transform:
259256
m_PrefabInstance: {fileID: 0}
260257
m_PrefabAsset: {fileID: 0}
261258
m_GameObject: {fileID: 3503421935870801903}
259+
serializedVersion: 2
262260
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
263261
m_LocalPosition: {x: 0, y: 0, z: 0}
264262
m_LocalScale: {x: 1, y: 1, z: 1}
265263
m_ConstrainProportionsScale: 0
266264
m_Children:
267265
- {fileID: 2438333664808875362}
268266
m_Father: {fileID: 0}
269-
m_RootOrder: 0
270267
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
271268
--- !u!114 &228276015862408994
272269
MonoBehaviour:
@@ -285,6 +282,7 @@ MonoBehaviour:
285282
DeepLinkButton: {fileID: 4160231591218546103}
286283
OTPPanel: {fileID: 1978744874944535028}
287284
OTPText: {fileID: 9175537191550043107}
285+
OTPHeaderText: {fileID: 6388212339867805453}
288286
--- !u!114 &3873553887018070327
289287
MonoBehaviour:
290288
m_ObjectHideFlags: 0
@@ -322,8 +320,9 @@ MonoBehaviour:
322320
m_Name:
323321
m_EditorClassIdentifier:
324322
config: {fileID: 11400000, guid: 6cbb8289bcfbdba43817188b3b4f15e0, type: 2}
325-
initializeOnAwake: 1
323+
initializeOnAwake: 0
326324
_transport: {fileID: 11400000, guid: 2794b8de755b55048bc6f0544321e072, type: 2}
325+
InfuraProjectId:
327326
RpcUrl: []
328327
clearSessionData: 0
329328
--- !u!114 &4671479922431115845
@@ -383,7 +382,6 @@ RectTransform:
383382
m_ConstrainProportionsScale: 0
384383
m_Children: []
385384
m_Father: {fileID: 6025360505761643383}
386-
m_RootOrder: 0
387385
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
388386
m_AnchorMin: {x: 0, y: 0}
389387
m_AnchorMax: {x: 1, y: 1}
@@ -518,7 +516,6 @@ RectTransform:
518516
m_ConstrainProportionsScale: 0
519517
m_Children: []
520518
m_Father: {fileID: 4654996450284410679}
521-
m_RootOrder: 0
522519
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
523520
m_AnchorMin: {x: 0.5, y: 0.5}
524521
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -656,7 +653,6 @@ RectTransform:
656653
m_Children:
657654
- {fileID: 1016137851376285130}
658655
m_Father: {fileID: 2438333664808875362}
659-
m_RootOrder: 4
660656
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
661657
m_AnchorMin: {x: 0.5, y: 0.5}
662658
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -788,7 +784,6 @@ RectTransform:
788784
m_ConstrainProportionsScale: 0
789785
m_Children: []
790786
m_Father: {fileID: 2438333664808875362}
791-
m_RootOrder: 0
792787
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
793788
m_AnchorMin: {x: 0, y: 0}
794789
m_AnchorMax: {x: 1, y: 1}
@@ -871,7 +866,6 @@ RectTransform:
871866
- {fileID: 2932539567639123612}
872867
- {fileID: 4654996450284410679}
873868
m_Father: {fileID: 3503421935870801902}
874-
m_RootOrder: 0
875869
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
876870
m_AnchorMin: {x: 0, y: 0}
877871
m_AnchorMax: {x: 0, y: 0}
@@ -895,7 +889,9 @@ Canvas:
895889
m_OverrideSorting: 0
896890
m_OverridePixelPerfect: 0
897891
m_SortingBucketNormalizedSize: 0
892+
m_VertexColorAlwaysGammaSpace: 0
898893
m_AdditionalShaderChannelsFlag: 25
894+
m_UpdateRectTransformForStandalone: 0
899895
m_SortingLayerID: 0
900896
m_SortingOrder: 1
901897
m_TargetDisplay: 0
@@ -970,7 +966,6 @@ RectTransform:
970966
m_ConstrainProportionsScale: 0
971967
m_Children: []
972968
m_Father: {fileID: 2932539567639123612}
973-
m_RootOrder: 0
974969
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
975970
m_AnchorMin: {x: 0, y: 0}
976971
m_AnchorMax: {x: 1, y: 1}
@@ -1105,7 +1100,6 @@ RectTransform:
11051100
m_ConstrainProportionsScale: 0
11061101
m_Children: []
11071102
m_Father: {fileID: 4654996450284410679}
1108-
m_RootOrder: 1
11091103
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
11101104
m_AnchorMin: {x: 0.5, y: 0.5}
11111105
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1242,7 +1236,6 @@ RectTransform:
12421236
m_Children:
12431237
- {fileID: 5381113169963213877}
12441238
m_Father: {fileID: 2438333664808875362}
1245-
m_RootOrder: 3
12461239
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
12471240
m_AnchorMin: {x: 0.5, y: 0.5}
12481241
m_AnchorMax: {x: 0.5, y: 0.5}

Assets/Thirdweb/Core/Scripts/Wallets/ThirdwebMetamask.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Numerics;
22
using System.Threading.Tasks;
3+
using MetaMask;
34
using MetaMask.NEthereum;
45
using MetaMask.Unity;
56
using Nethereum.Web3;
@@ -11,6 +12,25 @@ namespace Thirdweb.Wallets
1112
{
1213
public class ThirdwebMetamask : IThirdwebWallet
1314
{
15+
public class MetaMaskThirdwebConfig : MetaMaskConfig
16+
{
17+
public void SetDefaults(MetaMaskConfig defaults)
18+
{
19+
this.encrypt = defaults.Encrypt;
20+
this.log = defaults.Log;
21+
this.encryptionPassword = defaults.EncryptionPassword;
22+
this.userAgent = defaults.UserAgent;
23+
this.sessionIdentifier = defaults.SessionIdentifier;
24+
this.socketUrl = defaults.SocketUrl;
25+
}
26+
27+
public void UpdateConfig(string appName, string appUrl)
28+
{
29+
this.appName = appName;
30+
this.appUrl = appUrl;
31+
}
32+
}
33+
1434
private Web3 _web3;
1535
private readonly WalletProvider _provider;
1636
private readonly WalletProvider _signerProvider;
@@ -28,12 +48,27 @@ public async Task<string> Connect(WalletConnection walletConnection, string rpc)
2848
{
2949
GameObject.Instantiate(ThirdwebManager.Instance.MetamaskPrefab);
3050
await new WaitForSeconds(1f);
51+
SetupMetaMask();
3152
}
3253
await MetamaskUI.Instance.Connect();
3354
_web3 = MetaMaskUnity.Instance.CreateWeb3();
3455
return await GetAddress();
3556
}
3657

58+
private void SetupMetaMask()
59+
{
60+
var config = ScriptableObject.CreateInstance<MetaMaskThirdwebConfig>();
61+
var defaults = MetaMaskConfig.DefaultInstance;
62+
63+
config.SetDefaults(defaults);
64+
65+
var appName = ThirdwebManager.Instance.SDK.session.Options.wallet?.appName;
66+
var appUrl = ThirdwebManager.Instance.SDK.session.Options.wallet?.appUrl;
67+
config.UpdateConfig(appName, appUrl);
68+
69+
MetaMaskUnity.Instance.Initialize(config);
70+
}
71+
3772
public Task Disconnect()
3873
{
3974
MetaMaskUnity.Instance.Disconnect(true);

Assets/Thirdweb/Core/Scripts/WalletsUI/MetamaskUI.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class MetamaskUI : MonoBehaviour, IMetaMaskUnityTransportListener
1919
public Button DeepLinkButton;
2020
public GameObject OTPPanel;
2121
public TMP_Text OTPText;
22+
public TMP_Text OTPHeaderText;
2223

2324
public static MetamaskUI Instance;
2425

@@ -150,7 +151,20 @@ public void OnMetaMaskSuccess()
150151
public void OnMetaMaskOTP(int otp)
151152
{
152153
OTPPanel.SetActive(true);
153-
OTPText.text = otp.ToString();
154+
155+
var shouldShowOtpCode = DateTime.Now - MetaMaskUnity.Instance.Wallet.LastActive >= TimeSpan.FromHours(1);
156+
157+
// They simply need to press resume in the app
158+
OTPText.gameObject.SetActive(shouldShowOtpCode);
159+
160+
if (shouldShowOtpCode)
161+
{
162+
OTPText.text = otp.ToString();
163+
}
164+
else
165+
{
166+
OTPHeaderText.text = "Open the MetaMask app to continue with your session.";
167+
}
154168
}
155169

156170
public void OnMetaMaskDisconnected()

0 commit comments

Comments
 (0)