| | 1 | | using DCL.Guests.HUD.ConnectWallet; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using TMPro; |
| | 5 | | using UIComponents.Scripts.Components; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.EventSystems; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | namespace DCL.Wallet |
| | 11 | | { |
| | 12 | | public class WalletSectionHUDComponentView : BaseComponentView<WalletSectionHUDModel>, IWalletSectionHUDComponentVie |
| | 13 | | { |
| | 14 | | private const float COPY_TOAST_VISIBLE_TIME = 3; |
| | 15 | | private const string LEARN_MORE_LINK_ID = "learn_more"; |
| | 16 | |
|
| | 17 | | [SerializeField] internal GameObject signedInWalletContainer; |
| | 18 | | [SerializeField] internal GameObject guestContainer; |
| | 19 | | [SerializeField] internal ConnectWalletComponentView connectWalletView; |
| | 20 | | [SerializeField] internal TMP_Text walletAddressText; |
| | 21 | | [SerializeField] internal Button copyWalletAddressButton; |
| | 22 | | [SerializeField] internal ShowHideAnimator copyWalletAddressToast; |
| | 23 | | [SerializeField] internal TMP_Text ethereumManaLearnMoreText; |
| | 24 | | [SerializeField] internal Button buyEthereumManaButton; |
| | 25 | | [SerializeField] internal TMP_Text polygonManaLearnMoreText; |
| | 26 | | [SerializeField] internal Button buyPolygonManaButton; |
| | 27 | | [SerializeField] internal TMP_Text ethereumManaBalanceText; |
| | 28 | | [SerializeField] internal GameObject ethereumManaBalanceLoading; |
| | 29 | | [SerializeField] internal TMP_Text polygonManaBalanceText; |
| | 30 | | [SerializeField] internal GameObject polygonManaBalanceLoading; |
| | 31 | |
|
| | 32 | | public event Action OnCopyWalletAddress; |
| | 33 | | public event Action<bool> OnBuyManaClicked; |
| | 34 | | public event Action OnLearnMoreClicked; |
| | 35 | |
|
| 0 | 36 | | public IConnectWalletComponentView currentConnectWalletView => connectWalletView; |
| | 37 | |
|
| | 38 | | private Transform thisTransform; |
| | 39 | | private Coroutine copyToastRoutine; |
| | 40 | |
|
| | 41 | | public override void Awake() |
| | 42 | | { |
| 14 | 43 | | base.Awake(); |
| | 44 | |
|
| 14 | 45 | | thisTransform = transform; |
| | 46 | |
|
| 14 | 47 | | copyWalletAddressButton.onClick.AddListener(CopyWalletAddress); |
| 15 | 48 | | buyEthereumManaButton.onClick.AddListener(() => OnBuyManaClicked?.Invoke(false)); |
| 15 | 49 | | buyPolygonManaButton.onClick.AddListener(() => OnBuyManaClicked?.Invoke(true)); |
| 14 | 50 | | } |
| | 51 | |
|
| | 52 | | public override void Dispose() |
| | 53 | | { |
| 28 | 54 | | copyWalletAddressButton.onClick.RemoveAllListeners(); |
| 28 | 55 | | buyEthereumManaButton.onClick.RemoveAllListeners(); |
| 28 | 56 | | buyPolygonManaButton.onClick.RemoveAllListeners(); |
| | 57 | |
|
| 28 | 58 | | base.Dispose(); |
| 28 | 59 | | } |
| | 60 | |
|
| | 61 | | public override void RefreshControl() |
| | 62 | | { |
| 0 | 63 | | SetWalletSectionAsGuest(model.IsGuest); |
| 0 | 64 | | SetWalletAddress(model.WalletAddress); |
| 0 | 65 | | SetEthereumManaBalance(model.EthereumManaBalance); |
| 0 | 66 | | SetPolygonManaBalance(model.PolygonManaBalance); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 70 | | { |
| 0 | 71 | | if (parentTransform == null) |
| 0 | 72 | | return; |
| | 73 | |
|
| 0 | 74 | | thisTransform.SetParent(parentTransform); |
| 0 | 75 | | thisTransform.localScale = Vector3.one; |
| | 76 | |
|
| 0 | 77 | | RectTransform rectTransform = thisTransform as RectTransform; |
| 0 | 78 | | if (rectTransform == null) return; |
| 0 | 79 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 80 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 81 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 82 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 83 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 84 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | public void SetWalletSectionAsGuest(bool isGuest) |
| | 88 | | { |
| 2 | 89 | | model.IsGuest = isGuest; |
| 2 | 90 | | signedInWalletContainer.SetActive(!isGuest); |
| 2 | 91 | | guestContainer.SetActive(isGuest); |
| 2 | 92 | | } |
| | 93 | |
|
| | 94 | | public void SetWalletAddress(string fullWalletAddress) |
| | 95 | | { |
| 1 | 96 | | model.WalletAddress = fullWalletAddress; |
| 1 | 97 | | walletAddressText.text = fullWalletAddress; |
| 1 | 98 | | } |
| | 99 | |
|
| | 100 | | public void SetEthereumManaLoadingActive(bool isActive) |
| | 101 | | { |
| 2 | 102 | | ethereumManaBalanceText.gameObject.SetActive(!isActive); |
| 2 | 103 | | ethereumManaBalanceLoading.SetActive(isActive); |
| 2 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetEthereumManaBalance(double balance) |
| | 107 | | { |
| 2 | 108 | | model.EthereumManaBalance = balance; |
| 2 | 109 | | ethereumManaBalanceText.text = WalletUtils.FormatBalanceToString(balance); |
| 2 | 110 | | } |
| | 111 | |
|
| | 112 | | public void SetPolygonManaLoadingActive(bool isActive) |
| | 113 | | { |
| 2 | 114 | | polygonManaBalanceText.gameObject.SetActive(!isActive); |
| 2 | 115 | | polygonManaBalanceLoading.SetActive(isActive); |
| 2 | 116 | | } |
| | 117 | |
|
| | 118 | | public void SetPolygonManaBalance(double balance) |
| | 119 | | { |
| 2 | 120 | | model.PolygonManaBalance = balance; |
| 2 | 121 | | polygonManaBalanceText.text = WalletUtils.FormatBalanceToString(balance); |
| 2 | 122 | | } |
| | 123 | |
|
| | 124 | | public void OnPointerClick(PointerEventData eventData) |
| | 125 | | { |
| 0 | 126 | | if (CheckClickOnLearnMoreLink(ethereumManaLearnMoreText)) |
| 0 | 127 | | return; |
| | 128 | |
|
| 0 | 129 | | CheckClickOnLearnMoreLink(polygonManaLearnMoreText); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | private void CopyWalletAddress() |
| | 133 | | { |
| 1 | 134 | | if (copyToastRoutine != null) |
| 0 | 135 | | StopCoroutine(copyToastRoutine); |
| | 136 | |
|
| 1 | 137 | | copyToastRoutine = StartCoroutine(ShowCopyToast()); |
| | 138 | |
|
| 1 | 139 | | OnCopyWalletAddress?.Invoke(); |
| 1 | 140 | | } |
| | 141 | |
|
| | 142 | | private IEnumerator ShowCopyToast() |
| | 143 | | { |
| 1 | 144 | | if (!copyWalletAddressToast.gameObject.activeSelf) |
| 1 | 145 | | copyWalletAddressToast.gameObject.SetActive(true); |
| | 146 | |
|
| 1 | 147 | | copyWalletAddressToast.Show(); |
| 1 | 148 | | yield return new WaitForSeconds(COPY_TOAST_VISIBLE_TIME); |
| 0 | 149 | | copyWalletAddressToast.Hide(); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | private bool CheckClickOnLearnMoreLink(TMP_Text textToCheck) |
| | 153 | | { |
| 0 | 154 | | int linkIndex = TMP_TextUtilities.FindIntersectingLink(textToCheck, Input.mousePosition, textToCheck.canvas. |
| 0 | 155 | | if (linkIndex == -1) |
| 0 | 156 | | return false; |
| | 157 | |
|
| 0 | 158 | | TMP_LinkInfo linkInfo = textToCheck.textInfo.linkInfo[linkIndex]; |
| 0 | 159 | | if (linkInfo.GetLinkID() != LEARN_MORE_LINK_ID) |
| 0 | 160 | | return false; |
| | 161 | |
|
| 0 | 162 | | OnLearnMoreClicked?.Invoke(); |
| 0 | 163 | | return true; |
| | 164 | | } |
| | 165 | | } |
| | 166 | | } |