Skip to content

Commit

Permalink
cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rob1997 committed Jan 16, 2025
1 parent e7e1a90 commit 5aa8026
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 272 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using ChainSafe.Gaming.EmbeddedWallet;
using TWeb3Auth = Web3Auth;
using Network = Web3Auth.Network;
using ThemeModes = Web3Auth.ThemeModes;
using Language = Web3Auth.Language;

namespace ChainSafe.GamingSdk.Web3Auth
{
Expand All @@ -10,10 +13,33 @@ namespace ChainSafe.GamingSdk.Web3Auth
/// </summary>
public interface IWeb3AuthConfig : IEmbeddedWalletConfig
{
// Name of the App.
public string AppName { get; }
// Client ID you get from Web3Auth dashboard.
public string ClientId { get; }
// Redirect URI for the app.
public string RedirectUri { get; }
// Network to connect to (MainNet, TestNet...).
public Network Network { get; }
public ThemeModes Theme { get; }
public Language Language { get; }

/// <summary>
/// Gets or sets the Web3AuthOptions for configuring the Web3Auth instance associated with the wallet.
/// </summary>
public Web3AuthOptions Web3AuthOptions { get; }
public Web3AuthOptions Web3AuthOptions => new Web3AuthOptions
{
clientId = ClientId,
redirectUrl = new Uri(RedirectUri),
network = Network,

whiteLabel = new()
{
mode = Theme,
defaultLanguage = Language,
appName = AppName,
}
};

/// <summary>
/// Login Provider to use when connecting the wallet, like Google, facebook etc...
Expand All @@ -23,12 +49,21 @@ public interface IWeb3AuthConfig : IEmbeddedWalletConfig
/// <summary>
/// Get the SessionId on connection from the provider.
/// </summary>
public Task<string> SessionTask { get; set; }
public Task<string> SessionTask { get; }

/// <summary>
/// Token for cancelling a connection
/// </summary>
public CancellationToken CancellationToken { get; }

/// <summary>
/// Remember this session
/// </summary>
public bool RememberMe { get; }

/// <summary>
/// Remember a previous session and login automatically
/// </summary>
public bool AutoLogin { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public class Web3AuthConnectionProvider : ConnectionProvider, ILogoutHandler, IW
public override Sprite ButtonIcon { get; protected set; }

[field: SerializeField] public override string ButtonText { get; protected set; } = "Web3Auth";

[field: Space] [field: SerializeField] public string AppName { get; private set; } = "ChainSafe Gaming SDK";
[field: SerializeField] public string ClientId { get; private set; }

[field: SerializeField] public string RedirectUri { get; private set; }

[SerializeField] private string clientId;
[SerializeField] private string redirectUri;
[SerializeField] private Network network;
[field: SerializeField] public Network Network { get; private set; }
[field: SerializeField] public Web3Auth.ThemeModes Theme { get; private set; } = Web3Auth.ThemeModes.dark;
[field: SerializeField] public Web3Auth.Language Language { get; private set; } = Web3Auth.Language.en;

[Space]

Expand All @@ -56,6 +61,16 @@ public class Web3AuthConnectionProvider : ConnectionProvider, ILogoutHandler, IW

public override bool IsAvailable => true;

public Task<string> SessionTask { get; private set; }

public Task<Provider> ProviderTask => _rememberMe ? default : _modal.SelectProvider();

public CancellationToken CancellationToken => _rememberMe ? default : _modal.CancellationToken;

public bool RememberMe => _rememberMe || RememberSession;

public bool AutoLogin => _rememberMe;

#if UNITY_WEBGL && !UNITY_EDITOR

private TaskCompletionSource<string> _initializeTcs;
Expand Down Expand Up @@ -242,27 +257,4 @@ public Task OnWeb3Initialized(Web3 web3)
}

public bool AutoApproveTransactions => !enableWalletGui;

public Web3AuthOptions Web3AuthOptions => new Web3AuthOptions
{
clientId = clientId,
redirectUrl = new Uri(redirectUri),
network = network,
whiteLabel = new()
{
mode = Web3Auth.ThemeModes.dark,
defaultLanguage = Web3Auth.Language.en,
appName = "ChainSafe Gaming SDK",
}
};

public Task<string> SessionTask { get; set; }

public Task<Provider> ProviderTask => _rememberMe ? default : _modal.SelectProvider();

public CancellationToken CancellationToken => _rememberMe ? default : _modal.CancellationToken;

public bool RememberMe => _rememberMe || RememberSession;

public bool AutoLogin => _rememberMe;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override async Task<string> Connect()
if (!_config.AutoLogin && providerTask != null
//On webGL providerTask is always completed, so we don't have to go through another login flow.
#if UNITY_WEBGL && !UNITY_EDITOR
&& !providerTask.IsCompleted
&& !providerTask.IsCompleted
#endif
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,4 @@ public static IWeb3ServiceCollection UseWeb3AuthWallet(this IWeb3ServiceCollecti

return collection;
}

/// <summary>
/// Replaces the existing Web3AuthWallet configuration within an IWeb3ServiceCollection with the provided configuration.
/// </summary>
/// <param name="collection">The IWeb3ServiceCollection to configure the Web3AuthWallet within.</param>
/// <param name="configuration">The configuration for the Web3AuthWallet.</param>
/// <returns>The modified IWeb3ServiceCollection with the Web3AuthWallet configuration replaced.</returns>
public static IWeb3ServiceCollection ConfigureWeb3AuthWallet(this IWeb3ServiceCollection collection, IWeb3AuthConfig configuration)
{
collection.Replace(ServiceDescriptor.Singleton(typeof(IWeb3AuthConfig), configuration));
return collection;
}
}

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

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5aa8026

Please sign in to comment.