Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet event manager #136

Merged
merged 12 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Examples/Common/Scripts/AccountInfoUI.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TezosSDK.Beacon;
using TezosSDK.Tezos;
using TMPro;
using UnityEngine;
Expand All @@ -18,14 +19,16 @@ private void Start()
TezosManager.Instance.MessageReceiver.AccountDisconnected += OnAccountDisconnected;
}

private void OnAccountDisconnected(string obj)
private void OnAccountDisconnected(AccountInfo account_info)
{
addressText.text = notConnectedText;
}

private void OnAccountConnected(string obj)
private void OnAccountConnected(AccountInfo account_info)
{
addressText.text = TezosManager.Instance.Wallet.GetActiveAddress();
// OR
addressText.text = account_info.Address;
}
}
}
5 changes: 3 additions & 2 deletions Examples/Common/Scripts/ContractInfoUI.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TezosSDK.Beacon;
using TezosSDK.Tezos;
using TMPro;
using UnityEngine;
Expand All @@ -16,12 +17,12 @@ private void Start()
addressText.text = NotConnectedText;
}

private void OnAccountDisconnected(string obj)
private void OnAccountDisconnected(AccountInfo account_info)
{
addressText.text = NotConnectedText;
}

private void OnAccountConnected(string obj)
private void OnAccountConnected(AccountInfo account_info)
{
addressText.text = TezosManager
.Instance
Expand Down
5 changes: 3 additions & 2 deletions Examples/WalletConnection/Scripts/LogoutButton.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TezosSDK.Beacon;
using TezosSDK.Tezos;
using UnityEngine;

Expand All @@ -19,12 +20,12 @@ private void Start()

}

private void OnAccountDisconnected(string obj)
private void OnAccountDisconnected(AccountInfo account_info)
{
gameObject.SetActive(false);
}

private void OnAccountConnected(string obj)
private void OnAccountConnected(AccountInfo account_info)
{
gameObject.SetActive(true);
}
Expand Down
11 changes: 6 additions & 5 deletions Examples/WalletConnection/Scripts/QRImageGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using TezosSDK.Beacon;
using TezosSDK.Tezos;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -23,29 +24,29 @@ private void Start()
TezosManager.Instance.MessageReceiver.AccountConnectionFailed += OnAccountConnectionFailed;
}

private void OnAccountDisconnected(string obj)
private void OnAccountDisconnected(AccountInfo account_info)
{
gameObject.SetActive(true);
}

private void OnAccountConnectionFailed(string message)
private void OnAccountConnectionFailed(ErrorInfo error_info)
{
throw new Exception("Account connection failed!");
}

private void OnAccountConnected(string message)
private void OnAccountConnected(AccountInfo account_info)
{
gameObject.SetActive(false);
}

private void SetQrCode(string handshake)
private void SetQrCode(HandshakeData handshake_data)
{
if (encoded)
{
return;
}

var uri = "tezos://?type=tzip10&data=" + handshake;
var uri = "tezos://?type=tzip10&data=" + handshake_data.PairingData;
EncodeTextToQrCode(uri);
}

Expand Down
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.

5 changes: 3 additions & 2 deletions Examples/WalletConnection/Scripts/UI/ConnectedTextUI.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TezosSDK.Beacon;
using TezosSDK.Tezos;
using UnityEngine;

Expand All @@ -18,12 +19,12 @@ private void Start()
}
}

private void OnAccountDisconnected(string obj)
private void OnAccountDisconnected(AccountInfo account_info)
{
gameObject.SetActive(false);
}

private void OnAccountConnected(string obj)
private void OnAccountConnected(AccountInfo account_info)
{
gameObject.SetActive(true);
}
Expand Down
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
Loading