-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathZkEvmGetBalanceScript.cs
More file actions
55 lines (50 loc) · 1.46 KB
/
Copy pathZkEvmGetBalanceScript.cs
File metadata and controls
55 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Globalization;
using System.Numerics;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using Cysharp.Threading.Tasks;
using Immutable.Passport;
public class ZkEvmGetBalanceScript : MonoBehaviour
{
[SerializeField] private Text Output;
[SerializeField] private InputField AddressInput;
public void GetBalance()
{
GetBalanceAsync();
}
private async UniTaskVoid GetBalanceAsync()
{
if (SampleAppManager.PassportInstance == null)
{
ShowOutput("Passport instance is null");
return;
}
ShowOutput("Getting account balance...");
try
{
string balanceHex = await SampleAppManager.PassportInstance.ZkEvmGetBalance(AddressInput.text);
var balanceDec = BigInteger.Parse(balanceHex.Replace("0x", ""), NumberStyles.HexNumber);
if (balanceDec < 0)
{
balanceDec = BigInteger.Parse("0" + balanceHex.Replace("0x", ""), NumberStyles.HexNumber);
}
ShowOutput($"Balance:\nHex: {balanceHex}\nDec: {balanceDec}");
}
catch (System.Exception ex)
{
ShowOutput($"Failed to get balance: {ex.Message}");
}
}
public void Cancel()
{
SceneManager.LoadScene("AuthenticatedScene");
}
private void ShowOutput(string message)
{
if (Output != null)
{
Output.text = message;
}
}
}