< 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:150
Coverable lines:150
Total lines:345
Line coverage:0% (0 of 150)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:40
Method coverage:0% (0 of 40)

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 DCL.MyAccount;
 3using ExploreV2Analytics;
 4using System;
 5using System.Collections;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9using Environment = DCL.Environment;
 10
 11public class ProfileHUDView : BaseComponentView, IProfileHUDView
 12{
 13    private const int ADDRESS_CHUNK_LENGTH = 6;
 14    private const int NAME_POSTFIX_LENGTH = 4;
 15    private const float COPY_TOAST_VISIBLE_TIME = 3;
 16
 17    [SerializeField] private RectTransform mainRootLayout;
 18    [SerializeField] private GameObject loadingSpinner;
 19    [SerializeField] private ShowHideAnimator copyToast;
 20    [SerializeField] private GameObject copyTooltip;
 21    [SerializeField] private GameObject expandedObject;
 22    [SerializeField] private GameObject profilePicObject;
 23    [SerializeField] private InputAction_Trigger closeAction;
 24
 25    [Header("Hide GOs on claimed name")]
 26    [SerializeField] internal GameObject[] hideOnNameClaimed;
 27
 28    [Header("Connected wallet sections")]
 29    [SerializeField] internal GameObject connectedWalletSection;
 30    [SerializeField] internal GameObject nonConnectedWalletSection;
 31
 32    [Header("Thumbnail")]
 33    [SerializeField] internal RawImage imageAvatarThumbnail;
 34    [SerializeField] protected internal Button buttonToggleMenu;
 35
 36    [Header("Texts")]
 37    [SerializeField] internal TextMeshProUGUI textName;
 38    [SerializeField] internal TextMeshProUGUI textPostfix;
 39    [SerializeField] internal TextMeshProUGUI textAddress;
 40
 41    [Header("Buttons")]
 42    [SerializeField] protected internal Button buttonLogOut;
 43    [SerializeField] protected internal Button buttonSignUp;
 44    [SerializeField] protected internal Button buttonClaimName;
 45    [SerializeField] protected internal Button buttonCopyAddress;
 46    [SerializeField] protected internal Button_OnPointerDown buttonTermsOfServiceForConnectedWallets;
 47    [SerializeField] protected internal Button_OnPointerDown buttonPrivacyPolicyForConnectedWallets;
 48    [SerializeField] protected internal Button_OnPointerDown buttonTermsOfServiceForNonConnectedWallets;
 49    [SerializeField] protected internal Button_OnPointerDown buttonPrivacyPolicyForNonConnectedWallets;
 50
 51    [Header("Name Edition")]
 52    [SerializeField] protected internal Button_OnPointerDown buttonEditName;
 53    [SerializeField] protected internal Button_OnPointerDown buttonEditNamePrefix;
 54    [SerializeField] internal TMP_InputField inputName;
 55    [SerializeField] internal TextMeshProUGUI textCharLimit;
 56    [SerializeField] internal ManaCounterView manaCounterView;
 57    [SerializeField] internal ManaCounterView polygonManaCounterView;
 58
 59    [Header("Tutorial Config")]
 60    [SerializeField] internal RectTransform tutorialTooltipReference;
 61
 62    [Header("Description")]
 63    [SerializeField] internal TMP_InputField descriptionEditionInput;
 64    [SerializeField] internal GameObject charLimitDescriptionContainer;
 65    [SerializeField] internal TextMeshProUGUI textCharLimitDescription;
 66    [SerializeField] internal GameObject descriptionContainer;
 67
 68    public event EventHandler ClaimNamePressed;
 69    public event EventHandler SignedUpPressed;
 70    public event EventHandler LogedOutPressed;
 71    public event EventHandler Opened;
 72    public event EventHandler Closed;
 73    public event EventHandler<string> NameSubmitted;
 74    public event EventHandler<string> DescriptionSubmitted;
 75    public event EventHandler ManaInfoPressed;
 76    public event EventHandler ManaPurchasePressed;
 77    public event EventHandler TermsAndServicesPressed;
 78    public event EventHandler PrivacyPolicyPressed;
 79
 80    internal bool isStartMenuInitialized = false;
 81
 82    private InputAction_Trigger.Triggered closeActionDelegate;
 83    private Coroutine copyToastRoutine = null;
 84    private UserProfile profile = null;
 85
 86    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 87
 088    public GameObject GameObject => gameObject;
 089    public RectTransform ExpandedMenu => mainRootLayout;
 090    public RectTransform MyAccountCardLayout => null;
 091    public RectTransform MyAccountCardMenu => null;
 092    public MyAccountCardComponentView MyAccountCardView => null;
 093    public RectTransform TutorialReference => tutorialTooltipReference;
 94
 95
 096    public override void RefreshControl() { }
 97
 098    public bool HasManaCounterView() => manaCounterView != null;
 99
 0100    public bool HasPolygonManaCounterView() => polygonManaCounterView != null;
 101
 0102    public bool IsDesciptionIsLongerThanMaxCharacters() => descriptionEditionInput.characterLimit < descriptionEditionIn
 103
 0104    public void SetManaBalance(string balance) => manaCounterView.SetBalance(balance);
 105
 0106    public void SetPolygonBalance(double balance) => polygonManaCounterView.SetBalance(balance);
 107
 0108    public void SetWalletSectionEnabled(bool isEnabled) => connectedWalletSection.SetActive(isEnabled);
 109
 0110    public void SetNonWalletSectionEnabled(bool isEnabled) => nonConnectedWalletSection.SetActive(isEnabled);
 111
 0112    public void SetStartMenuButtonActive(bool isActive) => isStartMenuInitialized = isActive;
 113
 114    public void ShowProfileIcon(bool show)
 115    {
 0116        profilePicObject.SetActive(show);
 0117    }
 118
 119    public void ShowExpanded(bool show, bool showMyAccountVersion = false)
 120    {
 0121        expandedObject.SetActive(show);
 0122        if (show && profile)
 0123            UpdateLayoutByProfile(profile);
 0124    }
 125
 126    public void SetProfile(UserProfile userProfile)
 127    {
 0128        profile = userProfile;
 0129        UpdateLayoutByProfile(userProfile);
 0130    }
 131
 132
 0133    private void OnEnable() => closeAction.OnTriggered += closeActionDelegate;
 134
 0135    private void OnDisable() => closeAction.OnTriggered -= closeActionDelegate;
 136
 137    private void Awake()
 138    {
 0139        buttonLogOut.onClick.AddListener(() => LogedOutPressed?.Invoke(this, EventArgs.Empty));
 0140        buttonSignUp.onClick.AddListener(() => SignedUpPressed?.Invoke(this, EventArgs.Empty));
 0141        buttonClaimName.onClick.AddListener(() => ClaimNamePressed?.Invoke(this, EventArgs.Empty));
 142
 0143        buttonTermsOfServiceForConnectedWallets.onClick.AddListener(() => TermsAndServicesPressed?.Invoke(this, EventArg
 0144        buttonTermsOfServiceForNonConnectedWallets.onClick.AddListener(() => TermsAndServicesPressed?.Invoke(this, Event
 0145        buttonPrivacyPolicyForConnectedWallets.onClick.AddListener(() => PrivacyPolicyPressed?.Invoke(this, EventArgs.Em
 0146        buttonPrivacyPolicyForNonConnectedWallets.onClick.AddListener(() => PrivacyPolicyPressed?.Invoke(this, EventArgs
 147
 0148        manaCounterView.buttonManaInfo.onClick.AddListener(() => ManaInfoPressed?.Invoke(this, EventArgs.Empty));
 0149        polygonManaCounterView.buttonManaInfo.onClick.AddListener(() => ManaInfoPressed?.Invoke(this, EventArgs.Empty));
 0150        manaCounterView.buttonManaPurchase.onClick.AddListener(() => ManaPurchasePressed?.Invoke(this, EventArgs.Empty))
 0151        polygonManaCounterView.buttonManaPurchase.onClick.AddListener(() => ManaPurchasePressed?.Invoke(this, EventArgs.
 152
 0153        buttonToggleMenu.onClick.AddListener(OpenStartMenu);
 0154        buttonCopyAddress.onClick.AddListener(CopyAddress);
 0155        buttonEditName.onPointerDown += () => ActivateProfileNameEditionMode(true);
 0156        buttonEditNamePrefix.onPointerDown += () => ActivateProfileNameEditionMode(true);
 0157        inputName.onValueChanged.AddListener(UpdateNameCharLimit);
 0158        inputName.onEndEdit.AddListener(x =>
 159        {
 0160            inputName.OnDeselect(null);
 0161        });
 0162        inputName.onDeselect.AddListener(x =>
 163        {
 0164            ActivateProfileNameEditionMode(false);
 0165            NameSubmitted?.Invoke(this, x);
 0166        });
 167
 0168        descriptionEditionInput.onTextSelection.AddListener((description, x, y) =>
 169        {
 0170            SetDescriptionIsEditing(true);
 0171            UpdateDescriptionCharLimit(description);
 0172        });
 0173        descriptionEditionInput.onSelect.AddListener(description =>
 174        {
 0175            SetDescriptionIsEditing(true);
 0176            UpdateDescriptionCharLimit(description);
 0177        });
 0178        descriptionEditionInput.onValueChanged.AddListener(description =>
 179        {
 0180            UpdateDescriptionCharLimit(description);
 0181        });
 0182        descriptionEditionInput.onEndEdit.AddListener(description =>
 183        {
 0184            descriptionEditionInput.OnDeselect(null);
 0185        });
 0186        descriptionEditionInput.onDeselect.AddListener(description =>
 187        {
 0188            SetDescriptionIsEditing(false);
 0189            DescriptionSubmitted?.Invoke(this, description);
 0190        });
 0191        copyToast.gameObject.SetActive(false);
 0192        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 0193    }
 194
 195    private void UpdateLayoutByProfile(UserProfile userProfile)
 196    {
 0197        if (userProfile.hasClaimedName)
 0198            HandleClaimedProfileName(userProfile);
 199        else
 0200            HandleUnverifiedProfileName(userProfile);
 201
 0202        SetConnectedWalletSectionActive(userProfile.hasConnectedWeb3);
 0203        HandleProfileAddress(userProfile);
 0204        HandleProfileSnapshot(userProfile);
 0205        SetDescription(userProfile.description);
 0206        SetDescriptionEnabled(userProfile.hasConnectedWeb3);
 0207    }
 208
 0209    private void UpdateNameCharLimit(string newValue) => textCharLimit.text = $"{newValue.Length}/{inputName.characterLi
 210
 211    private void UpdateDescriptionCharLimit(string newValue) =>
 0212        textCharLimitDescription.text = $"{newValue.Length}/{descriptionEditionInput.characterLimit}";
 213
 214    private void SetDescriptionEnabled(bool enabled)
 215    {
 0216        if (descriptionContainer.activeSelf != enabled)
 0217            StartCoroutine(EnableNextFrame(descriptionContainer, enabled));
 0218    }
 219
 220    private void OpenStartMenu()
 221    {
 0222        if (isStartMenuInitialized)
 223        {
 0224            if (!DataStore.i.exploreV2.isOpen.Get())
 225            {
 0226                var exploreV2Analytics = new ExploreV2Analytics.ExploreV2Analytics();
 0227                exploreV2Analytics.SendStartMenuVisibility(true, ExploreUIVisibilityMethod.FromClick);
 228            }
 0229            DataStore.i.exploreV2.isOpen.Set(true);
 230        }
 0231    }
 232
 233    private void HandleProfileSnapshot(UserProfile userProfile)
 234    {
 0235        loadingSpinner.SetActive(true);
 0236        userProfile.snapshotObserver.AddListener(SetProfileImage);
 0237    }
 238
 239    private void HandleClaimedProfileName(UserProfile userProfile)
 240    {
 0241        textName.text = userProfile.userName;
 0242        SetActiveUnverifiedNameGOs(false);
 0243    }
 244
 245    private void HandleUnverifiedProfileName(UserProfile userProfile)
 246    {
 0247        textName.text = string.IsNullOrEmpty(userProfile.userName) || userProfile.userName.Length <= NAME_POSTFIX_LENGTH
 248            ? userProfile.userName
 249            : userProfile.userName.Substring(0, userProfile.userName.Length - NAME_POSTFIX_LENGTH - 1);
 250
 0251        textPostfix.text = $"#{userProfile.userId.Substring(userProfile.userId.Length - NAME_POSTFIX_LENGTH)}";
 0252        SetActiveUnverifiedNameGOs(true);
 0253    }
 254
 255    private void SetConnectedWalletSectionActive(bool active)
 256    {
 0257        connectedWalletSection.SetActive(active);
 0258        nonConnectedWalletSection.SetActive(!active);
 0259        buttonLogOut.gameObject.SetActive(active);
 0260    }
 261
 262    private void SetActiveUnverifiedNameGOs(bool active)
 263    {
 0264        for (int i = 0; i < hideOnNameClaimed.Length; i++)
 0265            hideOnNameClaimed[i].SetActive(active);
 0266    }
 267
 268    private void HandleProfileAddress(UserProfile userProfile)
 269    {
 0270        string address = userProfile.userId;
 0271        string start = address.Substring(0, ADDRESS_CHUNK_LENGTH);
 0272        string end = address.Substring(address.Length - ADDRESS_CHUNK_LENGTH);
 0273        textAddress.text = $"{start}...{end}";
 0274    }
 275
 276    private void SetProfileImage(Texture2D texture)
 277    {
 0278        loadingSpinner.SetActive(false);
 0279        imageAvatarThumbnail.texture = texture;
 0280    }
 281
 282    private void OnDestroy()
 283    {
 0284        hudCanvasCameraModeController?.Dispose();
 0285        if (profile)
 0286            profile.snapshotObserver.RemoveListener(SetProfileImage);
 0287    }
 288
 289    private void CopyAddress()
 290    {
 0291        if (!profile)
 0292            return;
 293
 0294        Environment.i.platform.clipboard.WriteText(profile.userId);
 295
 0296        copyTooltip.SetActive(false);
 0297        if (copyToastRoutine != null)
 0298            StopCoroutine(copyToastRoutine);
 299
 0300        copyToastRoutine = StartCoroutine(ShowCopyToast());
 0301    }
 302
 303    private IEnumerator ShowCopyToast()
 304    {
 0305        if (!copyToast.gameObject.activeSelf)
 0306            copyToast.gameObject.SetActive(true);
 307
 0308        copyToast.Show();
 0309        yield return new WaitForSeconds(COPY_TOAST_VISIBLE_TIME);
 0310        copyToast.Hide();
 0311    }
 312
 313    internal void ActivateProfileNameEditionMode(bool activate)
 314    {
 0315        if (profile != null && profile.hasClaimedName)
 0316            return;
 317
 0318        textName.gameObject.SetActive(!activate);
 0319        inputName.gameObject.SetActive(activate);
 320
 0321        if (activate)
 322        {
 0323            inputName.text = textName.text;
 0324            inputName.Select();
 325        }
 0326    }
 327
 328    public void SetDescriptionIsEditing(bool isEditing)
 329    {
 0330        if (charLimitDescriptionContainer.activeSelf != isEditing)
 0331            StartCoroutine(EnableNextFrame(charLimitDescriptionContainer, isEditing));
 0332    }
 333
 334    private void SetDescription(string description)
 335    {
 0336        if (descriptionEditionInput.text != description)
 0337            descriptionEditionInput.text = description;
 0338    }
 339
 340    private IEnumerator EnableNextFrame(GameObject go, bool shouldEnable)
 341    {
 0342        yield return null;
 0343        go.SetActive(shouldEnable);
 0344    }
 345}