< 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:97
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()} is requesting the signature of a 
 71                                $"If you are interested, please click the Allow button to receive it in your Wallet Conn
 72                                $"This action does not imply message approval.";
 73        }
 474    }
 75
 76    public void Show(Model model)
 77    {
 478        if (Utils.IsCursorLocked)
 079            Utils.UnlockCursor();
 80
 481        this.model = model;
 82
 483        ShowSignMessage(model);
 484    }
 85
 86    public void AcceptTransaction()
 87    {
 088        OnTransactionAccepted?.Invoke(this);
 089        Destroy(gameObject);
 090    }
 91
 92    public void RejectTransaction()
 93    {
 094        OnTransactionRejected?.Invoke(this);
 095        Destroy(gameObject);
 096    }
 97}