Skip to content

Commit

Permalink
- Add account balance to _WalletConnection.unity
Browse files Browse the repository at this point in the history
  • Loading branch information
oskar-ziller committed Nov 29, 2023
1 parent 713c4e6 commit f5a6f79
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 137 deletions.
40 changes: 40 additions & 0 deletions Examples/WalletConnection/Scripts/UI/AccountBalanceUI.cs
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 Examples/WalletConnection/Scripts/UI/AccountBalanceUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Examples/WalletConnection/Scripts/UI/MetadataInfoUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MetadataInfoUI : MonoBehaviour
private void Start()
{
nameText.text = TezosManager.Instance.DAppMetadata.Name;
descriptionText.text = "-";
descriptionText.text = TezosManager.Instance.DAppMetadata.Description;
}
}

Expand Down
Loading

0 comments on commit f5a6f79

Please sign in to comment.