| | 1 | | using DCL.Browser; |
| | 2 | | using System; |
| | 3 | |
|
| | 4 | | namespace DCL.Guests.HUD.ConnectWallet |
| | 5 | | { |
| | 6 | | public class ConnectWalletComponentController : IDisposable |
| | 7 | | { |
| | 8 | | private const string HELP_URL = "https://docs.decentraland.org/player/blockchain-integration/get-a-wallet/"; |
| | 9 | |
|
| | 10 | | private readonly IConnectWalletComponentView connectWalletView; |
| | 11 | | private readonly IBrowserBridge browserBridge; |
| | 12 | | private readonly IUserProfileBridge userProfileBridge; |
| | 13 | | private readonly DataStore dataStore; |
| | 14 | |
|
| 12 | 15 | | private BaseVariable<bool> connectWalletModalVisible => dataStore.HUDs.connectWalletModalVisible; |
| | 16 | |
|
| 5 | 17 | | public ConnectWalletComponentController( |
| | 18 | | IConnectWalletComponentView connectWalletView, |
| | 19 | | IBrowserBridge browserBridge, |
| | 20 | | IUserProfileBridge userProfileBridge, |
| | 21 | | DataStore dataStore) |
| | 22 | | { |
| 5 | 23 | | this.connectWalletView = connectWalletView; |
| 5 | 24 | | this.browserBridge = browserBridge; |
| 5 | 25 | | this.userProfileBridge = userProfileBridge; |
| 5 | 26 | | this.dataStore = dataStore; |
| | 27 | |
|
| 5 | 28 | | this.connectWalletView.OnCancel += OnCancelWalletConnection; |
| 5 | 29 | | this.connectWalletView.OnConnect += OnConfirmWalletConnection; |
| 5 | 30 | | this.connectWalletView.OnHelp += OnConfirmHelp; |
| 5 | 31 | | connectWalletModalVisible.OnChange += OnChangeVisibility; |
| 5 | 32 | | } |
| | 33 | |
|
| | 34 | | public void Dispose() |
| | 35 | | { |
| 5 | 36 | | connectWalletView.OnCancel -= OnCancelWalletConnection; |
| 5 | 37 | | connectWalletView.OnConnect -= OnConfirmWalletConnection; |
| 5 | 38 | | connectWalletView.OnHelp -= OnConfirmHelp; |
| 5 | 39 | | connectWalletModalVisible.OnChange -= OnChangeVisibility; |
| 5 | 40 | | } |
| | 41 | |
|
| | 42 | | private void OnCancelWalletConnection() |
| | 43 | | { |
| 1 | 44 | | connectWalletView.Hide(); |
| 1 | 45 | | connectWalletModalVisible.Set(newValue: false, notifyEvent: false); |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | private void OnConfirmWalletConnection() |
| | 49 | | { |
| 1 | 50 | | connectWalletView.Hide(); |
| 1 | 51 | | connectWalletModalVisible.Set(newValue: false, notifyEvent: false); |
| 1 | 52 | | userProfileBridge.SignUp(); |
| 1 | 53 | | } |
| | 54 | |
|
| 1 | 55 | | private void OnConfirmHelp() => browserBridge.OpenUrl(HELP_URL); |
| | 56 | |
|
| | 57 | | private void OnChangeVisibility(bool isVisible, bool previousIsVisible) |
| | 58 | | { |
| 4 | 59 | | if (isVisible) |
| 3 | 60 | | connectWalletView.Show(); |
| | 61 | | else |
| 1 | 62 | | connectWalletView.Hide(); |
| 1 | 63 | | } |
| | 64 | | } |
| | 65 | | } |