| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Controllers; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | | using DCL.TransactionHUDModel; |
| | 9 | | using UnityEngine.SocialPlatforms.Impl; |
| | 10 | | using Type = DCL.TransactionHUDModel.Type; |
| | 11 | |
|
| | 12 | | public class TransactionHUD : MonoBehaviour, ITransactionHUD |
| | 13 | | { |
| | 14 | | [SerializeField] private Button acceptButton; |
| | 15 | |
|
| | 16 | | [SerializeField] private Button rejectButton; |
| | 17 | |
|
| | 18 | | [SerializeField] private TMP_Text messageLabel; |
| | 19 | |
|
| 5 | 20 | | 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 | | { |
| 4 | 28 | | acceptButton.onClick.AddListener(AcceptTransaction); |
| | 29 | |
|
| 4 | 30 | | rejectButton.onClick.AddListener(RejectTransaction); |
| 4 | 31 | | } |
| | 32 | |
|
| | 33 | | public IParcelScene FindScene(string sceneId) |
| | 34 | | { |
| 4 | 35 | | DCL.Environment.i.world.state.TryGetScene(sceneId, out var scene); |
| 4 | 36 | | return scene; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | private void OnDisable() |
| | 40 | | { |
| 4 | 41 | | acceptButton.onClick.RemoveAllListeners(); |
| 4 | 42 | | rejectButton.onClick.RemoveAllListeners(); |
| 4 | 43 | | } |
| | 44 | |
|
| | 45 | | private static string ShortAddress(string address) |
| | 46 | | { |
| 0 | 47 | | if (address == null) |
| 0 | 48 | | return "Null"; |
| | 49 | |
|
| 0 | 50 | | if (address.Length >= 12) |
| 0 | 51 | | return $"{address.Substring(0, 6)}...{address.Substring(address.Length - 4)}"; |
| | 52 | |
|
| 0 | 53 | | return address; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | private void ShowSignMessage(Model model) |
| | 57 | | { |
| 4 | 58 | | var scene = FindScene(model.sceneId); |
| | 59 | |
|
| 4 | 60 | | if (scene != null) |
| | 61 | | { |
| 0 | 62 | | 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 | | } |
| 4 | 66 | | } |
| | 67 | |
|
| | 68 | | public void Show(Model model) |
| | 69 | | { |
| 4 | 70 | | if (Utils.IsCursorLocked) |
| 0 | 71 | | Utils.UnlockCursor(); |
| | 72 | |
|
| 4 | 73 | | this.model = model; |
| | 74 | |
|
| 4 | 75 | | ShowSignMessage(model); |
| 4 | 76 | | } |
| | 77 | |
|
| | 78 | | public void AcceptTransaction() |
| | 79 | | { |
| 0 | 80 | | OnTransactionAccepted?.Invoke(this); |
| 0 | 81 | | Destroy(gameObject); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | public void RejectTransaction() |
| | 85 | | { |
| 0 | 86 | | OnTransactionRejected?.Invoke(this); |
| 0 | 87 | | Destroy(gameObject); |
| 0 | 88 | | } |
| | 89 | | } |