| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class TransactionHUDController : IHUD, ITransactionHUDController |
| | 6 | | { |
| | 7 | | [System.Serializable] |
| | 8 | | public class Model |
| | 9 | | { |
| 3 | 10 | | public List<ITransactionHUD> transactions = new List<ITransactionHUD>(); |
| | 11 | | } |
| | 12 | |
|
| 0 | 13 | | public TransactionListHUDView view { get; private set; } |
| 0 | 14 | | public Model model { get; private set; } |
| 6 | 15 | | public TransactionHUDController() : this(new Model()) { } |
| | 16 | |
|
| | 17 | | private TransactionBridge transactionBridge; |
| | 18 | |
|
| 0 | 19 | | public TransactionHUDController(Model model) |
| | 20 | | { |
| 0 | 21 | | this.model = model; |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | public void Initialize() |
| | 25 | | { |
| 3 | 26 | | view = TransactionListHUDView.Create(); |
| 3 | 27 | | view.OnTransactionAcceptedEvent += OnTransactionAccepted; |
| 3 | 28 | | view.OnTransactionRejectedEvent += OnTransactionRejected; |
| | 29 | |
|
| 3 | 30 | | transactionBridge = SceneReferences.i.bridgeGameObject.AddComponent<TransactionBridge>(); |
| 3 | 31 | | transactionBridge.transactionController = this; |
| 3 | 32 | | } |
| | 33 | |
|
| | 34 | | public void ShowTransaction(ITransactionHUD transaction) |
| | 35 | | { |
| 0 | 36 | | model.transactions.Add(transaction); |
| 0 | 37 | | view.ShowTransaction(transaction, transaction.model); |
| 0 | 38 | | } |
| | 39 | | public void ShowTransaction(DCL.TransactionHUDModel.Model model) |
| | 40 | | { |
| 4 | 41 | | var transaction = view.ShowTransaction(model); |
| 4 | 42 | | this.model.transactions.Add(transaction); |
| 4 | 43 | | } |
| | 44 | |
|
| | 45 | | private void OnTransactionAccepted(ITransactionHUD transaction) |
| | 46 | | { |
| 0 | 47 | | DCL.Interface.WebInterface.Web3UseResponse(transaction.model.id, true); |
| 0 | 48 | | model.transactions.Remove(transaction); |
| 0 | 49 | | } |
| | 50 | | private void OnTransactionRejected(ITransactionHUD transaction) |
| | 51 | | { |
| 0 | 52 | | DCL.Interface.WebInterface.Web3UseResponse(transaction.model.id, false); |
| 0 | 53 | | model.transactions.Remove(transaction); |
| 0 | 54 | | } |
| | 55 | |
|
| 0 | 56 | | public void SetActive(bool active) { view.SetActive(active); } |
| | 57 | |
|
| | 58 | | public void Dispose() |
| | 59 | | { |
| 3 | 60 | | if (transactionBridge != null) |
| | 61 | | { |
| 3 | 62 | | Object.Destroy(transactionBridge); |
| | 63 | | } |
| 3 | 64 | | if (view != null) |
| | 65 | | { |
| 3 | 66 | | Object.Destroy(view.gameObject); |
| | 67 | | } |
| | 68 | |
|
| 3 | 69 | | view.OnTransactionAcceptedEvent -= OnTransactionAccepted; |
| 3 | 70 | | view.OnTransactionRejectedEvent -= OnTransactionRejected; |
| 3 | 71 | | } |
| | 72 | |
|
| 0 | 73 | | public void SetVisibility(bool visible) { SetActive(visible); } |
| | 74 | | } |