Skip to content

Commit

Permalink
Refactor blockchain selection to use BlockchainNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
borre-haechi committed Oct 7, 2024
1 parent 482a8eb commit 10bdfb2
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ MonoBehaviour:
_multiStageIdInputField: {fileID: 8988222448735028466}
_connectButton: {fileID: 5272876550459924592}
_changeProfile: {fileID: 11400000, guid: 0985badaa4749434d96e1512b77a927f, type: 2}
_changeBlockchain: {fileID: 11400000, guid: 211a2dc0a77074be7bbb1749a9b4e0fb, type: 2}
_changeApiKey: {fileID: 11400000, guid: b7a612418ad00416b82369dfcf8db4b9, type: 2}
_changePrivateKey: {fileID: 11400000, guid: 2454854534ea54a4092188f8c25951bf, type: 2}
_changeMultiStageId: {fileID: 11400000, guid: 3e53cf0a30d6419bc980bb1a161feb86, type: 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ MonoBehaviour:
_appState: {fileID: 11400000, guid: 4a78ec3eec3af4eef88d48276d7101b3, type: 2}
_blockchainDropdown: {fileID: 4143877699697646035}
_connectButton: {fileID: 5272876550459924592}
_changeBlockchain: {fileID: 11400000, guid: 211a2dc0a77074be7bbb1749a9b4e0fb, type: 2}
_connect: {fileID: 11400000, guid: 826bf1e20101c4d85b5c3baed398f84f, type: 2}
_switchNetwork: {fileID: 11400000, guid: 2958cd5861edd45fabe41e2762944269, type: 2}
_onLogoutEvent: {fileID: 11400000, guid: 10cbde83a4f2b4cb182add5690db5406, type: 2}
Expand Down
4 changes: 4 additions & 0 deletions haechi.face.unity.sdk/Samples/Script/FaceWalletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class FaceWalletManager : MonoBehaviour
private ActionQueue _actionQueue;

[SerializeField] private ReadOnlyAppState _appState;
public AppStateSO appStateSO {
get { return this._appState as AppStateSO; }
set { this._appState = value; }
}

[Header("Listening on")]
/** Connect & Login */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using haechi.face.unity.sdk.Runtime.Type;
using UnityEngine;

Expand Down Expand Up @@ -41,8 +42,8 @@ public class AppStateSO : ReadOnlyAppState
[Tooltip("All blockchains that can be seen in the Connect page")]
[SerializeField] private List<Blockchain> _blockchains;

[Tooltip("Current selected blockchain")]
[SerializeField] private Blockchain _currentBlockchain;
[Tooltip("Current selected network")]
[SerializeField] private BlockchainNetwork _currentNetwork;

[SerializeField] private string _apiKey;
[SerializeField] private string _privateKey;
Expand All @@ -55,7 +56,6 @@ public class AppStateSO : ReadOnlyAppState

[Header("Listening on")]
[SerializeField] private StringEventChannelSO _onProfileChange;
[SerializeField] private StringEventChannelSO _onBlockchainChange;
[SerializeField] private StringEventChannelSO _onApiKeyChange;
[SerializeField] private StringEventChannelSO _onPrivateKeyChange;
[SerializeField] private StringEventChannelSO _onMultiStageIdChange;
Expand All @@ -76,7 +76,6 @@ private void OnEnable()
{
Debug.Log("OnEnable");
this._onProfileChange.OnEventRaised += this.SetCurrentProfile;
this._onBlockchainChange.OnEventRaised += this.SetCurrentBlockchain;
this._onApiKeyChange.OnEventRaised += this.SetCurrentApiKey;
this._onPrivateKeyChange.OnEventRaised += this.SetCurrentPrivateKey;
this._onMultiStageIdChange.OnEventRaised += this.SetCurrentMultiStageId;
Expand All @@ -91,7 +90,6 @@ private void OnEnable()
private void OnDisable()
{
this._onProfileChange.OnEventRaised -= this.SetCurrentProfile;
this._onBlockchainChange.OnEventRaised -= this.SetCurrentBlockchain;
this._onApiKeyChange.OnEventRaised -= this.SetCurrentApiKey;
this._onPrivateKeyChange.OnEventRaised -= this.SetCurrentPrivateKey;
this._onMultiStageIdChange.OnEventRaised -= this.SetCurrentMultiStageId;
Expand All @@ -109,10 +107,9 @@ private void SetCurrentProfile(string env)
this._profileUpdated.RaiseEvent();
}

private void SetCurrentBlockchain(string blockchain)
public void SetCurrentNetwork(BlockchainNetwork network)
{
this._currentBlockchain = Blockchains.ValueOf(blockchain);
this._blockchainUpdated.RaiseEvent();
this._currentNetwork = network;
}

private void SetCurrentApiKey(string value)
Expand Down Expand Up @@ -220,12 +217,12 @@ public override Profile GetEnv()

public override Blockchain GetBlockchain()
{
return this._currentBlockchain;
return BlockchainNetworks.Properties[this._currentNetwork].Blockchain;
}

public override BlockchainNetwork GetBlockchainNetwork()
{
return BlockchainNetworks.GetNetwork(this._currentBlockchain, this._currentProfile);
return this._currentNetwork;
}

public override string GetScheme()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using haechi.face.unity.sdk.Runtime.Type;
using NBitcoin;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -12,7 +14,6 @@ public class UISectionConnectNetwork : MonoBehaviour
[SerializeField] private UIButton _connectButton;

[Header("Broadcast to")]
[SerializeField] private StringEventChannelSO _changeBlockchain;
[SerializeField] private VoidEventChannelSO _connect;
[SerializeField] private VoidEventChannelSO _switchNetwork;

Expand Down Expand Up @@ -41,14 +42,14 @@ private void Start()

private void Initialize()
{
this._appState.GetAllBlockchains().ForEach(
b => this._blockchainDropdown.options.Add(new TMP_Dropdown.OptionData(b.ToString())));
BlockchainNetworks.GetAllNetworks().ForEach(n => this._blockchainDropdown.options.Add(new TMP_Dropdown.OptionData(n.ToString())));
this._blockchainDropdown.captionText.text = this._blockchainDropdown.options[0].text;
}

private void OnBlockchainChanges(int dropdownIndex)
{
this._changeBlockchain.RaiseEvent(this._blockchainDropdown.options[dropdownIndex].text);
BlockchainNetwork blockchainNetwork = BlockchainNetworks.ValueOf(this._blockchainDropdown.options[dropdownIndex].text);
this._appState.SetCurrentNetwork(blockchainNetwork);
}

private void ConnectOrSwitchNetwork()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using haechi.face.unity.sdk.Runtime.Type;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -17,7 +18,6 @@ public class UISectionDevConnectNetwork : MonoBehaviour

[Header("Broadcast to")]
[SerializeField] private StringEventChannelSO _changeProfile;
[SerializeField] private StringEventChannelSO _changeBlockchain;
[SerializeField] private StringEventChannelSO _changeApiKey;
[SerializeField] private StringEventChannelSO _changePrivateKey;
[SerializeField] private StringEventChannelSO _changeMultiStageId;
Expand Down Expand Up @@ -57,8 +57,7 @@ private void Initialize()
e => this._envDropdown.options.Add(new TMP_Dropdown.OptionData(e)));
this._envDropdown.captionText.text = this._envDropdown.options[0].text;

this._appState.GetAllBlockchains().ForEach(
b => this._blockchainDropdown.options.Add(new TMP_Dropdown.OptionData(b.ToString())));
BlockchainNetworks.GetAllNetworks().ForEach(n => this._blockchainDropdown.options.Add(new TMP_Dropdown.OptionData(n.ToString())));
this._blockchainDropdown.captionText.text = this._blockchainDropdown.options[0].text;

this._apiKeyInputField.text = this._appState.GetSampleApiKey();
Expand All @@ -74,7 +73,7 @@ private void OnEnvChanges(int dropdownIndex)

private void OnBlockchainChanges(int dropdownIndex)
{
this._changeBlockchain.RaiseEvent(this._blockchainDropdown.options[dropdownIndex].text);
this._appState.SetCurrentNetwork(BlockchainNetworks.ValueOf(this._blockchainDropdown.options[dropdownIndex].text));
}

private void OnApiKeyChanges(string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ MonoBehaviour:
_multiStageId:
_erc20Balance:
_onProfileChange: {fileID: 11400000, guid: 0985badaa4749434d96e1512b77a927f, type: 2}
_onBlockchainChange: {fileID: 11400000, guid: 211a2dc0a77074be7bbb1749a9b4e0fb, type: 2}
_onApiKeyChange: {fileID: 11400000, guid: b7a612418ad00416b82369dfcf8db4b9, type: 2}
_onPrivateKeyChange: {fileID: 11400000, guid: 2454854534ea54a4092188f8c25951bf, type: 2}
_onMultiStageIdChange: {fileID: 11400000, guid: 3e53cf0a30d6419bc980bb1a161feb86, type: 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ MonoBehaviour:
_multiStageId:
_erc20Balance:
_onProfileChange: {fileID: 11400000, guid: 0985badaa4749434d96e1512b77a927f, type: 2}
_onBlockchainChange: {fileID: 11400000, guid: 211a2dc0a77074be7bbb1749a9b4e0fb, type: 2}
_onApiKeyChange: {fileID: 11400000, guid: b7a612418ad00416b82369dfcf8db4b9, type: 2}
_onPrivateKeyChange: {fileID: 11400000, guid: 2454854534ea54a4092188f8c25951bf, type: 2}
_onMultiStageIdChange: {fileID: 11400000, guid: 3e53cf0a30d6419bc980bb1a161feb86, type: 2}
Expand Down

0 comments on commit 10bdfb2

Please sign in to comment.