< Summary

Class:TransactionHUD
Assembly:TransactionHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TransactionHUD/TransactionHUD.cs
Covered lines:40
Uncovered lines:14
Coverable lines:54
Total lines:139
Line coverage:74% (40 of 54)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TransactionHUD()0%110100%
OnEnable()0%330100%
FindScene(...)0%358025%
OnDisable()0%330100%
ShortAddress(...)0%3.073080%
ShowTransferMessage(...)0%22090.91%
ShowSignMessage(...)0%2.012087.5%
Show(...)0%3.033085.71%
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 GameObject paymentPanel;
 15
 16    [SerializeField] private GameObject signPanel;
 17
 18    [SerializeField] private List<Button> acceptButtons;
 19
 20    [SerializeField] private List<Button> rejectButtons;
 21
 22    [SerializeField] private TMP_Text amountLabel;
 23
 24    [SerializeField] private TMP_Text fromAddressLabel;
 25
 26    [SerializeField] private TMP_Text toAddressLabel;
 27
 28    [SerializeField] private TMP_Text messageLabel;
 29
 30    [SerializeField] private TMP_Text paymentPanelTitle;
 31
 32    [SerializeField] private TMP_Text signPanelTitle;
 33
 34    [SerializeField] private TMP_Text paymentNetworkLabel;
 35
 36    [SerializeField] private TMP_Text signNetworkLabel;
 37
 538    public Model model { get; private set; } = new Model();
 39
 40    public event Action<ITransactionHUD> OnTransactionAccepted;
 41
 42    public event Action<ITransactionHUD> OnTransactionRejected;
 43
 44    private void OnEnable()
 45    {
 2446        foreach (var acceptButton in acceptButtons)
 847            acceptButton.onClick.AddListener(AcceptTransaction);
 48
 2449        foreach (var rejectButton in rejectButtons)
 850            rejectButton.onClick.AddListener(RejectTransaction);
 451    }
 52
 53    public IParcelScene FindScene(string sceneId)
 54    {
 455        if (DCL.Environment.i.world?.state?.scenesSortedByDistance != null)
 56        {
 057            foreach (IParcelScene scene in DCL.Environment.i.world.state.scenesSortedByDistance)
 58            {
 059                if (scene.sceneData.id == sceneId)
 060                    return scene;
 61            }
 62        }
 63
 464        return null;
 065    }
 66
 67    private void OnDisable()
 68    {
 2469        foreach (var acceptButton in acceptButtons)
 870            acceptButton.onClick.RemoveAllListeners();
 71
 2472        foreach (var rejectButton in rejectButtons)
 873            rejectButton.onClick.RemoveAllListeners();
 474    }
 75
 76    private static string ShortAddress(string address)
 77    {
 278        if (address == null)
 179            return "Null";
 80
 181        if (address.Length >= 12)
 182            return $"{address.Substring(0, 6)}...{address.Substring(address.Length - 4)}";
 83
 084        return address;
 85    }
 86
 87    private void ShowTransferMessage(Model model)
 88    {
 189        var scene = FindScene(model.sceneId);
 90
 191        if (scene != null)
 092            paymentPanelTitle.text = $"'{scene.GetSceneName()}', {scene.sceneData.basePosition.ToString()} wants to init
 193        paymentPanel.SetActive(true);
 194        signPanel.SetActive(false);
 95
 196        UserProfile ownUserProfile = UserProfile.GetOwnUserProfile();
 197        fromAddressLabel.text = ShortAddress(ownUserProfile.ethAddress);
 198        toAddressLabel.text = ShortAddress(model.toAddress);
 199        amountLabel.text = $"{model.amount} {model.currency}";
 1100        paymentNetworkLabel.text = KernelConfig.i.Get().network.ToUpper();
 1101    }
 102
 103    private void ShowSignMessage(Model model)
 104    {
 3105        var scene = FindScene(model.sceneId);
 106
 3107        if (scene != null)
 0108            signPanelTitle.text = $"'{scene.GetSceneName()}', {scene.sceneData.basePosition.ToString()} wants to sign th
 3109        paymentPanel.SetActive(false);
 3110        signPanel.SetActive(true);
 3111        signNetworkLabel.text = KernelConfig.i.Get().network.ToUpper();
 3112        messageLabel.text = model.message;
 3113    }
 114
 115    public void Show(Model model)
 116    {
 4117        if (Utils.IsCursorLocked)
 0118            Utils.UnlockCursor();
 119
 4120        this.model = model;
 121
 4122        if (model.requestType == Type.REQUIRE_PAYMENT)
 1123            ShowTransferMessage(model);
 124        else
 3125            ShowSignMessage(model);
 3126    }
 127
 128    public void AcceptTransaction()
 129    {
 0130        OnTransactionAccepted?.Invoke(this);
 0131        Destroy(gameObject);
 0132    }
 133
 134    public void RejectTransaction()
 135    {
 0136        OnTransactionRejected?.Invoke(this);
 0137        Destroy(gameObject);
 0138    }
 139}