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

Fixes #1052

Merged
merged 12 commits into from
Jul 5, 2024
Merged

Fixes #1052

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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private class Web3Config : ICompleteProjectConfig
public string BlockExplorerUrl => "https://explorer.gochain.io/";
public string Ipc { get; }
public string Ws { get; }
public bool EnableAnalytics => true;
}

private async void Awake()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ValueTask WillStartAsync()
analyticsClient.CaptureEvent(new AnalyticsEvent()
{
EventName = "Ramp Initialized",
PackageName = "io.chiansafe.web3-unity.exchangers.ramp"
PackageName = "io.chainsafe.web3-unity.exchangers.ramp"
});
platformImplementation = RampExchangerFactory.CreateRampExchanger(config, signer);
platformImplementation.OnRampPurchaseCreated += InvokeOnRampPurchaseCreated;
Expand Down
36 changes: 36 additions & 0 deletions Packages/io.chainsafe.web3-unity/Editor/ScriptingDefineSymbols.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Linq;
using UnityEditor;

public static class ScriptingDefineSymbols
{
public static bool TryAddDefineSymbol(string symbol)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper method, nice

{
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out string[] symbols);

if (symbols.Contains(symbol))
{
return false;
}

symbols = symbols.Append(symbol).ToArray();
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);

return true;
}

public static bool TryRemoveDefineSymbol(string symbol)
{
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, out string[] symbols);

if (!symbols.Contains(symbol))
{
return false;
}

symbols = symbols.Where(s => s != symbol).ToArray();
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);

return true;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Packages/io.chainsafe.web3-unity/Editor/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ChainSafeServerSettings : EditorWindow
private const string SymbolDefault = "Seth";
private const string RpcDefault = "https://rpc.sepolia.org";
private const string BlockExplorerUrlDefault = "https://sepolia.etherscan.io";
private const string EnableAnalyticsScriptingDefineSymbol = "ENABLE_ANALYTICS";

// Chain values
private string projectID;
Expand All @@ -38,6 +39,7 @@ public class ChainSafeServerSettings : EditorWindow
private string rpc;
private string newRpc;
private string blockExplorerUrl;
private bool enableAnalytics;
public string previousProjectId;

private Texture2D logo;
Expand Down Expand Up @@ -77,6 +79,7 @@ private void Awake()
symbol = string.IsNullOrEmpty(projectConfig?.Symbol) ? SymbolDefault : projectConfig.Symbol;
rpc = string.IsNullOrEmpty(projectConfig?.Rpc) ? RpcDefault : projectConfig.Rpc;
blockExplorerUrl = string.IsNullOrEmpty(projectConfig?.BlockExplorerUrl) ? BlockExplorerUrlDefault : projectConfig.BlockExplorerUrl;
enableAnalytics = projectConfig.EnableAnalytics;
// Search menu
onDropDownChange = new UnityEvent();
onDropDownChange.AddListener(UpdateServerMenuInfo);
Expand Down Expand Up @@ -196,6 +199,18 @@ private void OnGUI()
chainID = EditorGUILayout.TextField("Chain ID: ", chainID);
symbol = EditorGUILayout.TextField("Symbol: ", symbol);
blockExplorerUrl = EditorGUILayout.TextField("Block Explorer: ", blockExplorerUrl);
enableAnalytics = EditorGUILayout.Toggle(new GUIContent("Collect Data for Analytics:", "Consent to collecting data for analytics purposes. This will help improve our product."), enableAnalytics);

if (enableAnalytics)
{
ScriptingDefineSymbols.TryAddDefineSymbol(EnableAnalyticsScriptingDefineSymbol);
}

else
{
ScriptingDefineSymbols.TryRemoveDefineSymbol(EnableAnalyticsScriptingDefineSymbol);
}

EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Select RPC");
// Remove "https://" so the user doesn't have to click through 2 levels for the rpc options
Expand Down Expand Up @@ -237,6 +252,7 @@ private void OnGUI()
projectConfig.Symbol = symbol;
projectConfig.Rpc = rpc;
projectConfig.BlockExplorerUrl = blockExplorerUrl;
projectConfig.EnableAnalytics = enableAnalytics;
ProjectConfigUtilities.Save(projectConfig);
if(projectID != previousProjectId)
ValidateProjectID(projectID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ProjectConfigScriptableObject : ScriptableObject, ICompleteProjectC
[SerializeField] private string symbol;
[SerializeField] private string rpc;
[SerializeField] private string blockExplorerUrl;
[SerializeField] private bool enableAnalytics;

public string Symbol
{
Expand Down Expand Up @@ -68,5 +69,11 @@ public string BlockExplorerUrl
get => blockExplorerUrl;
set => blockExplorerUrl = value;
}

public bool EnableAnalytics
{
get => enableAnalytics;
set => enableAnalytics = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static ProjectConfigScriptableObject Load()
}

public static ProjectConfigScriptableObject Load(string projectId, string chainId, string chain, string network,
string symbol, string rpc)
string symbol, string rpc, string blockExplorerUrl, bool enableAnalytics)
{
var projectConfig = ScriptableObject.CreateInstance<ProjectConfigScriptableObject>();

Expand All @@ -26,6 +26,8 @@ public static ProjectConfigScriptableObject Load(string projectId, string chainI
projectConfig.Network = network;
projectConfig.Symbol = symbol;
projectConfig.Rpc = rpc;
projectConfig.BlockExplorerUrl = blockExplorerUrl;
projectConfig.EnableAnalytics = enableAnalytics;

return projectConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public static IWeb3ServiceCollection UseUnityEnvironment(this IWeb3ServiceCollec
services.AddSingleton<IHttpClient, UnityHttpClient>();
services.AddSingleton<ILogWriter, UnityLogWriter>();
services.AddSingleton<IOperatingSystemMediator, UnityOperatingSystemMediator>();
#if ENABLE_ANALYTICS
services.AddSingleton<IAnalyticsClient, CountlyAnalytics>();
#else
services.DisableAnalytics();
#endif
return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static ValueTask<Web3> BuildTestWeb3(Web3Builder.ConfigureServicesDeleg
if (projectConfigScriptableObject == null)
{
projectConfigScriptableObject = ProjectConfigUtilities.Load("3dc3e125-71c4-4511-a367-e981a6a94371", "11155111",
"Ethereum", "Sepolia", "Seth", "https://sepolia.infura.io/v3/287318045c6e455ab34b81d6bcd7a65f");
"Ethereum", "Sepolia", "Seth", "https://sepolia.infura.io/v3/287318045c6e455ab34b81d6bcd7a65f", "https://sepolia.etherscan.io/", false);
}

// Create web3builder & assign services
Expand Down
6 changes: 6 additions & 0 deletions src/ChainSafe.Gaming.NetCore/ProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ public class ProjectConfig : IProjectConfig
/// Project Id fetched from the ChainSafe Gaming web dashboard.
/// </summary>
public string ProjectId { get; set; }

/// <summary>
/// Implementation of <see cref="IProjectConfig.EnableAnalytics"/>
/// Enables or disables analytics.
/// </summary>
public bool EnableAnalytics { get; set; }
}
}
6 changes: 5 additions & 1 deletion src/ChainSafe.Gaming.Tests/Web3Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ internal static class Web3Util
JsonRpcWalletConfig jsonRpcWalletConfig, Web3Builder.ConfigureServicesDelegate configureDelegate = null)
{
return new Web3Builder(
new ProjectConfig { ProjectId = string.Empty },
new ProjectConfig
{
ProjectId = string.Empty,
EnableAnalytics = true,
},
new ChainConfig
{
Chain = "Anvil",
Expand Down
2 changes: 2 additions & 0 deletions src/ChainSafe.Gaming/Web3/Core/IProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public interface IProjectConfig
/// The project id issued by ChainSafe. Follow https://docs.gaming.chainsafe.io to learn more.
/// </summary>
public string ProjectId { get; }

public bool EnableAnalytics => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private class Web3Config : ICompleteProjectConfig
public string BlockExplorerUrl => "https://explorer.gochain.io/";
public string Ipc { get; }
public string Ws { get; }
public bool EnableAnalytics => true;
}

private async void Awake()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ PlayerSettings:
webGLMemoryGeometricGrowthCap: 96
webGLPowerPreference: 2
scriptingDefineSymbols:
Standalone:
WebGL: RAMP_AVAILABLE
additionalCompilerArguments: {}
platformArchitecture: {}
Expand Down
Loading