Skip to content

Commit

Permalink
add connect flag for silent login (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian authored May 15, 2024
1 parent ac7b599 commit bc82178
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Assets/Treasure/TDK/Runtime/Connect/UI/TDKConnectUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ public class TDKConnectUIManager : MonoBehaviour
[Header("Test buttons")]
[SerializeField] private Button switchThemeButton;
[SerializeField] private Button switchSceneButton;
[SerializeField] private ScreenOrientation currentOriantation;
[SerializeField] private ScreenOrientation currentOriantation;

private ModalBase currentModalOpended;

private bool _isActive = false;

private string _address;
private string _email;
private bool _isSilentLogin = false;
private bool useSmartWallets = true;
private ChainData _currentChainData;

private void Awake()
{
if (Instance == null)
Instance = this;
Instance = this;
}

private void Start()
Expand All @@ -63,6 +64,11 @@ private void Start()
});
}

public bool IsSilentLogin
{
get { return _isSilentLogin; }
}

#region test code
IEnumerator SwitchScene()
{
Expand Down Expand Up @@ -134,9 +140,9 @@ public void ShowAccountModal()
currentModalOpended.Hide();

currentModalOpended = logedInHolder;
logedInHolder.Show();
logedInHolder.Show();

TDK.Analytics.TrackCustomEvent(AnalyticsConstants.EVT_TREASURECONNECT_UI_ACCOUNT);
TDK.Analytics.TrackCustomEvent(AnalyticsConstants.EVT_TREASURECONNECT_UI_ACCOUNT);
}

public void LogOut()
Expand All @@ -157,9 +163,10 @@ private void Activate()
#endregion

#region Connecting
public async Task<bool> ConnectEmail(string email)
public async Task<bool> ConnectEmail(string email, bool isSilentLogin = false)
{
_email = email;
_isSilentLogin = isSilentLogin;
var wc = useSmartWallets
? new WalletConnection(
provider: WalletProvider.SmartWallet,
Expand Down
8 changes: 8 additions & 0 deletions Assets/Treasure/TDK/Runtime/Connect/UI/TDKEmbeddedWalletUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Treasure
{
public class TDKSilentLoginException : Exception { }

public class TDKEmbeddedWalletUI : InAppWalletUI
{
[Space]
Expand Down Expand Up @@ -79,6 +81,12 @@ public override async Task LoginWithOTP()
}
catch (Exception e)
{
if (TDKConnectUIManager.Instance.IsSilentLogin)
{
ThirdwebDebug.Log($"Could not recreate user automatically, skipping silent login");
throw new TDKSilentLoginException();
}

ThirdwebDebug.Log($"Could not recreate user automatically, proceeding with auth: {e.Message}");
}

Expand Down

0 comments on commit bc82178

Please sign in to comment.