Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
chore: re-enabled email request popup (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbosio authored Aug 21, 2020
1 parent a61d645 commit 8cff3ec
Show file tree
Hide file tree
Showing 32 changed files with 1,104 additions and 941 deletions.
1 change: 1 addition & 0 deletions kernel/packages/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const INIT_PRE_LOAD = location.search.indexOf('INIT_PRE_LOAD') !== -1

export const AWS = location.search.indexOf('AWS') !== -1
export const NO_MOTD = location.search.indexOf('NO_MOTD') !== -1
export const RESET_TUTORIAL = location.search.indexOf('RESET_TUTORIAL') !== -1

export const DISABLE_AUTH = location.search.indexOf('DISABLE_AUTH') !== -1 || DEBUG
export const ENGINE_DEBUG_PANEL = location.search.indexOf('ENGINE_DEBUG_PANEL') !== -1
Expand Down
11 changes: 10 additions & 1 deletion kernel/packages/shared/profiles/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
getWearablesSafeURL,
PIN_CATALYST,
PREVIEW,
ethereumConfigurations
ethereumConfigurations,
RESET_TUTORIAL
} from 'config'

import { NotificationType } from 'shared/types'
Expand Down Expand Up @@ -188,6 +189,11 @@ function* initialProfileLoad() {
profileDirty = true
}

if (RESET_TUTORIAL) {
profile = { ...profile, tutorialStep: 0 }
profileDirty = true
}

if (profileDirty) {
scheduleProfileUpdate(profile)
}
Expand Down Expand Up @@ -489,6 +495,9 @@ export function* submitProfileToRenderer(action: ProfileSuccessAction): any {
if (ALL_WEARABLES) {
profile.inventory = (yield select(getExclusiveCatalog)).map((_: Wearable) => _.id)
}

globalThis.unityInterface.ConfigureEmailPrompt(profile.tutorialStep)

yield call(sendLoadProfile, profile)
} else {
yield call(ensureRenderer)
Expand Down
3 changes: 2 additions & 1 deletion kernel/packages/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export enum HUDElementID {
OPEN_EXTERNAL_URL_PROMPT = 14,
NFT_INFO_DIALOG = 16,
TELEPORT_DIALOG = 17,
CONTROLS_HUD = 18
CONTROLS_HUD = 18,
EMAIL_PROMPT = 19
}

export type HUDConfiguration = {
Expand Down
9 changes: 8 additions & 1 deletion kernel/packages/unity-interface/UnityInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class UnityInterface {
}

if (!this.gameInstance.Module) {

defaultLogger.log(
`Can't change base resolution height to ${height}! Are you running explorer in unity editor or native?`
)
Expand Down Expand Up @@ -300,6 +299,14 @@ export class UnityInterface {
}
}

public ConfigureEmailPrompt(tutorialStep: number) {
const emailCompletedFlag = 128
this.ConfigureHUDElement(HUDElementID.EMAIL_PROMPT, {
active: (tutorialStep & emailCompletedFlag) === 0,
visible: false
})
}

// *********************************************************************************
// ************** Builder messages **************
// *********************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
"name": "EmailPromptHUD",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:1de3566cccb280f4a982c59ad0d08c96",
"GUID:555c1f3c6d18648df910b7a1de75b424",
"GUID:b1087c5731ff68448a0a9c625bb7e52d",
"GUID:4720e174f2805c74bb7aa94cc8bb5bf8",
"GUID:760a1d365aad58044916992b072cf2a6",
"GUID:3f4c1b4f55716479ea104c4254afe172",
"GUID:8e14059e964ca49aeb55d0e7b2b14c3c",
"GUID:4973650d2444c4561a15d50f24d91cd9"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}
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);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8cff3ec

Please sign in to comment.