Skip to content

Commit 9165f0e

Browse files
authored
Now the default behaviour for switching the chain is actually to try to add it, if it already exists, we're getting a prompt to switch to it. (#1250)
* Now the default behaviour for switching the chain is actually to try to add it, if it already exists, we're getting a prompt to switch to it. * Removed unnecessary chain declaration * Naming conventions and default values. * Addressed Oleks comments * Creating the directory if it doesn't exist * Removed return * Updated dependencies
1 parent d13f667 commit 9165f0e

File tree

42 files changed

+246
-83
lines changed

Some content is hidden

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

42 files changed

+246
-83
lines changed
Binary file not shown.
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private async void SetTokens()
8383
customTokenDisplay.SetActive(false);
8484
}
8585
// Set native token
86-
nativeTokenSymbolText.text = Web3Unity.Web3.ChainConfig.Symbol.ToUpper();
86+
nativeTokenSymbolText.text = Web3Unity.Web3.ChainConfig.NativeCurrency.Symbol.ToUpper();
8787
var hexBalance = await Web3Unity.Web3.RpcProvider.GetBalance(Web3Unity.Web3.Signer.PublicAddress);
8888
var weiBalance = BigInteger.Parse(hexBalance.ToString());
8989
decimal ethBalance = (decimal)weiBalance / (decimal)Math.Pow(10, 18);

Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthConnectionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public override async Task Initialize(bool rememberSession)
9292

9393
//1155 is a decimal number, we need to convert it to an integer
9494
InitWeb3Auth(clientId, new HexBigInteger(BigInteger.Parse(chainConfig.ChainId)).HexValue,
95-
chainConfig.Rpc, chainConfig.Network, "", chainConfig.Symbol, "", network.ToString().ToLower(), Initialized, InitializeError);
95+
chainConfig.Rpc, chainConfig.Network, "", chainConfig.NativeCurrency.Symbol, "", network.ToString().ToLower(), Initialized, InitializeError);
9696

9797
await _initializeTcs.Task;
9898
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System.IO;
4+
5+
public class OpenPersistentDataPath
6+
{
7+
[MenuItem("Edit/Open Persistent Data Path")]
8+
private static void OpenPersistentDataPathFolder()
9+
{
10+
string path = Application.persistentDataPath;
11+
12+
// Check if the directory exists
13+
if (!Directory.Exists(path))
14+
{
15+
Directory.CreateDirectory(path);
16+
}
17+
18+
// Open the folder in the file explorer
19+
EditorUtility.RevealInFinder(path);
20+
}
21+
}

Packages/io.chainsafe.web3-unity/Editor/OpenPersistenDataPath.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/io.chainsafe.web3-unity/Editor/Web3SettingsEditor.ChainSettings.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Linq;
33
using ChainSafe.Gaming;
4+
using ChainSafe.Gaming.Web3;
45
using UnityEditor;
56
using UnityEditor.Experimental.GraphView;
67
using UnityEngine;
8+
using NativeCurrency = ChainSafe.Gaming.Web3.NativeCurrency;
79

810
namespace ChainSafe.GamingSdk.Editor
911
{
@@ -85,7 +87,13 @@ public void OnGUI()
8587

8688
chainConfig.Network = EditorGUILayout.TextField("Network", chainConfig.Network);
8789
chainConfig.ChainId = EditorGUILayout.TextField("Chain ID", chainConfig.ChainId);
88-
chainConfig.Symbol = EditorGUILayout.TextField("Symbol", chainConfig.Symbol);
90+
EditorGUILayout.LabelField("Native Currency", EditorStyles.boldLabel);
91+
EditorGUI.indentLevel++;
92+
// Draw fields for NativeCurrency
93+
chainConfig.NativeCurrency.Name = EditorGUILayout.TextField("Name", chainConfig.NativeCurrency.Name);
94+
chainConfig.NativeCurrency.Symbol = EditorGUILayout.TextField("Symbol", chainConfig.NativeCurrency.Symbol);
95+
chainConfig.NativeCurrency.Decimals = EditorGUILayout.IntField("Decimals", chainConfig.NativeCurrency.Decimals);
96+
EditorGUI.indentLevel--;
8997
chainConfig.BlockExplorerUrl = EditorGUILayout.TextField("Block Explorer", chainConfig.BlockExplorerUrl);
9098

9199
GUI.enabled = true;
@@ -195,7 +203,12 @@ private void UpdateServerMenuInfo(bool chainSwitched = false)
195203
{
196204
chainConfig.Network = chainPrototype.chain;
197205
chainConfig.ChainId = chainPrototype.chainId.ToString();
198-
chainConfig.Symbol = chainPrototype.nativeCurrency.symbol;
206+
chainConfig.NativeCurrency = new NativeCurrency()
207+
{
208+
Name = chainPrototype.nativeCurrency.Name,
209+
Symbol = chainPrototype.nativeCurrency.Symbol,
210+
Decimals = chainPrototype.nativeCurrency.Decimals
211+
};
199212
if (chainPrototype.explorers != null)
200213
{
201214
chainConfig.BlockExplorerUrl = chainPrototype.explorers[0].url;
Binary file not shown.

0 commit comments

Comments
 (0)