< 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:13
Coverable lines:29
Total lines:89
Line coverage:55.1% (16 of 29)
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%110100%
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
 2220    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(int sceneNumber)
 34    {
 435        DCL.Environment.i.world.state.TryGetScene(sceneNumber, out var scene);
 436        return scene;
 37    }
 38
 39    private void OnDisable()
 40    {
 441        acceptButton.onClick.RemoveAllListeners();
 442        rejectButton.onClick.RemoveAllListeners();
 443    }
 44
 45    private static string ShortAddress(string address)
 46    {
 047        if (address == null)
 048            return "Null";
 49
 050        if (address.Length >= 12)
 051            return $"{address.Substring(0, 6)}...{address.Substring(address.Length - 4)}";
 52
 053        return address;
 54    }
 55
 56    private void ShowSignMessage(Model model)
 57    {
 458        var scene = FindScene(model.sceneNumber);
 59
 460        if (scene != null)
 61        {
 062            messageLabel.text = $"This scene {scene.sceneData.basePosition.ToString()} is requesting the signature of a 
 63                                $"If you are interested, please click the Allow button to receive it in your Wallet Conn
 64                                $"This action does not imply message approval.";
 65        }
 466    }
 67
 68    public void Show(Model model)
 69    {
 470        if (Utils.IsCursorLocked)
 071            Utils.UnlockCursor();
 72
 473        this.model = model;
 74
 475        ShowSignMessage(model);
 476    }
 77
 78    public void AcceptTransaction()
 79    {
 080        OnTransactionAccepted?.Invoke(this);
 081        Destroy(gameObject);
 082    }
 83
 84    public void RejectTransaction()
 85    {
 086        OnTransactionRejected?.Invoke(this);
 087        Destroy(gameObject);
 088    }
 89}