Skip to content

Commit c7eb4e8

Browse files
sneakzttvrob1997
andauthored
Fixes (#1052)
* fixes fixes * fixes * fixes fixes * fixes for fixes * exception fixes by adding stub analytics * better fix for exception * typo * fixes fixes * fixes * Update ProjectSettings.asset * tooltip tooltip updated * Update ChainlinkLootboxSampleLauncher.cs --------- Co-authored-by: rob1997 <robelgetnetrg@gmail.com>
1 parent e9928ed commit c7eb4e8

14 files changed

Lines changed: 95 additions & 4 deletions

File tree

Packages/io.chainsafe.web3-unity.lootboxes/Samples~/Web3.Unity Chainlink Lootboxes/Scripts/ChainlinkLootboxSampleLauncher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private class Web3Config : ICompleteProjectConfig
3535
public string BlockExplorerUrl => "https://explorer.gochain.io/";
3636
public string Ipc { get; }
3737
public string Ws { get; }
38+
public bool EnableAnalytics => true;
3839
}
3940

4041
private async void Awake()

Packages/io.chainsafe.web3-unity.ramp/Runtime/Scripts/RampExchangerUniversal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ValueTask WillStartAsync()
3030
analyticsClient.CaptureEvent(new AnalyticsEvent()
3131
{
3232
EventName = "Ramp Initialized",
33-
PackageName = "io.chiansafe.web3-unity.exchangers.ramp"
33+
PackageName = "io.chainsafe.web3-unity.exchangers.ramp"
3434
});
3535
platformImplementation = RampExchangerFactory.CreateRampExchanger(config, signer);
3636
platformImplementation.OnRampPurchaseCreated += InvokeOnRampPurchaseCreated;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Linq;
3+
using UnityEditor;
4+
5+
public static class ScriptingDefineSymbols
6+
{
7+
public static bool TryAddDefineSymbol(string symbol)
8+
{
9+
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out string[] symbols);
10+
11+
if (symbols.Contains(symbol))
12+
{
13+
return false;
14+
}
15+
16+
symbols = symbols.Append(symbol).ToArray();
17+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);
18+
19+
return true;
20+
}
21+
22+
public static bool TryRemoveDefineSymbol(string symbol)
23+
{
24+
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out string[] symbols);
25+
26+
if (!symbols.Contains(symbol))
27+
{
28+
return false;
29+
}
30+
31+
symbols = symbols.Where(s => s != symbol).ToArray();
32+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);
33+
34+
return true;
35+
}
36+
}

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

Lines changed: 11 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/ServerSettings.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ChainSafeServerSettings : EditorWindow
2828
private const string SymbolDefault = "Seth";
2929
private const string RpcDefault = "https://rpc.sepolia.org";
3030
private const string BlockExplorerUrlDefault = "https://sepolia.etherscan.io";
31+
private const string EnableAnalyticsScriptingDefineSymbol = "ENABLE_ANALYTICS";
3132

3233
// Chain values
3334
private string projectID;
@@ -38,6 +39,7 @@ public class ChainSafeServerSettings : EditorWindow
3839
private string rpc;
3940
private string newRpc;
4041
private string blockExplorerUrl;
42+
private bool enableAnalytics;
4143
public string previousProjectId;
4244

4345
private Texture2D logo;
@@ -77,6 +79,7 @@ private void Awake()
7779
symbol = string.IsNullOrEmpty(projectConfig?.Symbol) ? SymbolDefault : projectConfig.Symbol;
7880
rpc = string.IsNullOrEmpty(projectConfig?.Rpc) ? RpcDefault : projectConfig.Rpc;
7981
blockExplorerUrl = string.IsNullOrEmpty(projectConfig?.BlockExplorerUrl) ? BlockExplorerUrlDefault : projectConfig.BlockExplorerUrl;
82+
enableAnalytics = projectConfig.EnableAnalytics;
8083
// Search menu
8184
onDropDownChange = new UnityEvent();
8285
onDropDownChange.AddListener(UpdateServerMenuInfo);
@@ -196,6 +199,18 @@ private void OnGUI()
196199
chainID = EditorGUILayout.TextField("Chain ID: ", chainID);
197200
symbol = EditorGUILayout.TextField("Symbol: ", symbol);
198201
blockExplorerUrl = EditorGUILayout.TextField("Block Explorer: ", blockExplorerUrl);
202+
enableAnalytics = EditorGUILayout.Toggle(new GUIContent("Collect Data for Analytics:", "Consent to collecting data for analytics purposes. This will help improve our product."), enableAnalytics);
203+
204+
if (enableAnalytics)
205+
{
206+
ScriptingDefineSymbols.TryAddDefineSymbol(EnableAnalyticsScriptingDefineSymbol);
207+
}
208+
209+
else
210+
{
211+
ScriptingDefineSymbols.TryRemoveDefineSymbol(EnableAnalyticsScriptingDefineSymbol);
212+
}
213+
199214
EditorGUILayout.BeginHorizontal();
200215
EditorGUILayout.PrefixLabel("Select RPC");
201216
// Remove "https://" so the user doesn't have to click through 2 levels for the rpc options
@@ -237,6 +252,7 @@ private void OnGUI()
237252
projectConfig.Symbol = symbol;
238253
projectConfig.Rpc = rpc;
239254
projectConfig.BlockExplorerUrl = blockExplorerUrl;
255+
projectConfig.EnableAnalytics = enableAnalytics;
240256
ProjectConfigUtilities.Save(projectConfig);
241257
if(projectID != previousProjectId)
242258
ValidateProjectID(projectID);

Packages/io.chainsafe.web3-unity/Runtime/Scripts/ProjectConfigScriptableObject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class ProjectConfigScriptableObject : ScriptableObject, ICompleteProjectC
1414
[SerializeField] private string symbol;
1515
[SerializeField] private string rpc;
1616
[SerializeField] private string blockExplorerUrl;
17+
[SerializeField] private bool enableAnalytics;
1718

1819
public string Symbol
1920
{
@@ -68,5 +69,11 @@ public string BlockExplorerUrl
6869
get => blockExplorerUrl;
6970
set => blockExplorerUrl = value;
7071
}
72+
73+
public bool EnableAnalytics
74+
{
75+
get => enableAnalytics;
76+
set => enableAnalytics = value;
77+
}
7178
}
7279
}

Packages/io.chainsafe.web3-unity/Runtime/Scripts/ProjectConfigUtilities.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static ProjectConfigScriptableObject Load()
1616
}
1717

1818
public static ProjectConfigScriptableObject Load(string projectId, string chainId, string chain, string network,
19-
string symbol, string rpc)
19+
string symbol, string rpc, string blockExplorerUrl, bool enableAnalytics)
2020
{
2121
var projectConfig = ScriptableObject.CreateInstance<ProjectConfigScriptableObject>();
2222

@@ -26,6 +26,8 @@ public static ProjectConfigScriptableObject Load(string projectId, string chainI
2626
projectConfig.Network = network;
2727
projectConfig.Symbol = symbol;
2828
projectConfig.Rpc = rpc;
29+
projectConfig.BlockExplorerUrl = blockExplorerUrl;
30+
projectConfig.EnableAnalytics = enableAnalytics;
2931

3032
return projectConfig;
3133
}

Packages/io.chainsafe.web3-unity/Runtime/Scripts/UnityEnvironmentExtension.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public static IWeb3ServiceCollection UseUnityEnvironment(this IWeb3ServiceCollec
2121
services.AddSingleton<IHttpClient, UnityHttpClient>();
2222
services.AddSingleton<ILogWriter, UnityLogWriter>();
2323
services.AddSingleton<IOperatingSystemMediator, UnityOperatingSystemMediator>();
24+
#if ENABLE_ANALYTICS
2425
services.AddSingleton<IAnalyticsClient, CountlyAnalytics>();
26+
#else
27+
services.DisableAnalytics();
28+
#endif
2529
return services;
2630
}
2731
}

Packages/io.chainsafe.web3-unity/Tests/Runtime/SampleTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal static ValueTask<Web3> BuildTestWeb3(Web3Builder.ConfigureServicesDeleg
4949
if (projectConfigScriptableObject == null)
5050
{
5151
projectConfigScriptableObject = ProjectConfigUtilities.Load("3dc3e125-71c4-4511-a367-e981a6a94371", "11155111",
52-
"Ethereum", "Sepolia", "Seth", "https://sepolia.infura.io/v3/287318045c6e455ab34b81d6bcd7a65f");
52+
"Ethereum", "Sepolia", "Seth", "https://sepolia.infura.io/v3/287318045c6e455ab34b81d6bcd7a65f", "https://sepolia.etherscan.io/", false);
5353
}
5454

5555
// Create web3builder & assign services

src/ChainSafe.Gaming.NetCore/ProjectConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ public class ProjectConfig : IProjectConfig
1212
/// Project Id fetched from the ChainSafe Gaming web dashboard.
1313
/// </summary>
1414
public string ProjectId { get; set; }
15+
16+
/// <summary>
17+
/// Implementation of <see cref="IProjectConfig.EnableAnalytics"/>
18+
/// Enables or disables analytics.
19+
/// </summary>
20+
public bool EnableAnalytics { get; set; }
1521
}
1622
}

0 commit comments

Comments
 (0)