diff --git a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Prefabs/LoginPanel.prefab b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Prefabs/LoginPanel.prefab index 57ea081f4..349664e26 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Prefabs/LoginPanel.prefab +++ b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Prefabs/LoginPanel.prefab @@ -169,6 +169,7 @@ RectTransform: - {fileID: 3911810628226866637} - {fileID: 3911810628424708713} - {fileID: 3911810627461880608} + - {fileID: 7757550704155501701} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -5793,7 +5794,7 @@ MonoBehaviour: _animation: 0 _errorText: {fileID: 3911810627816165819} _infoPopupPanelPrefab: {fileID: 8067163605015323916, guid: a5a68ec1b8c3c430694abc1729fc5369, type: 3} - _loadingScreenPrefab: {fileID: 3094631411173026328, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + _loadingScreen: {fileID: 181291193031515344} --- !u!114 &702636062 MonoBehaviour: m_ObjectHideFlags: 0 @@ -6453,7 +6454,7 @@ MonoBehaviour: - {fileID: 3911810626580786188} _enterCodeText: {fileID: 3911810626720903612} _errorText: {fileID: 3911810627950373898} - _loadingScreenPrefab: {fileID: 3094631411173026328, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + _loadingScreen: {fileID: 181291193031515344} --- !u!1 &3911810628491489749 GameObject: m_ObjectHideFlags: 0 @@ -7105,3 +7106,110 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!1001 &2915594493199070920 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 3911810626490335503} + m_Modifications: + - target: {fileID: 3094631411173026328, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_Name + value: LoadingScreen + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_Pivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_Pivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_RootOrder + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchorMax.x + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchorMax.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchorMin.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_SizeDelta.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_SizeDelta.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_AnchoredPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 21aa1af318f304faca1367525db9bc28, type: 3} +--- !u!1 &181291193031515344 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3094631411173026328, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + m_PrefabInstance: {fileID: 2915594493199070920} + m_PrefabAsset: {fileID: 0} +--- !u!224 &7757550704155501701 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 4890380321044959821, guid: 21aa1af318f304faca1367525db9bc28, type: 3} + m_PrefabInstance: {fileID: 2915594493199070920} + m_PrefabAsset: {fileID: 0} diff --git a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoadingScreen.cs b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoadingScreen.cs index d5d0f3e2c..d0381824e 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoadingScreen.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoadingScreen.cs @@ -1,11 +1,7 @@ -using System; using System.Collections; using System.Collections.Generic; -using Sequence.Authentication; -using Sequence.EmbeddedWallet; using UnityEngine; using UnityEngine.UI; -using Random = System.Random; namespace Sequence.Demo { @@ -15,74 +11,14 @@ public class LoadingScreen : MonoBehaviour [SerializeField] [Range(0, 255)] private int _maxAlpha = 255; [SerializeField] [Range(0, 255)] private int _minAlpha = 0; [SerializeField] private float _animationSpeed = .1f; - private LoginPanel _loginPanel; private const int DefaultFullAlphaValue = 255; private void OnEnable() { - _loginPanel = FindObjectOfType(); - if (_loginPanel != null) - { - _loginPanel.LoginHandler.OnLoginSuccess += OnLoginSuccessHandler; - _loginPanel.LoginHandler.OnMFAEmailSent += OnMFAEmailSentHandler; - _loginPanel.LoginHandler.OnLoginFailed += OnLoginFailedHandler; - _loginPanel.LoginHandler.OnMFAEmailFailedToSend += OnMFAEmailFailedToSendHandler; - SequenceWallet.OnAccountFederationFailed += OnAccountFederationFailedHandler; - SequenceWallet.OnAccountFederated += OnAccountFederatedHandler; - } - else - { - Debug.LogError("No LoginPanel found!"); - Destroy(gameObject); - } - StartCoroutine(LoadingAnimation()); } - private void OnDestroy() - { - if (_loginPanel != null) - { - _loginPanel.LoginHandler.OnLoginSuccess -= OnLoginSuccessHandler; - _loginPanel.LoginHandler.OnMFAEmailSent -= OnMFAEmailSentHandler; - _loginPanel.LoginHandler.OnLoginFailed -= OnLoginFailedHandler; - _loginPanel.LoginHandler.OnMFAEmailFailedToSend -= OnMFAEmailFailedToSendHandler; - SequenceWallet.OnAccountFederationFailed -= OnAccountFederationFailedHandler; - SequenceWallet.OnAccountFederated -= OnAccountFederatedHandler; - } - } - - private void OnLoginSuccessHandler(string sessionId, string walletAddress) - { - Destroy(gameObject); - } - - private void OnMFAEmailSentHandler(string email) - { - Destroy(gameObject); - } - - private void OnLoginFailedHandler(string error, LoginMethod method, string email, List loginMethods) - { - Destroy(gameObject); - } - - private void OnMFAEmailFailedToSendHandler(string email, string error) - { - Destroy(gameObject); - } - - private void OnAccountFederationFailedHandler(string error) - { - Destroy(gameObject); - } - - private void OnAccountFederatedHandler(Account account) - { - Destroy(gameObject); - } - private IEnumerator LoadingAnimation() { int numberOfCircles = _circles.Length; @@ -153,24 +89,5 @@ private int[] ShiftIndices(int[] indicesArray) return shifted; } - - private void OnApplicationFocus(bool hasFocus) - { -#if !UNITY_IOS - if (hasFocus) - { - StartCoroutine(DestroyIfNotLoggingIn()); - } -#endif - } - - private IEnumerator DestroyIfNotLoggingIn() - { - yield return new WaitForSecondsRealtime(0.1f); - if (!_loginPanel.LoginHandler.IsLoggingIn()) - { - Destroy(gameObject); - } - } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPage.cs b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPage.cs index ca84f4db1..f7762e0c9 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/LoginPage.cs @@ -1,12 +1,8 @@ -using System; using System.Collections.Generic; using Sequence.Authentication; -using Sequence.Demo.Tweening; using Sequence.EmbeddedWallet; using TMPro; using UnityEngine; -using UnityEngine.Serialization; -using UnityEngine.UI; namespace Sequence.Demo { @@ -14,12 +10,13 @@ public class LoginPage : UIPage { [SerializeField] private TextMeshProUGUI _errorText; [SerializeField] private GameObject _infoPopupPanelPrefab; - [SerializeField] private GameObject _loadingScreenPrefab; - + [SerializeField] private GameObject _loadingScreen; + private TMP_InputField _inputField; private LoginMethod _loginMethod; private string _loginEmail; private LoginButtonHighlighter _loginButtonHighlighter; + internal ILogin LoginHandler { get; private set; } protected override void Awake() @@ -32,14 +29,14 @@ protected override void Awake() private void Start() { _loginMethod = GetLoginMethod(); - + if (_loginButtonHighlighter != null) { _loginButtonHighlighter.HighlightAppropriateButton(_loginMethod); } _loginEmail = GetLoginEmail(); - + SetEmailInputInitialText(); } @@ -53,6 +50,7 @@ protected virtual void SetEmailInputInitialText() return; } } + _inputField.text = _loginEmail; } @@ -60,6 +58,8 @@ public override void Close() { base.Close(); _errorText.text = ""; + EnableLoadingScreen(false); + LoginHandler.OnMFAEmailFailedToSend -= OnMFAEmailFailedToSendHandler; LoginHandler.OnLoginFailed -= OnLoginFailedHandler; SequenceWallet.OnAccountFederationFailed -= OnAccountFederationFailedHandler; @@ -71,6 +71,7 @@ public void SetupLogin(ILogin loginHandler) LoginHandler.OnMFAEmailFailedToSend += OnMFAEmailFailedToSendHandler; LoginHandler.OnLoginFailed += OnLoginFailedHandler; SequenceWallet.OnAccountFederationFailed += OnAccountFederationFailedHandler; + EnableLoadingScreen(false); } public void Login() @@ -78,56 +79,57 @@ public void Login() string email = _inputField.text; Debug.Log($"Signing in with email: {email}"); _errorText.text = ""; + EnableLoadingScreen(true); LoginHandler.Login(email); - InstantiateLoadingScreen(); } public void GoogleLogin() { Debug.Log("Google Login"); + EnableLoadingScreen(true); LoginHandler.GoogleLogin(); - InstantiateLoadingScreen(); } public void DiscordLogin() { Debug.Log("Discord Login"); + EnableLoadingScreen(true); LoginHandler.DiscordLogin(); - InstantiateLoadingScreen(); } public void FacebookLogin() { Debug.Log("Facebook Login"); + EnableLoadingScreen(true); LoginHandler.FacebookLogin(); - InstantiateLoadingScreen(); } public void AppleLogin() { Debug.Log("Apple Login"); + EnableLoadingScreen(true); LoginHandler.AppleLogin(); - InstantiateLoadingScreen(); } - + private void OnMFAEmailFailedToSendHandler(string email, string error) { Debug.LogError($"Failed to send MFA email to {email} with error: {error}"); - _errorText.text = error; + SetError(error); } - - private void OnLoginFailedHandler(string error, LoginMethod method, string email, List loginMethods) + + private void OnLoginFailedHandler(string error, LoginMethod method, string email, + List loginMethods) { Debug.LogError($"Failed to sign in to WaaS API with error: {error}"); - _errorText.text = error; + SetError(error); } - + private void OnAccountFederationFailedHandler(string error) { Debug.LogError($"Failed to federate account with Sequence API: {error}"); - _errorText.text = error; + SetError(error); } - + private LoginMethod GetLoginMethod() { if (PlayerPrefs.HasKey(SequenceLogin.WaaSLoginMethod)) @@ -148,9 +150,15 @@ private string GetLoginEmail() return ""; } - private void InstantiateLoadingScreen() + private void SetError(string error) + { + _errorText.text = error; + EnableLoadingScreen(false); + } + + private void EnableLoadingScreen(bool enable) { - Instantiate(_loadingScreenPrefab, transform.parent); + _loadingScreen.SetActive(enable); } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/MultifactorAuthenticationPage.cs b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/MultifactorAuthenticationPage.cs index 4262c6280..5d7e91392 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/MultifactorAuthenticationPage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceFrontend/Scripts/UI/MultifactorAuthenticationPage.cs @@ -4,7 +4,6 @@ using Sequence.Utils; using TMPro; using UnityEngine; -using UnityEngine.UI; namespace Sequence.Demo { @@ -14,7 +13,7 @@ public class MultifactorAuthenticationPage : UIPage [SerializeField] private TextMeshProUGUI[] _inputBoxes; [SerializeField] private TextMeshProUGUI _enterCodeText; [SerializeField] private TextMeshProUGUI _errorText; - [SerializeField] private GameObject _loadingScreenPrefab; + [SerializeField] private GameObject _loadingScreen; private int _numberOfMFADigits; internal ILogin LoginHandler { get; private set; } @@ -32,6 +31,8 @@ public override void Close() { base.Close(); _errorText.text = ""; + + LoginHandler.OnLoginSuccess -= OnLoginSuccessHandler; LoginHandler.OnLoginFailed -= OnLoginFailedHandler; } @@ -60,6 +61,8 @@ public override void Open(params object[] args) } _enterCodeText.text = $"Enter the code sent to\n{email}"; _inputField.text = ""; + + LoginHandler.OnLoginSuccess += OnLoginSuccessHandler; LoginHandler.OnLoginFailed += OnLoginFailedHandler; } @@ -90,18 +93,25 @@ public void Login() string code = _inputField.text.Substring(0, Math.Min(_numberOfMFADigits, _inputField.text.Length)); Debug.Log($"Attempting to sign in with email {email} and code {code}"); LoginHandler.Login(email, code); - InstantiateLoadingScreen(); + EnableLoadingScreen(true); } + private void OnLoginSuccessHandler(string sessionId, string walletAddress) + { + Debug.Log($"Login Succeeded {walletAddress}"); + EnableLoadingScreen(false); + } + private void OnLoginFailedHandler(string error, LoginMethod method, string email, List loginMethods) { Debug.LogError($"Failed login: {error}"); _errorText.text = error; + EnableLoadingScreen(false); } - private void InstantiateLoadingScreen() + private void EnableLoadingScreen(bool enable) { - Instantiate(_loadingScreenPrefab, transform.parent); + _loadingScreen.SetActive(enable); } } } \ No newline at end of file diff --git a/Packages/Sequence-Unity/package.json b/Packages/Sequence-Unity/package.json index a7f8a8f2d..6ab8fdcd9 100644 --- a/Packages/Sequence-Unity/package.json +++ b/Packages/Sequence-Unity/package.json @@ -1,6 +1,6 @@ { "name": "xyz.0xsequence.waas-unity", - "version": "3.14.1", + "version": "3.14.2", "displayName": "Sequence Embedded Wallet SDK", "description": "A Unity SDK for the Sequence WaaS API", "unity": "2021.3",