< Summary

Class:TransactionHUD
Assembly:TransactionHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TransactionHUD/TransactionHUD.cs
Covered lines:16
Uncovered lines:17
Coverable lines:33
Total lines:95
Line coverage:48.4% (16 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TransactionHUD()0%110100%
OnEnable()0%110100%
FindScene(...)0%358025%
OnDisable()0%110100%
ShortAddress(...)0%12300%
ShowSignMessage(...)0%2.062075%
Show(...)0%2.032080%
AcceptTransaction()0%6200%
RejectTransaction()0%6200%

File(s)

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

#LineLine coverage
 1using System;
 2using TMPro;
 3using System.Collections.Generic;
 4using DCL.Controllers;
 5using DCL.Helpers;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using DCL.TransactionHUDModel;
 9using UnityEngine.SocialPlatforms.Impl;
 10using Type = DCL.TransactionHUDModel.Type;
 11
 12public class TransactionHUD : MonoBehaviour, ITransactionHUD
 13{
 14    [SerializeField] private Button acceptButton;
 15
 16    [SerializeField] private Button rejectButton;
 17
 18    [SerializeField] private TMP_Text messageLabel;
 19
 520    public Model model { get; private set; } = new Model();
 21
 22    public event Action<ITransactionHUD> OnTransactionAccepted;
 23
 24    public event Action<ITransactionHUD> OnTransactionRejected;
 25
 26    private void OnEnable()
 27    {
 428        acceptButton.onClick.AddListener(AcceptTransaction);
 29
 430        rejectButton.onClick.AddListener(RejectTransaction);
 431    }
 32
 33    public IParcelScene FindScene(string sceneId)
 34    {
 435        if (DCL.Environment.i.world?.state?.scenesSortedByDistance != null)
 36        {
 037            foreach (IParcelScene scene in DCL.Environment.i.world.state.scenesSortedByDistance)
 38            {
 039                if (scene.sceneData.id == sceneId)
 040                    return scene;
 41            }
 42        }
 43
 444        return null;
 045    }
 46
 47    private void OnDisable()
 48    {
 449        acceptButton.onClick.RemoveAllListeners();
 450        rejectButton.onClick.RemoveAllListeners();
 451    }
 52
 53    private static string ShortAddress(string address)
 54    {
 055        if (address == null)
 056            return "Null";
 57
 058        if (address.Length >= 12)
 059            return $"{address.Substring(0, 6)}...{address.Substring(address.Length - 4)}";
 60
 061        return address;
 62    }
 63
 64    private void ShowSignMessage(Model model)
 65    {
 466        var scene = FindScene(model.sceneId);
 67
 468        if (scene != null)
 69        {
 070            messageLabel.text = $"This scene {scene.sceneData.basePosition.ToString()} wants you to sign a message. Pres
 71        }
 472    }
 73
 74    public void Show(Model model)
 75    {
 476        if (Utils.IsCursorLocked)
 077            Utils.UnlockCursor();
 78
 479        this.model = model;
 80
 481        ShowSignMessage(model);
 482    }
 83
 84    public void AcceptTransaction()
 85    {
 086        OnTransactionAccepted?.Invoke(this);
 087        Destroy(gameObject);
 088    }
 89
 90    public void RejectTransaction()
 91    {
 092        OnTransactionRejected?.Invoke(this);
 093        Destroy(gameObject);
 094    }
 95}