Skip to content

Commit bc786ee

Browse files
committed
Handle invalid Email OTP submission and add optional UnityEvent for EmbeddedWalletUI inspector
1 parent 6b2cd8d commit bc786ee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System;
1212
using System.Linq;
1313
using System.Collections.Generic;
14+
using UnityEngine.Events;
1415

1516
namespace Thirdweb.Wallets
1617
{
@@ -26,6 +27,9 @@ public class EmbeddedWalletUI : MonoBehaviour
2627
public TMP_Text RecoveryCodesText;
2728
public Button RecoveryCodesCopy;
2829

30+
[Tooltip("Invoked when the user submits an invalid OTP and can retry.")]
31+
public UnityEvent OnEmailOTPVerificationFailed;
32+
2933
private EmbeddedWallet _embeddedWallet;
3034
private string _email;
3135
private User _user;
@@ -174,6 +178,16 @@ private async void OnSubmitOTP()
174178
{
175179
string otp = OTPInput.text;
176180
var res = await _embeddedWallet.VerifyOtpAsync(_email, otp, string.IsNullOrEmpty(RecoveryInput.text) ? null : RecoveryInput.text);
181+
if (res.User == null)
182+
{
183+
if (res.CanRetry && OnEmailOTPVerificationFailed.GetPersistentEventCount() > 0)
184+
{
185+
OnEmailOTPVerificationFailed.Invoke();
186+
return;
187+
}
188+
_exception = new UnityException("User OTP Verification Failed.");
189+
return;
190+
}
177191
_user = res.User;
178192
ShowRecoveryCodes(res);
179193
}

0 commit comments

Comments
 (0)