diff --git a/ChainSafe.Gaming.sln b/ChainSafe.Gaming.sln
index 58c9d95e1..aeac54666 100644
--- a/ChainSafe.Gaming.sln
+++ b/ChainSafe.Gaming.sln
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Unity.Ethe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Mud", "src\ChainSafe.Gaming.Mud\ChainSafe.Gaming.Mud.csproj", "{084E4FCB-9376-4B29-AA8C-6871E13906E6}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.EmbeddedWallet", "src\ChainSafe.Gaming.EmbeddedWallet\ChainSafe.Gaming.EmbeddedWallet.csproj", "{CFFFCC7F-946E-4371-A235-18250B6A5E09}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +163,12 @@ Global
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Release|Any CPU.Build.0 = Release|Any CPU
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Test|Any CPU.Build.0 = Debug|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Test|Any CPU.ActiveCfg = Debug|Any CPU
+ {CFFFCC7F-946E-4371-A235-18250B6A5E09}.Test|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs
new file mode 100644
index 000000000..bab136ced
--- /dev/null
+++ b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using ChainSafe.Gaming.EmbeddedWallet;
+using Network = Web3Auth.Network;
+using ThemeModes = Web3Auth.ThemeModes;
+using Language = Web3Auth.Language;
+
+namespace ChainSafe.GamingSdk.Web3Auth
+{
+ ///
+ /// Configuration options for initializing a Web3AuthWallet instance.
+ ///
+ 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; }
+
+ ///
+ /// Gets or sets the Web3AuthOptions for configuring the Web3Auth instance associated with the wallet.
+ ///
+ public Web3AuthOptions Web3AuthOptions => new Web3AuthOptions
+ {
+ clientId = ClientId,
+ redirectUrl = new Uri(RedirectUri),
+ network = Network,
+
+ whiteLabel = new()
+ {
+ mode = Theme,
+ defaultLanguage = Language,
+ appName = AppName,
+ }
+ };
+
+ ///
+ /// Login Provider to use when connecting the wallet, like Google, facebook etc...
+ ///
+ public Task ProviderTask { get; }
+
+ ///
+ /// Get the SessionId on connection from the provider.
+ ///
+ public Task SessionTask { get; }
+
+ ///
+ /// Token for cancelling a connection
+ ///
+ public CancellationToken CancellationToken { get; }
+
+ ///
+ /// Remember this session
+ ///
+ public bool RememberMe { get; }
+
+ ///
+ /// Remember a previous session and login automatically
+ ///
+ public bool AutoLogin { get; }
+ }
+}
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthWalletConfig.cs.meta b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs.meta
similarity index 100%
rename from Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthWalletConfig.cs.meta
rename to Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs.meta
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs
deleted file mode 100644
index 9a120b03b..000000000
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System;
-using ChainSafe.Gaming.Evm.Transactions;
-
-namespace ChainSafe.GamingSdk.Web3Auth
-{
- ///
- /// Handles web3Auth Transaction requests, approvals, declines and confirmations.
- ///
- public interface IWeb3AuthTransactionHandler
- {
- ///
- /// Invokes when transaction is requested.
- ///
- public event Action OnTransactionRequested;
-
- ///
- /// Invokes when transaction is confirmed on block.
- ///
- public event Action OnTransactionConfirmed;
-
- ///
- /// Transaction got approved.
- ///
- /// Transaction pool Id of Transaction that was approved.
- public void TransactionApproved(string transactionId);
-
- ///
- /// Transaction got declined.
- ///
- /// Transaction pool Id of Transaction that was declined.
- public void TransactionDeclined(string transactionId);
- }
-}
\ No newline at end of file
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs.meta b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs.meta
deleted file mode 100644
index e14c7cad5..000000000
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: e9c7983fd4e94aa19f276777cc939d57
-timeCreated: 1718962297
\ No newline at end of file
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab
index 381846fa4..b4d664b96 100644
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab
+++ b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab
@@ -6292,33 +6292,22 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
customTokenPlaceHolder: {fileID: 6238643033416456295}
- customNftPlaceHolder: {fileID: 3893186881389953187}
customTokenDisplayErc20Parent: {fileID: 5657123885924398801}
customNftDisplayParent: {fileID: 8176955415891050272}
customTokenDisplayErc20: {fileID: 1544044832913725164}
- customNftDisplay: {fileID: 6034000924353824336}
transferTokensContainer: {fileID: 6754551686753108061}
addCustomTokensMenu: {fileID: 7449198859952559396}
- addCustomNftMenu: {fileID: 1102691479002500486}
selectedTokenToTransfer: {fileID: 1643824617281436576}
customTokenAddressInput: {fileID: 1450622858095165912}
customTokenSymbolInput: {fileID: 3033696630416049437}
- customNftAddressInput: {fileID: 431849629550995913}
- customNftSymbolInput: {fileID: 7343186495474426007}
- customNftIdInput: {fileID: 6727692128954422283}
transferTokensWalletInput: {fileID: 7702073597766504067}
transferTokensAmountInput: {fileID: 3540026797197030748}
- customNftAmountText: {fileID: 8143053246957829318}
- customNftSymbolText: {fileID: 1935757266164244188}
customTokenAmountText: {fileID: 8346934949460858011}
customTokenSymbolText: {fileID: 6891909999124788805}
nativeTokenSymbolText: {fileID: 6256012485412186482}
nativeTokenAmountText: {fileID: 1012412206096704489}
addTokensMenuButton: {fileID: 1391477503969280662}
- addNftsMenuButton: {fileID: 3285911010377504504}
closeAddTokensMenuButton: {fileID: 5417894310233579526}
- closeAddNftMenuButton: {fileID: 176133887779786777}
- addNftButton: {fileID: 2207920767897871812}
addTokenButton: {fileID: 3172254933871926392}
transferTokensMenuButton: {fileID: 3166722148647569110}
closeTransferTokensButton: {fileID: 3090088527211704690}
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Scripts/Web3AuthWalletGUITxManager.cs b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Scripts/Web3AuthWalletGUITxManager.cs
index 4713d61db..231a7cbb3 100644
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Scripts/Web3AuthWalletGUITxManager.cs
+++ b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Scripts/Web3AuthWalletGUITxManager.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using ChainSafe.Gaming.EmbeddedWallet;
using ChainSafe.Gaming.Evm.Transactions;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.GamingSdk.Web3Auth;
@@ -33,8 +34,8 @@ public class Web3AuthWalletGUITxManager : MonoBehaviour
private int txHistoryDisplayCount = 20;
private bool _processingTransaction;
- private IWeb3AuthTransactionHandler _transactionHandler;
- private readonly Queue _transactionQueue = new();
+ private IEmbeddedWalletTransactionHandler _transactionHandler;
+ private TransactionPool _transactionPool;
#endregion
@@ -59,16 +60,15 @@ private void Awake()
rejectRequestButton.onClick.AddListener(RejectRequest);
autoTxToggle.onValueChanged.AddListener(ToggleAutoTx);
- _transactionHandler = Web3Unity.Web3.ServiceProvider.GetService();
+ _transactionHandler = Web3Unity.Web3.ServiceProvider.GetService();
+ _transactionPool = Web3Unity.Web3.ServiceProvider.GetService();
}
///
/// Populates the incoming transaction display.
///
- private void OnTransactionRequested(TransactionRequest request)
+ private void RequestTransaction(EmbeddedWalletTransaction transaction)
{
- _transactionQueue.Enqueue(request);
-
if (_processingTransaction)
{
return;
@@ -76,16 +76,14 @@ private void OnTransactionRequested(TransactionRequest request)
_processingTransaction = true;
- PromptTransactionRequest();
+ PromptTransactionRequest(transaction);
}
///
/// Prompts transaction request display.
///
- private void PromptTransactionRequest()
+ private void PromptTransactionRequest(EmbeddedWalletTransaction transaction)
{
- var transaction = _transactionQueue.Peek();
-
incomingTxNotification.SetActive(true);
if (AutoConfirmTransactions)
@@ -102,8 +100,8 @@ private void PromptTransactionRequest()
incomingTxPlaceHolder.SetActive(false);
incomingTxDisplay.SetActive(true);
- incomingTxHashText.text = transaction.Data;
- incomingTxActionText.text = transaction.Value?.ToString() ?? "Sign Request";
+ incomingTxHashText.text = transaction.Request.Data;
+ incomingTxActionText.text = transaction.Request.Value?.ToString() ?? "Sign Request";
}
///
@@ -111,9 +109,8 @@ private void PromptTransactionRequest()
///
private void AcceptRequest()
{
- var transaction = _transactionQueue.Dequeue();
ShowTxLoadingMenu();
- _transactionHandler.TransactionApproved(transaction.Id);
+ _transactionHandler.TransactionApproved();
ResetTransactionDisplay();
}
@@ -122,16 +119,17 @@ private void AcceptRequest()
///
private void RejectRequest()
{
- var transaction = _transactionQueue.Dequeue();
- _transactionHandler.TransactionDeclined(transaction.Id);
+ _transactionHandler.TransactionDeclined();
ResetTransactionDisplay();
}
///
/// Gets transaction data.
///
- private void OnTransactionConfirmed(TransactionResponse response)
+ private void OnTransactionConfirmed(EmbeddedWalletTransaction transaction)
{
+ var response = transaction.Response.Task.Result;
+
var txHash = response.Hash;
var txTime = DateTime.Now.ToString("hh:mm tt");
var txAmount = response.Value?.ToString() ?? "0";
@@ -180,9 +178,9 @@ private void ResetTransactionDisplay()
incomingTxDisplay.SetActive(false);
incomingTxPlaceHolder.SetActive(true);
// there's transactions in queue
- if (_transactionQueue.Count > 0)
+ if (_transactionPool.Count > 0)
{
- PromptTransactionRequest();
+ RequestTransaction(_transactionPool.Peek());
}
else
@@ -253,7 +251,7 @@ private void ToggleAutoTx(bool arg0)
private void OnEnable()
{
Web3AuthEventManager.ConfigureTxManager += OnConfigureTxManager;
- _transactionHandler.OnTransactionRequested += OnTransactionRequested;
+ _transactionHandler.OnTransactionQueued += RequestTransaction;
_transactionHandler.OnTransactionConfirmed += OnTransactionConfirmed;
}
@@ -263,7 +261,7 @@ private void OnEnable()
private void OnDisable()
{
Web3AuthEventManager.ConfigureTxManager -= OnConfigureTxManager;
- _transactionHandler.OnTransactionRequested -= OnTransactionRequested;
+ _transactionHandler.OnTransactionQueued -= RequestTransaction;
_transactionHandler.OnTransactionConfirmed -= OnTransactionConfirmed;
}
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthConnectionProvider.cs b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthConnectionProvider.cs
index fba8abe9c..396d1c2ed 100644
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthConnectionProvider.cs
+++ b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthConnectionProvider.cs
@@ -2,6 +2,7 @@
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Threading.Tasks;
using AOT;
using ChainSafe.Gaming;
@@ -22,16 +23,21 @@
/// ConnectionProvider for connecting wallet via Web3Auth.
///
[CreateAssetMenu(menuName = "ChainSafe/Connection Provider/Web3Auth", fileName = nameof(Web3AuthConnectionProvider))]
-public class Web3AuthConnectionProvider : ConnectionProvider, ILogoutHandler, IWeb3InitializedHandler
+public class Web3AuthConnectionProvider : ConnectionProvider, ILogoutHandler, IWeb3InitializedHandler, IWeb3AuthConfig
{
[field: SerializeField, DefaultAssetValue("Packages/io.chainsafe.web3-unity.web3auth/Runtime/Sprites/web3auth.png")]
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]
@@ -55,6 +61,16 @@ public class Web3AuthConnectionProvider : ConnectionProvider, ILogoutHandler, IW
public override bool IsAvailable => true;
+ public Task SessionTask { get; private set; }
+
+ public Task 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 _initializeTcs;
@@ -91,8 +107,8 @@ public override async Task Initialize(bool rememberSession)
}
//1155 is a decimal number, we need to convert it to an integer
- InitWeb3Auth(clientId, new HexBigInteger(BigInteger.Parse(chainConfig.ChainId)).HexValue,
- chainConfig.Rpc, chainConfig.Network, "", chainConfig.NativeCurrency.Symbol, "", network.ToString().ToLower(), Initialized, InitializeError);
+ InitWeb3Auth(ClientId, new HexBigInteger(BigInteger.Parse(chainConfig.ChainId)).HexValue,
+ chainConfig.Rpc, chainConfig.Network, "", chainConfig.NativeCurrency.Symbol, "", Network.ToString().ToLower(), Initialized, InitializeError);
await _initializeTcs.Task;
}
@@ -117,32 +133,8 @@ protected override void ConfigureServices(IWeb3ServiceCollection services)
DisplayModal();
}
- var web3AuthConfig = new Web3AuthWalletConfig
- {
- Web3AuthOptions = new()
- {
- clientId = clientId,
- redirectUrl = new Uri(redirectUri),
- network = network,
- whiteLabel = new()
- {
- mode = Web3Auth.ThemeModes.dark,
- defaultLanguage = Web3Auth.Language.en,
- appName = "ChainSafe Gaming SDK",
- }
- },
- RememberMe = _rememberMe || RememberSession,
-
- AutoLogin = _rememberMe,
- UseWalletGui = enableWalletGui
- };
-
- web3AuthConfig.CancellationToken = _rememberMe ? default : _modal.CancellationToken;
-
- web3AuthConfig.ProviderTask = _rememberMe ? default : _modal.SelectProvider();
-
#if UNITY_WEBGL && !UNITY_EDITOR
- web3AuthConfig.CancellationToken.Register(delegate
+ CancellationToken.Register(delegate
{
if (_connectionTcs != null && !_connectionTcs.Task.IsCompleted)
{
@@ -150,10 +142,10 @@ protected override void ConfigureServices(IWeb3ServiceCollection services)
}
});
- web3AuthConfig.SessionTask = Connect();
+ SessionTask = Connect();
#endif
- services.UseWeb3AuthWallet(web3AuthConfig);
+ services.UseWeb3AuthWallet(this);
services.AddSingleton(_ => this);
}
@@ -263,4 +255,6 @@ public Task OnWeb3Initialized(Web3 web3)
return Task.CompletedTask;
}
+
+ public bool AutoApproveTransactions => !enableWalletGui;
}
diff --git a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthProvider.cs b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthProvider.cs
index be5e853d2..b67a91ad8 100644
--- a/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthProvider.cs
+++ b/Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthProvider.cs
@@ -15,7 +15,7 @@
///
public class Web3AuthProvider : WalletProvider, IAccountProvider
{
- private readonly Web3AuthWalletConfig _config;
+ private readonly IWeb3AuthConfig _config;
private readonly IOperationTracker operationTracker;
private Web3Auth _coreInstance;
@@ -23,7 +23,7 @@ public class Web3AuthProvider : WalletProvider, IAccountProvider
private TaskCompletionSource