< Summary

Class:DCL.Wallet.WalletSectionHUDComponentView
Assembly:WalletHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WalletHUD/WalletSectionHUDComponentView.cs
Covered lines:38
Uncovered lines:34
Coverable lines:72
Total lines:166
Line coverage:52.7% (38 of 72)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:15
Method coverage:66.6% (10 of 15)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Dispose()0%110100%
RefreshControl()0%2100%
SetAsFullScreenMenuMode(...)0%12300%
SetWalletSectionAsGuest(...)0%110100%
SetWalletAddress(...)0%110100%
SetEthereumManaLoadingActive(...)0%110100%
SetEthereumManaBalance(...)0%110100%
SetPolygonManaLoadingActive(...)0%110100%
SetPolygonManaBalance(...)0%110100%
OnPointerClick(...)0%6200%
CopyWalletAddress()0%3.073080%
ShowCopyToast()0%4.594066.67%
CheckClickOnLearnMoreLink(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WalletHUD/WalletSectionHUDComponentView.cs

#LineLine coverage
 1using DCL.Guests.HUD.ConnectWallet;
 2using System;
 3using System.Collections;
 4using TMPro;
 5using UIComponents.Scripts.Components;
 6using UnityEngine;
 7using UnityEngine.EventSystems;
 8using UnityEngine.UI;
 9
 10namespace DCL.Wallet
 11{
 12    public class WalletSectionHUDComponentView : BaseComponentView<WalletSectionHUDModel>, IWalletSectionHUDComponentVie
 13    {
 14        private const float COPY_TOAST_VISIBLE_TIME = 3;
 15        private const string LEARN_MORE_LINK_ID = "learn_more";
 16
 17        [SerializeField] internal GameObject signedInWalletContainer;
 18        [SerializeField] internal GameObject guestContainer;
 19        [SerializeField] internal ConnectWalletComponentView connectWalletView;
 20        [SerializeField] internal TMP_Text walletAddressText;
 21        [SerializeField] internal Button copyWalletAddressButton;
 22        [SerializeField] internal ShowHideAnimator copyWalletAddressToast;
 23        [SerializeField] internal TMP_Text ethereumManaLearnMoreText;
 24        [SerializeField] internal Button buyEthereumManaButton;
 25        [SerializeField] internal TMP_Text polygonManaLearnMoreText;
 26        [SerializeField] internal Button buyPolygonManaButton;
 27        [SerializeField] internal TMP_Text ethereumManaBalanceText;
 28        [SerializeField] internal GameObject ethereumManaBalanceLoading;
 29        [SerializeField] internal TMP_Text polygonManaBalanceText;
 30        [SerializeField] internal GameObject polygonManaBalanceLoading;
 31
 32        public event Action OnCopyWalletAddress;
 33        public event Action<bool> OnBuyManaClicked;
 34        public event Action OnLearnMoreClicked;
 35
 036        public IConnectWalletComponentView currentConnectWalletView => connectWalletView;
 37
 38        private Transform thisTransform;
 39        private Coroutine copyToastRoutine;
 40
 41        public override void Awake()
 42        {
 1443            base.Awake();
 44
 1445            thisTransform = transform;
 46
 1447            copyWalletAddressButton.onClick.AddListener(CopyWalletAddress);
 1548            buyEthereumManaButton.onClick.AddListener(() => OnBuyManaClicked?.Invoke(false));
 1549            buyPolygonManaButton.onClick.AddListener(() => OnBuyManaClicked?.Invoke(true));
 1450        }
 51
 52        public override void Dispose()
 53        {
 2854            copyWalletAddressButton.onClick.RemoveAllListeners();
 2855            buyEthereumManaButton.onClick.RemoveAllListeners();
 2856            buyPolygonManaButton.onClick.RemoveAllListeners();
 57
 2858            base.Dispose();
 2859        }
 60
 61        public override void RefreshControl()
 62        {
 063            SetWalletSectionAsGuest(model.IsGuest);
 064            SetWalletAddress(model.WalletAddress);
 065            SetEthereumManaBalance(model.EthereumManaBalance);
 066            SetPolygonManaBalance(model.PolygonManaBalance);
 067        }
 68
 69        public void SetAsFullScreenMenuMode(Transform parentTransform)
 70        {
 071            if (parentTransform == null)
 072                return;
 73
 074            thisTransform.SetParent(parentTransform);
 075            thisTransform.localScale = Vector3.one;
 76
 077            RectTransform rectTransform = thisTransform as RectTransform;
 078            if (rectTransform == null) return;
 079            rectTransform.anchorMin = Vector2.zero;
 080            rectTransform.anchorMax = Vector2.one;
 081            rectTransform.pivot = new Vector2(0.5f, 0.5f);
 082            rectTransform.localPosition = Vector2.zero;
 083            rectTransform.offsetMax = Vector2.zero;
 084            rectTransform.offsetMin = Vector2.zero;
 085        }
 86
 87        public void SetWalletSectionAsGuest(bool isGuest)
 88        {
 289            model.IsGuest = isGuest;
 290            signedInWalletContainer.SetActive(!isGuest);
 291            guestContainer.SetActive(isGuest);
 292        }
 93
 94        public void SetWalletAddress(string fullWalletAddress)
 95        {
 196            model.WalletAddress = fullWalletAddress;
 197            walletAddressText.text = fullWalletAddress;
 198        }
 99
 100        public void SetEthereumManaLoadingActive(bool isActive)
 101        {
 2102            ethereumManaBalanceText.gameObject.SetActive(!isActive);
 2103            ethereumManaBalanceLoading.SetActive(isActive);
 2104        }
 105
 106        public void SetEthereumManaBalance(double balance)
 107        {
 2108            model.EthereumManaBalance = balance;
 2109            ethereumManaBalanceText.text = WalletUtils.FormatBalanceToString(balance);
 2110        }
 111
 112        public void SetPolygonManaLoadingActive(bool isActive)
 113        {
 2114            polygonManaBalanceText.gameObject.SetActive(!isActive);
 2115            polygonManaBalanceLoading.SetActive(isActive);
 2116        }
 117
 118        public void SetPolygonManaBalance(double balance)
 119        {
 2120            model.PolygonManaBalance = balance;
 2121            polygonManaBalanceText.text = WalletUtils.FormatBalanceToString(balance);
 2122        }
 123
 124        public void OnPointerClick(PointerEventData eventData)
 125        {
 0126            if (CheckClickOnLearnMoreLink(ethereumManaLearnMoreText))
 0127                return;
 128
 0129            CheckClickOnLearnMoreLink(polygonManaLearnMoreText);
 0130        }
 131
 132        private void CopyWalletAddress()
 133        {
 1134            if (copyToastRoutine != null)
 0135                StopCoroutine(copyToastRoutine);
 136
 1137            copyToastRoutine = StartCoroutine(ShowCopyToast());
 138
 1139            OnCopyWalletAddress?.Invoke();
 1140        }
 141
 142        private IEnumerator ShowCopyToast()
 143        {
 1144            if (!copyWalletAddressToast.gameObject.activeSelf)
 1145                copyWalletAddressToast.gameObject.SetActive(true);
 146
 1147            copyWalletAddressToast.Show();
 1148            yield return new WaitForSeconds(COPY_TOAST_VISIBLE_TIME);
 0149            copyWalletAddressToast.Hide();
 0150        }
 151
 152        private bool CheckClickOnLearnMoreLink(TMP_Text textToCheck)
 153        {
 0154            int linkIndex = TMP_TextUtilities.FindIntersectingLink(textToCheck, Input.mousePosition, textToCheck.canvas.
 0155            if (linkIndex == -1)
 0156                return false;
 157
 0158            TMP_LinkInfo linkInfo = textToCheck.textInfo.linkInfo[linkIndex];
 0159            if (linkInfo.GetLinkID() != LEARN_MORE_LINK_ID)
 0160                return false;
 161
 0162            OnLearnMoreClicked?.Invoke();
 0163            return true;
 164        }
 165    }
 166}