This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: re-enabled email request popup (#1188)
- Loading branch information
Showing
32 changed files
with
1,104 additions
and
941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 95 additions & 19 deletions
114
...Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmailPromptHUD/EmailPromptHUDController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,110 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using TMPro; | ||
using DCL.Interface; | ||
using DCL.Helpers; | ||
using System.Collections; | ||
using DCL.Tutorial; | ||
|
||
public class EmailPromptHUDController : MonoBehaviour | ||
public class EmailPromptHUDController : IHUD | ||
{ | ||
public TMP_InputField inputField; | ||
public GameObject cryptoUserMessage; | ||
public GameObject nonCryptoUserMessage; | ||
public Button sendButton; | ||
const float POPUP_DELAY = 60; | ||
|
||
void Awake() | ||
EmailPromptHUDView view; | ||
|
||
bool isPopupRoutineRunning = false; | ||
Coroutine showPopupDelayedRoutine; | ||
|
||
public EmailPromptHUDController() | ||
{ | ||
view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("EmailPromptHUD")).GetComponent<EmailPromptHUDView>(); | ||
view.name = "_EmailPromptHUD"; | ||
|
||
view.OnDismiss += OnDismiss; | ||
view.OnSendEmail += OnSendEmail; | ||
|
||
view.gameObject.SetActive(false); | ||
} | ||
|
||
public void SetVisibility(bool visible) | ||
{ | ||
if (visible) | ||
{ | ||
Utils.UnlockCursor(); | ||
view.gameObject.SetActive(true); | ||
view.showHideAnimator.Show(); | ||
} | ||
else | ||
{ | ||
view.showHideAnimator.Hide(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (view != null) | ||
{ | ||
GameObject.Destroy(view.gameObject); | ||
} | ||
if (showPopupDelayedRoutine != null) | ||
{ | ||
StopPopupRoutine(); | ||
} | ||
} | ||
|
||
public void SetEnable(bool enable) | ||
{ | ||
if (enable && !isPopupRoutineRunning) | ||
{ | ||
StartPopupRoutine(); | ||
} | ||
else if (!enable && isPopupRoutineRunning) | ||
{ | ||
StopPopupRoutine(); | ||
} | ||
} | ||
|
||
void StartPopupRoutine() | ||
{ | ||
showPopupDelayedRoutine = CoroutineStarter.Start(ShowPopupDelayed(POPUP_DELAY)); | ||
} | ||
|
||
void StopPopupRoutine() | ||
{ | ||
bool hasWallet = UserProfile.GetOwnUserProfile().hasConnectedWeb3; | ||
if (showPopupDelayedRoutine != null) | ||
{ | ||
CoroutineStarter.Stop(showPopupDelayedRoutine); | ||
showPopupDelayedRoutine = null; | ||
} | ||
isPopupRoutineRunning = false; | ||
} | ||
|
||
cryptoUserMessage.SetActive(hasWallet); | ||
nonCryptoUserMessage.SetActive(!hasWallet); | ||
IEnumerator ShowPopupDelayed(float seconds) | ||
{ | ||
isPopupRoutineRunning = true; | ||
yield return new WaitUntil(() => CommonScriptableObjects.rendererState.Get()); | ||
yield return WaitForSecondsCache.Get(seconds); | ||
yield return new WaitUntil(() => CommonScriptableObjects.rendererState.Get()); | ||
SetVisibility(true); | ||
isPopupRoutineRunning = false; | ||
} | ||
|
||
sendButton.interactable = false; | ||
sendButton.onClick.AddListener(SaveEmail); | ||
void OnSendEmail(string email) | ||
{ | ||
WebInterface.SendUserEmail(email); | ||
SetEmailFlag(); | ||
SetVisibility(false); | ||
} | ||
|
||
inputField.onValueChanged.AddListener(value => | ||
void OnDismiss(bool dontAskAgain) | ||
{ | ||
if (dontAskAgain) | ||
{ | ||
sendButton.interactable = !string.IsNullOrEmpty(value); | ||
}); | ||
SetEmailFlag(); | ||
} | ||
SetVisibility(false); | ||
} | ||
|
||
public void SaveEmail() | ||
void SetEmailFlag() | ||
{ | ||
gameObject.SetActive(false); | ||
WebInterface.SendUserEmail(inputField.text); | ||
TutorialController.i.SetStepCompleted(TutorialController.TutorialStep.EmailRequested); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/Scripts/MainScripts/DCL/Controllers/HUD/EmailPromptHUD/EmailPromptHUDController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
...lient/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmailPromptHUD/EmailPromptHUDView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using TMPro; | ||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
internal class EmailPromptHUDView : MonoBehaviour | ||
{ | ||
public event Action<string> OnSendEmail; | ||
public event Action<bool> OnDismiss; | ||
|
||
public TMP_InputField inputField; | ||
public Button_OnPointerDown closeButton; | ||
public Button_OnPointerDown sendButton; | ||
public Toggle dontAskAgain; | ||
public ShowHideAnimator showHideAnimator; | ||
public GameObject invalidEmailIndicator; | ||
|
||
// NOTE: regex based in https://github.com/Microsoft/referencesource/blob/master/System.ComponentModel.DataAnnotations/DataAnnotations/EmailAddressAttribute.cs | ||
const string emailPattern = @"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$"; | ||
const RegexOptions options = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture; | ||
Regex emailRegex = new Regex(emailPattern, options); | ||
|
||
void Awake() | ||
{ | ||
sendButton.interactable = false; | ||
invalidEmailIndicator.SetActive(false); | ||
|
||
sendButton.onClick.AddListener(() => OnSendEmail?.Invoke(inputField.text)); | ||
closeButton.onClick.AddListener(() => OnDismiss?.Invoke(dontAskAgain.isOn)); | ||
|
||
inputField.onValueChanged.AddListener(value => | ||
{ | ||
bool isValidValue = IsValidEmail(value); | ||
sendButton.interactable = isValidValue; | ||
|
||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
invalidEmailIndicator.SetActive(!isValidValue); | ||
} | ||
else | ||
{ | ||
invalidEmailIndicator.SetActive(false); | ||
} | ||
}); | ||
|
||
inputField.onSubmit.AddListener(value => | ||
{ | ||
if (sendButton.interactable) | ||
{ | ||
sendButton.onClick.Invoke(); | ||
} | ||
}); | ||
|
||
showHideAnimator.OnWillFinishStart += OnWillFinishStart; | ||
} | ||
|
||
void OnWillFinishStart(ShowHideAnimator animator) | ||
{ | ||
inputField.Select(); | ||
inputField.ActivateInputField(); | ||
} | ||
|
||
void OnDestroy() | ||
{ | ||
showHideAnimator.OnWillFinishStart -= OnWillFinishStart; | ||
} | ||
|
||
bool IsValidEmail(string email) | ||
{ | ||
return emailRegex.IsMatch(email); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmailPromptHUD/EmailPromptHUDView.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...trollers/HUD/EmailPromptHUD/Textures.meta → ...rollers/HUD/EmailPromptHUD/Resources.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.