< Summary

Class:ProfileHUDView
Assembly:ProfileHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ProfileHUD/ProfileHUDView.cs
Covered lines:0
Uncovered lines:147
Coverable lines:147
Total lines:341
Line coverage:0% (0 of 147)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RefreshControl()0%2100%
HasManaCounterView()0%2100%
HasPolygonManaCounterView()0%2100%
IsDesciptionIsLongerThanMaxCharacters()0%2100%
SetManaBalance(...)0%2100%
SetPolygonBalance(...)0%2100%
SetWalletSectionEnabled(...)0%2100%
SetNonWalletSectionEnabled(...)0%2100%
SetStartMenuButtonActive(...)0%2100%
ShowProfileIcon(...)0%2100%
ShowExpanded(...)0%12300%
SetProfile(...)0%2100%
OnEnable()0%2100%
OnDisable()0%2100%
Awake()0%2100%
UpdateLayoutByProfile(...)0%6200%
UpdateNameCharLimit(...)0%2100%
UpdateDescriptionCharLimit(...)0%2100%
SetDescriptionEnabled(...)0%6200%
OpenStartMenu()0%12300%
HandleProfileSnapshot(...)0%2100%
HandleClaimedProfileName(...)0%2100%
HandleUnverifiedProfileName(...)0%12300%
SetConnectedWalletSectionActive(...)0%2100%
SetActiveUnverifiedNameGOs(...)0%6200%
HandleProfileAddress(...)0%2100%
SetProfileImage(...)0%2100%
OnDestroy()0%12300%
CopyAddress()0%12300%
ShowCopyToast()0%20400%
ActivateProfileNameEditionMode(...)0%20400%
SetDescriptionIsEditing(...)0%6200%
SetDescription(...)0%6200%
EnableNextFrame()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ProfileHUD/ProfileHUDView.cs

#LineLine coverage
 1using DCL;
 2using ExploreV2Analytics;
 3using System;
 4using System.Collections;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using Environment = DCL.Environment;
 9
 10public class ProfileHUDView : BaseComponentView, IProfileHUDView
 11{
 12    private const int ADDRESS_CHUNK_LENGTH = 6;
 13    private const int NAME_POSTFIX_LENGTH = 4;
 14    private const float COPY_TOAST_VISIBLE_TIME = 3;
 15
 16    [SerializeField] private RectTransform mainRootLayout;
 17    [SerializeField] private GameObject loadingSpinner;
 18    [SerializeField] private ShowHideAnimator copyToast;
 19    [SerializeField] private GameObject copyTooltip;
 20    [SerializeField] private GameObject expandedObject;
 21    [SerializeField] private GameObject profilePicObject;
 22    [SerializeField] private InputAction_Trigger closeAction;
 23
 24    [Header("Hide GOs on claimed name")]
 25    [SerializeField] internal GameObject[] hideOnNameClaimed;
 26
 27    [Header("Connected wallet sections")]
 28    [SerializeField] internal GameObject connectedWalletSection;
 29    [SerializeField] internal GameObject nonConnectedWalletSection;
 30
 31    [Header("Thumbnail")]
 32    [SerializeField] internal RawImage imageAvatarThumbnail;
 33    [SerializeField] protected internal Button buttonToggleMenu;
 34
 35    [Header("Texts")]
 36    [SerializeField] internal TextMeshProUGUI textName;
 37    [SerializeField] internal TextMeshProUGUI textPostfix;
 38    [SerializeField] internal TextMeshProUGUI textAddress;
 39
 40    [Header("Buttons")]
 41    [SerializeField] protected internal Button buttonLogOut;
 42    [SerializeField] protected internal Button buttonSignUp;
 43    [SerializeField] protected internal Button buttonClaimName;
 44    [SerializeField] protected internal Button buttonCopyAddress;
 45    [SerializeField] protected internal Button_OnPointerDown buttonTermsOfServiceForConnectedWallets;
 46    [SerializeField] protected internal Button_OnPointerDown buttonPrivacyPolicyForConnectedWallets;
 47    [SerializeField] protected internal Button_OnPointerDown buttonTermsOfServiceForNonConnectedWallets;
 48    [SerializeField] protected internal Button_OnPointerDown buttonPrivacyPolicyForNonConnectedWallets;
 49
 50    [Header("Name Edition")]
 51    [SerializeField] protected internal Button_OnPointerDown buttonEditName;
 52    [SerializeField] protected internal Button_OnPointerDown buttonEditNamePrefix;
 53    [SerializeField] internal TMP_InputField inputName;
 54    [SerializeField] internal TextMeshProUGUI textCharLimit;
 55    [SerializeField] internal ManaCounterView manaCounterView;
 56    [SerializeField] internal ManaCounterView polygonManaCounterView;
 57
 58    [Header("Tutorial Config")]
 59    [SerializeField] internal RectTransform tutorialTooltipReference;
 60
 61    [Header("Description")]
 62    [SerializeField] internal TMP_InputField descriptionEditionInput;
 63    [SerializeField] internal GameObject charLimitDescriptionContainer;
 64    [SerializeField] internal TextMeshProUGUI textCharLimitDescription;
 65    [SerializeField] internal GameObject descriptionContainer;
 66
 67    public event EventHandler ClaimNamePressed;
 68    public event EventHandler SignedUpPressed;
 69    public event EventHandler LogedOutPressed;
 70    public event EventHandler Opened;
 71    public event EventHandler Closed;
 72    public event EventHandler<string> NameSubmitted;
 73    public event EventHandler<string> DescriptionSubmitted;
 74    public event EventHandler ManaInfoPressed;
 75    public event EventHandler ManaPurchasePressed;
 76    public event EventHandler TermsAndServicesPressed;
 77    public event EventHandler PrivacyPolicyPressed;
 78
 79    internal bool isStartMenuInitialized = false;
 80
 81    private InputAction_Trigger.Triggered closeActionDelegate;
 82    private Coroutine copyToastRoutine = null;
 83    private UserProfile profile = null;
 84
 85    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 86
 087    public GameObject GameObject => gameObject;
 088    public RectTransform ExpandedMenu => mainRootLayout;
 089    public RectTransform TutorialReference => tutorialTooltipReference;
 90
 91
 092    public override void RefreshControl() { }
 93
 094    public bool HasManaCounterView() => manaCounterView != null;
 95
 096    public bool HasPolygonManaCounterView() => polygonManaCounterView != null;
 97
 098    public bool IsDesciptionIsLongerThanMaxCharacters() => descriptionEditionInput.characterLimit < descriptionEditionIn
 99
 0100    public void SetManaBalance(string balance) => manaCounterView.SetBalance(balance);
 101
 0102    public void SetPolygonBalance(double balance) => polygonManaCounterView.SetBalance(balance);
 103
 0104    public void SetWalletSectionEnabled(bool isEnabled) => connectedWalletSection.SetActive(isEnabled);
 105
 0106    public void SetNonWalletSectionEnabled(bool isEnabled) => nonConnectedWalletSection.SetActive(isEnabled);
 107
 0108    public void SetStartMenuButtonActive(bool isActive) => isStartMenuInitialized = isActive;
 109
 110    public void ShowProfileIcon(bool show)
 111    {
 0112        profilePicObject.SetActive(show);
 0113    }
 114
 115    public void ShowExpanded(bool show)
 116    {
 0117        expandedObject.SetActive(show);
 0118        if (show && profile)
 0119            UpdateLayoutByProfile(profile);
 0120    }
 121
 122    public void SetProfile(UserProfile userProfile)
 123    {
 0124        profile = userProfile;
 0125        UpdateLayoutByProfile(userProfile);
 0126    }
 127
 128
 0129    private void OnEnable() => closeAction.OnTriggered += closeActionDelegate;
 130
 0131    private void OnDisable() => closeAction.OnTriggered -= closeActionDelegate;
 132
 133    private void Awake()
 134    {
 0135        buttonLogOut.onClick.AddListener(() => LogedOutPressed?.Invoke(this, EventArgs.Empty));
 0136        buttonSignUp.onClick.AddListener(() => SignedUpPressed?.Invoke(this, EventArgs.Empty));
 0137        buttonClaimName.onClick.AddListener(() => ClaimNamePressed?.Invoke(this, EventArgs.Empty));
 138
 0139        buttonTermsOfServiceForConnectedWallets.onClick.AddListener(() => TermsAndServicesPressed?.Invoke(this, EventArg
 0140        buttonTermsOfServiceForNonConnectedWallets.onClick.AddListener(() => TermsAndServicesPressed?.Invoke(this, Event
 0141        buttonPrivacyPolicyForConnectedWallets.onClick.AddListener(() => PrivacyPolicyPressed?.Invoke(this, EventArgs.Em
 0142        buttonPrivacyPolicyForNonConnectedWallets.onClick.AddListener(() => PrivacyPolicyPressed?.Invoke(this, EventArgs
 143
 0144        manaCounterView.buttonManaInfo.onClick.AddListener(() => ManaInfoPressed?.Invoke(this, EventArgs.Empty));
 0145        polygonManaCounterView.buttonManaInfo.onClick.AddListener(() => ManaInfoPressed?.Invoke(this, EventArgs.Empty));
 0146        manaCounterView.buttonManaPurchase.onClick.AddListener(() => ManaPurchasePressed?.Invoke(this, EventArgs.Empty))
 0147        polygonManaCounterView.buttonManaPurchase.onClick.AddListener(() => ManaPurchasePressed?.Invoke(this, EventArgs.
 148
 0149        buttonToggleMenu.onClick.AddListener(OpenStartMenu);
 0150        buttonCopyAddress.onClick.AddListener(CopyAddress);
 0151        buttonEditName.onPointerDown += () => ActivateProfileNameEditionMode(true);
 0152        buttonEditNamePrefix.onPointerDown += () => ActivateProfileNameEditionMode(true);
 0153        inputName.onValueChanged.AddListener(UpdateNameCharLimit);
 0154        inputName.onEndEdit.AddListener(x =>
 155        {
 0156            inputName.OnDeselect(null);
 0157        });
 0158        inputName.onDeselect.AddListener(x =>
 159        {
 0160            ActivateProfileNameEditionMode(false);
 0161            NameSubmitted?.Invoke(this, x);
 0162        });
 163
 0164        descriptionEditionInput.onTextSelection.AddListener((description, x, y) =>
 165        {
 0166            SetDescriptionIsEditing(true);
 0167            UpdateDescriptionCharLimit(description);
 0168        });
 0169        descriptionEditionInput.onSelect.AddListener(description =>
 170        {
 0171            SetDescriptionIsEditing(true);
 0172            UpdateDescriptionCharLimit(description);
 0173        });
 0174        descriptionEditionInput.onValueChanged.AddListener(description =>
 175        {
 0176            UpdateDescriptionCharLimit(description);
 0177        });
 0178        descriptionEditionInput.onEndEdit.AddListener(description =>
 179        {
 0180            descriptionEditionInput.OnDeselect(null);
 0181        });
 0182        descriptionEditionInput.onDeselect.AddListener(description =>
 183        {
 0184            SetDescriptionIsEditing(false);
 0185            DescriptionSubmitted?.Invoke(this, description);
 0186        });
 0187        copyToast.gameObject.SetActive(false);
 0188        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 0189    }
 190
 191    private void UpdateLayoutByProfile(UserProfile userProfile)
 192    {
 0193        if (userProfile.hasClaimedName)
 0194            HandleClaimedProfileName(userProfile);
 195        else
 0196            HandleUnverifiedProfileName(userProfile);
 197
 0198        SetConnectedWalletSectionActive(userProfile.hasConnectedWeb3);
 0199        HandleProfileAddress(userProfile);
 0200        HandleProfileSnapshot(userProfile);
 0201        SetDescription(userProfile.description);
 0202        SetDescriptionEnabled(userProfile.hasConnectedWeb3);
 0203    }
 204
 0205    private void UpdateNameCharLimit(string newValue) => textCharLimit.text = $"{newValue.Length}/{inputName.characterLi
 206
 207    private void UpdateDescriptionCharLimit(string newValue) =>
 0208        textCharLimitDescription.text = $"{newValue.Length}/{descriptionEditionInput.characterLimit}";
 209
 210    private void SetDescriptionEnabled(bool enabled)
 211    {
 0212        if (descriptionContainer.activeSelf != enabled)
 0213            StartCoroutine(EnableNextFrame(descriptionContainer, enabled));
 0214    }
 215
 216    private void OpenStartMenu()
 217    {
 0218        if (isStartMenuInitialized)
 219        {
 0220            if (!DataStore.i.exploreV2.isOpen.Get())
 221            {
 0222                var exploreV2Analytics = new ExploreV2Analytics.ExploreV2Analytics();
 0223                exploreV2Analytics.SendStartMenuVisibility(true, ExploreUIVisibilityMethod.FromClick);
 224            }
 0225            DataStore.i.exploreV2.isOpen.Set(true);
 226        }
 0227    }
 228
 229    private void HandleProfileSnapshot(UserProfile userProfile)
 230    {
 0231        loadingSpinner.SetActive(true);
 0232        userProfile.snapshotObserver.AddListener(SetProfileImage);
 0233    }
 234
 235    private void HandleClaimedProfileName(UserProfile userProfile)
 236    {
 0237        textName.text = userProfile.userName;
 0238        SetActiveUnverifiedNameGOs(false);
 0239    }
 240
 241    private void HandleUnverifiedProfileName(UserProfile userProfile)
 242    {
 0243        textName.text = string.IsNullOrEmpty(userProfile.userName) || userProfile.userName.Length <= NAME_POSTFIX_LENGTH
 244            ? userProfile.userName
 245            : userProfile.userName.Substring(0, userProfile.userName.Length - NAME_POSTFIX_LENGTH - 1);
 246
 0247        textPostfix.text = $"#{userProfile.userId.Substring(userProfile.userId.Length - NAME_POSTFIX_LENGTH)}";
 0248        SetActiveUnverifiedNameGOs(true);
 0249    }
 250
 251    private void SetConnectedWalletSectionActive(bool active)
 252    {
 0253        connectedWalletSection.SetActive(active);
 0254        nonConnectedWalletSection.SetActive(!active);
 0255        buttonLogOut.gameObject.SetActive(active);
 0256    }
 257
 258    private void SetActiveUnverifiedNameGOs(bool active)
 259    {
 0260        for (int i = 0; i < hideOnNameClaimed.Length; i++)
 0261            hideOnNameClaimed[i].SetActive(active);
 0262    }
 263
 264    private void HandleProfileAddress(UserProfile userProfile)
 265    {
 0266        string address = userProfile.userId;
 0267        string start = address.Substring(0, ADDRESS_CHUNK_LENGTH);
 0268        string end = address.Substring(address.Length - ADDRESS_CHUNK_LENGTH);
 0269        textAddress.text = $"{start}...{end}";
 0270    }
 271
 272    private void SetProfileImage(Texture2D texture)
 273    {
 0274        loadingSpinner.SetActive(false);
 0275        imageAvatarThumbnail.texture = texture;
 0276    }
 277
 278    private void OnDestroy()
 279    {
 0280        hudCanvasCameraModeController?.Dispose();
 0281        if (profile)
 0282            profile.snapshotObserver.RemoveListener(SetProfileImage);
 0283    }
 284
 285    private void CopyAddress()
 286    {
 0287        if (!profile)
 0288            return;
 289
 0290        Environment.i.platform.clipboard.WriteText(profile.userId);
 291
 0292        copyTooltip.SetActive(false);
 0293        if (copyToastRoutine != null)
 0294            StopCoroutine(copyToastRoutine);
 295
 0296        copyToastRoutine = StartCoroutine(ShowCopyToast());
 0297    }
 298
 299    private IEnumerator ShowCopyToast()
 300    {
 0301        if (!copyToast.gameObject.activeSelf)
 0302            copyToast.gameObject.SetActive(true);
 303
 0304        copyToast.Show();
 0305        yield return new WaitForSeconds(COPY_TOAST_VISIBLE_TIME);
 0306        copyToast.Hide();
 0307    }
 308
 309    internal void ActivateProfileNameEditionMode(bool activate)
 310    {
 0311        if (profile != null && profile.hasClaimedName)
 0312            return;
 313
 0314        textName.gameObject.SetActive(!activate);
 0315        inputName.gameObject.SetActive(activate);
 316
 0317        if (activate)
 318        {
 0319            inputName.text = textName.text;
 0320            inputName.Select();
 321        }
 0322    }
 323
 324    public void SetDescriptionIsEditing(bool isEditing)
 325    {
 0326        if (charLimitDescriptionContainer.activeSelf != isEditing)
 0327            StartCoroutine(EnableNextFrame(charLimitDescriptionContainer, isEditing));
 0328    }
 329
 330    private void SetDescription(string description)
 331    {
 0332        if (descriptionEditionInput.text != description)
 0333            descriptionEditionInput.text = description;
 0334    }
 335
 336    private IEnumerator EnableNextFrame(GameObject go, bool shouldEnable)
 337    {
 0338        yield return null;
 0339        go.SetActive(shouldEnable);
 0340    }
 341}