Skip to content

Commit dff75c9

Browse files
committed
Make WalletUI functions overrideable
1 parent 557c132 commit dff75c9

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private void Awake()
6161

6262
#region Connection Flow
6363

64-
public async Task<User> Connect(EmbeddedWallet embeddedWallet, string email, AuthOptions authOptions)
64+
public virtual async Task<User> Connect(EmbeddedWallet embeddedWallet, string email, AuthOptions authOptions)
6565
{
6666
var config = Resources.Load<ThirdwebConfig>("ThirdwebConfig");
6767
_customScheme = config != null ? config.customScheme : null;
@@ -135,7 +135,7 @@ public async Task<User> Connect(EmbeddedWallet embeddedWallet, string email, Aut
135135
return _user;
136136
}
137137

138-
public void Cancel()
138+
public virtual void Cancel()
139139
{
140140
_exception = new UnityException("User cancelled");
141141
}
@@ -144,7 +144,7 @@ public void Cancel()
144144

145145
#region Email OTP Flow
146146

147-
private async Task LoginWithOTP()
147+
public virtual async Task LoginWithOTP()
148148
{
149149
if (_email == null)
150150
throw new UnityException("Email is required for OTP login");
@@ -154,7 +154,7 @@ private async Task LoginWithOTP()
154154
EmbeddedWalletCanvas.SetActive(true);
155155
}
156156

157-
private async Task OnSendOTP()
157+
public virtual async Task OnSendOTP()
158158
{
159159
try
160160
{
@@ -169,7 +169,7 @@ private async Task OnSendOTP()
169169
}
170170
}
171171

172-
private async void OnSubmitOTP()
172+
public virtual async void OnSubmitOTP()
173173
{
174174
OTPInput.interactable = false;
175175
RecoveryInput.interactable = false;
@@ -207,7 +207,7 @@ private async void OnSubmitOTP()
207207

208208
#region OAuth2 Flow
209209

210-
private async Task LoginWithOauth(string authProviderStr)
210+
public virtual async Task LoginWithOauth(string authProviderStr)
211211
{
212212
if (Application.isMobilePlatform && string.IsNullOrEmpty(_customScheme))
213213
throw new UnityException("No custom scheme provided for mobile deeplinks, please set one in your ThirdwebConfig (found in ThirdwebManager)");
@@ -251,7 +251,7 @@ private async Task LoginWithOauth(string authProviderStr)
251251
}
252252
}
253253

254-
private async void OnSubmitRecoveryOauth(string authProviderStr, string authResult)
254+
public virtual async void OnSubmitRecoveryOauth(string authProviderStr, string authResult)
255255
{
256256
try
257257
{
@@ -266,7 +266,7 @@ private async void OnSubmitRecoveryOauth(string authProviderStr, string authResu
266266
}
267267
}
268268

269-
private async Task<string> GetLoginLink(string authProvider)
269+
public virtual async Task<string> GetLoginLink(string authProvider)
270270
{
271271
string loginUrl = await _embeddedWallet.FetchHeadlessOauthLoginLinkAsync(authProvider);
272272
string platform = "unity";
@@ -279,7 +279,7 @@ private async Task<string> GetLoginLink(string authProvider)
279279

280280
#region JWT Flow
281281

282-
private async Task LoginWithJWT(string jwtToken, string encryptionKey, string recoveryCode = null)
282+
public virtual async Task LoginWithJWT(string jwtToken, string encryptionKey, string recoveryCode = null)
283283
{
284284
if (string.IsNullOrEmpty(jwtToken))
285285
throw new UnityException("JWT token is required for JWT login!");
@@ -295,7 +295,7 @@ private async Task LoginWithJWT(string jwtToken, string encryptionKey, string re
295295

296296
#region Auth Endpoint Flow
297297

298-
private async Task LoginWithAuthEndpoint(string payload, string encryptionKey, string recoveryCode = null)
298+
public virtual async Task LoginWithAuthEndpoint(string payload, string encryptionKey, string recoveryCode = null)
299299
{
300300
if (string.IsNullOrEmpty(payload))
301301
throw new UnityException("Auth payload is required for Auth Endpoint login!");
@@ -311,15 +311,15 @@ private async Task LoginWithAuthEndpoint(string payload, string encryptionKey, s
311311

312312
#region Common
313313

314-
private void DisplayRecoveryInput(bool hideOtpInput)
314+
public virtual void DisplayRecoveryInput(bool hideOtpInput)
315315
{
316316
if (hideOtpInput)
317317
OTPInput.gameObject.SetActive(false);
318318
RecoveryInput.gameObject.SetActive(true);
319319
EmbeddedWalletCanvas.SetActive(true);
320320
}
321321

322-
private void ShowRecoveryCodes(EmbeddedWallet.VerifyResult res)
322+
public virtual void ShowRecoveryCodes(EmbeddedWallet.VerifyResult res)
323323
{
324324
if (res.MainRecoveryCode != null && res.WasEmailed.HasValue && res.WasEmailed.Value == false)
325325
{

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void Awake()
4343

4444
// Core
4545

46-
public async Task<string> Connect()
46+
public virtual async Task<string> Connect()
4747
{
4848
OTPPanel.SetActive(false);
4949

@@ -78,14 +78,14 @@ public async Task<string> Connect()
7878
return MetaMaskUnity.Instance.Wallet.SelectedAddress;
7979
}
8080

81-
public void Cancel()
81+
public virtual void Cancel()
8282
{
8383
_exception = new UnityException("User cancelled");
8484
}
8585

8686
// QR
8787

88-
private void ShowQR(string universalLink, string deepLink)
88+
public virtual void ShowQR(string universalLink, string deepLink)
8989
{
9090
var qrCodeAsTexture2D = GenerateQRTexture(universalLink);
9191
QRCodeImage.sprite = Sprite.Create(qrCodeAsTexture2D, new Rect(0, 0, qrCodeAsTexture2D.width, qrCodeAsTexture2D.height), new Vector2(0.5f, 0.5f));
@@ -94,7 +94,7 @@ private void ShowQR(string universalLink, string deepLink)
9494
QRCodeImage.mainTexture.filterMode = FilterMode.Point;
9595
}
9696

97-
private Texture2D GenerateQRTexture(string text)
97+
public virtual Texture2D GenerateQRTexture(string text)
9898
{
9999
Texture2D encoded = new Texture2D(256, 256);
100100
var color32 = EncodeToQR(text, encoded.width, encoded.height);
@@ -103,7 +103,7 @@ private Texture2D GenerateQRTexture(string text)
103103
return encoded;
104104
}
105105

106-
private Color32[] EncodeToQR(string textForEncoding, int width, int height)
106+
public virtual Color32[] EncodeToQR(string textForEncoding, int width, int height)
107107
{
108108
var writer = new BarcodeWriter
109109
{
@@ -115,48 +115,48 @@ private Color32[] EncodeToQR(string textForEncoding, int width, int height)
115115

116116
// Top level Event Listeners
117117

118-
private void OnWalletConnected(object sender, EventArgs e)
118+
public virtual void OnWalletConnected(object sender, EventArgs e)
119119
{
120120
_connected = true;
121121
}
122122

123-
private void OnWalletAuthorized(object sender, EventArgs e)
123+
public virtual void OnWalletAuthorized(object sender, EventArgs e)
124124
{
125125
_authorized = true;
126126
}
127127

128128
// IMetaMaskUnityTransportListener
129129

130-
public void OnMetaMaskConnectRequest(string universalLink, string deepLink)
130+
public virtual void OnMetaMaskConnectRequest(string universalLink, string deepLink)
131131
{
132132
ShowQR(universalLink, deepLink);
133133
}
134134

135-
public void OnMetaMaskRequest(string id, MetaMaskEthereumRequest request)
135+
public virtual void OnMetaMaskRequest(string id, MetaMaskEthereumRequest request)
136136
{
137137
return;
138138
}
139139

140-
public void OnMetaMaskFailure(Exception error)
140+
public virtual void OnMetaMaskFailure(Exception error)
141141
{
142142
_exception = error;
143143
}
144144

145-
public void OnMetaMaskSuccess()
145+
public virtual void OnMetaMaskSuccess()
146146
{
147147
_connected = true;
148148
_authorized = true;
149149
}
150150

151-
public void OnMetaMaskOTP(int otp)
151+
public virtual void OnMetaMaskOTP(int otp)
152152
{
153153
OTPPanel.SetActive(true);
154154

155155
var shouldShowOtpCode = DateTime.Now - MetaMaskUnity.Instance.Wallet.LastActive >= TimeSpan.FromHours(1);
156156

157157
// They simply need to press resume in the app
158158
OTPText.gameObject.SetActive(shouldShowOtpCode);
159-
159+
160160
if (shouldShowOtpCode)
161161
{
162162
OTPText.text = otp.ToString();
@@ -167,7 +167,7 @@ public void OnMetaMaskOTP(int otp)
167167
}
168168
}
169169

170-
public void OnMetaMaskDisconnected()
170+
public virtual void OnMetaMaskDisconnected()
171171
{
172172
if (!MetaMaskUnity.Instance.Wallet.Transport.IsMobile || !MetaMaskUnity.Instance.Wallet.HasSession)
173173
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private void Awake()
4242
}
4343
}
4444

45-
public async Task<(WalletConnectSignClient, string, string)> Connect(string walletConnectProjectId, BigInteger chainId)
45+
public virtual async Task<(WalletConnectSignClient, string, string)> Connect(string walletConnectProjectId, BigInteger chainId)
4646
{
4747
WalletConnectCanvas.SetActive(true);
4848

@@ -135,7 +135,7 @@ private void Awake()
135135
}
136136
}
137137

138-
private static Texture2D GenerateQRTexture(string text)
138+
public virtual Texture2D GenerateQRTexture(string text)
139139
{
140140
Texture2D encoded = new Texture2D(256, 256);
141141
var color32 = EncodeToQR(text, encoded.width, encoded.height);
@@ -144,7 +144,7 @@ private static Texture2D GenerateQRTexture(string text)
144144
return encoded;
145145
}
146146

147-
private static Color32[] EncodeToQR(string textForEncoding, int width, int height)
147+
public virtual Color32[] EncodeToQR(string textForEncoding, int width, int height)
148148
{
149149
var writer = new BarcodeWriter
150150
{

0 commit comments

Comments
 (0)