-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add account balance to _WalletConnection.unity
- Loading branch information
1 parent
713c4e6
commit f5a6f79
Showing
4 changed files
with
415 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using TezosSDK.Beacon; | ||
using TezosSDK.Helpers; | ||
using TezosSDK.Tezos; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.Serialization; | ||
|
||
namespace TezosSDK | ||
{ | ||
public class AccountBalanceUI : MonoBehaviour | ||
{ | ||
[FormerlySerializedAs("addressText")] [SerializeField] private TextMeshProUGUI balanceText; | ||
|
||
private void Start() | ||
{ | ||
balanceText.text = "-"; | ||
TezosManager.Instance.MessageReceiver.AccountConnected += OnAccountConnected; | ||
TezosManager.Instance.MessageReceiver.AccountDisconnected += OnAccountDisconnected; | ||
} | ||
|
||
private void OnAccountDisconnected(AccountInfo _) | ||
{ | ||
balanceText.text = "-"; | ||
} | ||
|
||
private void OnAccountConnected(AccountInfo _) | ||
{ | ||
var routine = TezosManager.Instance.Tezos.GetCurrentWalletBalance(OnBalanceFetched); | ||
StartCoroutine(routine); | ||
} | ||
|
||
private void OnBalanceFetched(ulong balance) | ||
{ | ||
// Balance is in microtez, so we divide it by 1.000.000 to get tez | ||
balanceText.text = $"{balance / 1000000f}"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Examples/WalletConnection/Scripts/UI/AccountBalanceUI.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.