Skip to content

Commit 29ba3bd

Browse files
authored
Merge branch 'dev' into nikola/countly-issues
2 parents f172271 + dbce9a9 commit 29ba3bd

File tree

239 files changed

+17012
-26035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+17012
-26035
lines changed
Binary file not shown.
Binary file not shown.

Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab

Lines changed: 6643 additions & 2776 deletions
Large diffs are not rendered by default.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using UnityEngine;
2+
using TMPro;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using ChainSafe.Gaming.UnityPackage;
6+
using ChainSafe.GamingSdk.Web3Auth;
7+
using UnityEngine.UI;
8+
9+
public class Web3AuthCustomNftManager : MonoBehaviour
10+
{
11+
#region Fields
12+
13+
[SerializeField] private GameObject customNftPlaceHolder;
14+
[SerializeField] private GameObject customNftDisplayParent;
15+
[SerializeField] private GameObject customNftDisplay;
16+
[SerializeField] private GameObject addCustomNftMenu;
17+
[SerializeField] private TMP_InputField customNftAddressInput;
18+
[SerializeField] private TMP_InputField customNftSymbolInput;
19+
[SerializeField] private TMP_InputField customNftIdInput;
20+
[SerializeField] private TextMeshProUGUI customNftAmountText;
21+
[SerializeField] private TextMeshProUGUI customNftSymbolText;
22+
[SerializeField] private Button addNftsMenuButton;
23+
[SerializeField] private Button closeAddNftMenuButton;
24+
[SerializeField] private Button addNftButton;
25+
private string customNftContract;
26+
27+
#endregion
28+
29+
#region Methods
30+
31+
/// <summary>
32+
/// Initializes objects.
33+
/// </summary>
34+
private void Awake()
35+
{
36+
addNftButton.onClick.AddListener(AddNft);
37+
addNftsMenuButton.onClick.AddListener(ToggleAddNftMenuButton);
38+
closeAddNftMenuButton.onClick.AddListener(ToggleAddNftMenuButton);
39+
SetNfts();
40+
}
41+
42+
/// <summary>
43+
/// Sets custom nft displays.
44+
/// </summary>
45+
private async void SetNfts()
46+
{
47+
if (File.Exists(Path.Combine(Application.persistentDataPath, "customNft.txt")))
48+
{
49+
var customTokenData = File.ReadAllText(Path.Combine(Application.persistentDataPath, "customNft.txt"));
50+
var data = customTokenData.Split(",");
51+
customNftPlaceHolder.SetActive(false);
52+
customNftContract = data[0];
53+
customNftSymbolText.text = data[1].ToUpper();
54+
var balance = await Web3Unity.Web3.Erc1155.GetBalanceOf(customNftContract, data[2]);
55+
customNftAmountText.text = balance.ToString();
56+
customNftDisplay.SetActive(true);
57+
}
58+
else
59+
{
60+
customNftDisplay.SetActive(false);
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Toggles the add nft menu.
66+
/// </summary>
67+
private void ToggleAddNftMenuButton()
68+
{
69+
addCustomNftMenu.SetActive(!addCustomNftMenu.activeSelf);
70+
}
71+
72+
/// <summary>
73+
/// Adds a custom nft to the wallet.
74+
/// </summary>
75+
private void AddNft()
76+
{
77+
if (customNftAddressInput.text.Length != 42) return;
78+
File.WriteAllText(Path.Combine(Application.persistentDataPath, "customNft.txt"), $"{customNftAddressInput.text},{customNftSymbolInput.text},{customNftIdInput.text}");
79+
customNftSymbolText.text = customNftSymbolInput.text.ToUpper();
80+
ToggleAddNftMenuButton();
81+
customNftPlaceHolder.SetActive(false);
82+
customNftDisplay.SetActive(true);
83+
customNftAddressInput.text = string.Empty;
84+
customNftSymbolInput.text = string.Empty;
85+
customNftIdInput.text = string.Empty;
86+
SetNfts();
87+
}
88+
89+
/// <summary>
90+
/// Subscribes to events.
91+
/// </summary>
92+
private void OnEnable()
93+
{
94+
Web3AuthEventManager.SetTokens += SetNfts;
95+
}
96+
97+
/// <summary>
98+
/// Unsubscribes from events.
99+
/// </summary>
100+
private void OnDisable()
101+
{
102+
Web3AuthEventManager.SetTokens -= SetNfts;
103+
}
104+
105+
#endregion
106+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Scripts/Web3AuthWalletGUITokenManager.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using ChainSafe.Gaming.UnityPackage;
1010
using ChainSafe.Gaming.Web3;
1111
using ChainSafe.GamingSdk.Web3Auth;
12-
using Scripts.EVM.Token;
1312
using UnityEngine.UI;
1413

1514
/// <summary>
@@ -20,7 +19,9 @@ public class Web3AuthWalletGUITokenManager : MonoBehaviour
2019
#region Fields
2120

2221
[SerializeField] private GameObject customTokenPlaceHolder;
23-
[SerializeField] private GameObject customTokenDisplay;
22+
[SerializeField] private GameObject customTokenDisplayErc20Parent;
23+
[SerializeField] private GameObject customNftDisplayParent;
24+
[SerializeField] private GameObject customTokenDisplayErc20;
2425
[SerializeField] private GameObject transferTokensContainer;
2526
[SerializeField] private GameObject addCustomTokensMenu;
2627
[SerializeField] private TMP_Dropdown selectedTokenToTransfer;
@@ -38,10 +39,12 @@ public class Web3AuthWalletGUITokenManager : MonoBehaviour
3839
[SerializeField] private Button transferTokensMenuButton;
3940
[SerializeField] private Button closeTransferTokensButton;
4041
[SerializeField] private Button transferTokensButton;
42+
[SerializeField] private Button toggleCustomTokensButton;
4143
private Task<string> symbolTask;
4244
private bool isSymbolTaskRunning;
4345
private string lastCheckedAddress;
4446
private string customTokenContract;
47+
private string customNftContract;
4548

4649
#endregion
4750

@@ -58,6 +61,7 @@ private void Awake()
5861
transferTokensMenuButton.onClick.AddListener(ToggleTransferTokensMenuButton);
5962
closeTransferTokensButton.onClick.AddListener(ToggleTransferTokensMenuButton);
6063
transferTokensButton.onClick.AddListener(TransferTokens);
64+
toggleCustomTokensButton.onClick.AddListener(ToggleCustomTokenMenu);
6165
SetTokens();
6266
}
6367

@@ -76,11 +80,11 @@ private async void SetTokens()
7680
var balance = await Web3Unity.Web3.Erc20.GetBalanceOf(customTokenContract, Web3Unity.Web3.Signer.PublicAddress);
7781
var customTokenValue = (decimal)balance / (decimal)BigInteger.Pow(10, 18);
7882
customTokenAmountText.text = customTokenValue.ToString("N18");
79-
customTokenDisplay.SetActive(true);
83+
customTokenDisplayErc20.SetActive(true);
8084
}
8185
else
8286
{
83-
customTokenDisplay.SetActive(false);
87+
customTokenDisplayErc20.SetActive(false);
8488
}
8589
// Set native token
8690
nativeTokenSymbolText.text = Web3Unity.Web3.ChainConfig.NativeCurrency.Symbol.ToUpper();
@@ -97,10 +101,6 @@ private async void SetTokens()
97101
private void ToggleAddTokensMenuButton()
98102
{
99103
addCustomTokensMenu.SetActive(!addCustomTokensMenu.activeSelf);
100-
if (addCustomTokensMenu.activeSelf)
101-
{
102-
addTokenButton.gameObject.SetActive(false);
103-
}
104104
}
105105

106106
/// <summary>
@@ -129,6 +129,15 @@ private async void GetSymbol()
129129
}
130130
}
131131

132+
/// <summary>
133+
/// Toggles the custom token type menus.
134+
/// </summary>
135+
private void ToggleCustomTokenMenu()
136+
{
137+
customTokenDisplayErc20Parent.SetActive(!customTokenDisplayErc20Parent.activeSelf);
138+
customNftDisplayParent.SetActive(!customNftDisplayParent.activeSelf);
139+
}
140+
132141
/// <summary>
133142
/// Adds a custom token to the wallet.
134143
/// </summary>
@@ -139,7 +148,7 @@ private void AddToken()
139148
customTokenSymbolText.text = customTokenSymbolInput.text.ToUpper();
140149
ToggleAddTokensMenuButton();
141150
customTokenPlaceHolder.SetActive(false);
142-
customTokenDisplay.SetActive(true);
151+
customTokenDisplayErc20.SetActive(true);
143152
customTokenAddressInput.text = string.Empty;
144153
customTokenSymbolInput.text = string.Empty;
145154
SetTokens();
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)