< Summary

Class:OwnerInfoElement
Assembly:NFTPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnerInfoElement.cs
Covered lines:1
Uncovered lines:21
Coverable lines:22
Total lines:75
Line coverage:4.5% (1 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OwnerInfoElement()0%110100%
SetOwner(...)0%2100%
SetAddressLength(...)0%6200%
SetColorIndex(...)0%2100%
SetParent(...)0%2100%
SetConfig(...)0%2100%
SetActive(...)0%2100%
Dispose()0%6200%
OnDestroy()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnerInfoElement.cs

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6using Random = UnityEngine.Random;
 7
 8internal interface IOwnerInfoElement : IDisposable
 9{
 10    void SetOwner(string address);
 11    void SetAddressLength(int length);
 12    void SetColorIndex(int index);
 13    void SetParent(Transform parent);
 14    void SetActive(bool active);
 15    void SetConfig(float fontSize, float horizontalSpacing);
 16}
 17
 18internal class OwnerInfoElement : MonoBehaviour, IOwnerInfoElement
 19{
 20    private const int DEFAULT_ADDRESS_MAX_CHARS = 11;
 21
 22    [SerializeField] private TextMeshProUGUI textOwner;
 23    [SerializeField] private Image imageEllipse;
 24    [SerializeField] private HorizontalLayoutGroup horizontalLayout;
 25    [SerializeField] private Color[] colorsEllipse;
 26
 27    private bool isDestroyed = false;
 28    private string address;
 129    private int lastAddressLength = DEFAULT_ADDRESS_MAX_CHARS;
 30
 31    void IOwnerInfoElement.SetOwner(string ownerAddress)
 32    {
 033        address = ownerAddress;
 034        textOwner.text = NFTPromptHUDController.FormatOwnerAddress(ownerAddress, lastAddressLength);
 035    }
 36
 37    void IOwnerInfoElement.SetAddressLength(int length)
 38    {
 039        lastAddressLength = length;
 040        if (textOwner.text.Length != length)
 41        {
 042            textOwner.text = NFTPromptHUDController.FormatOwnerAddress(address, lastAddressLength);
 43        }
 044    }
 45
 46    void IOwnerInfoElement.SetColorIndex(int index)
 47    {
 048        int colorIndex = index % colorsEllipse.Length;
 049        imageEllipse.color = colorsEllipse[colorIndex];
 050    }
 51
 52    void IOwnerInfoElement.SetParent(Transform parent)
 53    {
 054        transform.SetParent(parent);
 055        transform.ResetLocalTRS();
 056    }
 57
 58    void IOwnerInfoElement.SetConfig(float fontSize, float horizontalSpacing)
 59    {
 060        textOwner.fontSize = fontSize;
 061        horizontalLayout.spacing = horizontalSpacing;
 062    }
 63
 064    void IOwnerInfoElement.SetActive(bool active) { gameObject.SetActive(active); }
 65
 66    public void Dispose()
 67    {
 068        if (!isDestroyed)
 69        {
 070            Destroy(gameObject);
 71        }
 072    }
 73
 074    private void OnDestroy() { isDestroyed = true; }
 75}