Skip to content

Commit a31904d

Browse files
authored
Embedded Wallet PR - 1 (#1272)
* wallet overlay prefab * checkpoint * checkpoint * embedded wallet implemented for transactions * cleanup and documentation * requested changes made
1 parent 3c58f67 commit a31904d

53 files changed

Lines changed: 31502 additions & 301 deletions

File tree

Some content is hidden

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

ChainSafe.Gaming.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Unity.Ethe
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Mud", "src\ChainSafe.Gaming.Mud\ChainSafe.Gaming.Mud.csproj", "{084E4FCB-9376-4B29-AA8C-6871E13906E6}"
4949
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.EmbeddedWallet", "src\ChainSafe.Gaming.EmbeddedWallet\ChainSafe.Gaming.EmbeddedWallet.csproj", "{CFFFCC7F-946E-4371-A235-18250B6A5E09}"
51+
EndProject
5052
Global
5153
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5254
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +163,12 @@ Global
161163
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Release|Any CPU.Build.0 = Release|Any CPU
162164
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Test|Any CPU.ActiveCfg = Debug|Any CPU
163165
{084E4FCB-9376-4B29-AA8C-6871E13906E6}.Test|Any CPU.Build.0 = Debug|Any CPU
166+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
168+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
169+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Release|Any CPU.Build.0 = Release|Any CPU
170+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Test|Any CPU.ActiveCfg = Debug|Any CPU
171+
{CFFFCC7F-946E-4371-A235-18250B6A5E09}.Test|Any CPU.Build.0 = Debug|Any CPU
164172
EndGlobalSection
165173
GlobalSection(SolutionProperties) = preSolution
166174
HideSolutionNode = FALSE
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using ChainSafe.Gaming.EmbeddedWallet;
5+
using Network = Web3Auth.Network;
6+
using ThemeModes = Web3Auth.ThemeModes;
7+
using Language = Web3Auth.Language;
8+
9+
namespace ChainSafe.GamingSdk.Web3Auth
10+
{
11+
/// <summary>
12+
/// Configuration options for initializing a Web3AuthWallet instance.
13+
/// </summary>
14+
public interface IWeb3AuthConfig : IEmbeddedWalletConfig
15+
{
16+
// Name of the App.
17+
public string AppName { get; }
18+
// Client ID you get from Web3Auth dashboard.
19+
public string ClientId { get; }
20+
// Redirect URI for the app.
21+
public string RedirectUri { get; }
22+
// Network to connect to (MainNet, TestNet...).
23+
public Network Network { get; }
24+
public ThemeModes Theme { get; }
25+
public Language Language { get; }
26+
27+
/// <summary>
28+
/// Gets or sets the Web3AuthOptions for configuring the Web3Auth instance associated with the wallet.
29+
/// </summary>
30+
public Web3AuthOptions Web3AuthOptions => new Web3AuthOptions
31+
{
32+
clientId = ClientId,
33+
redirectUrl = new Uri(RedirectUri),
34+
network = Network,
35+
36+
whiteLabel = new()
37+
{
38+
mode = Theme,
39+
defaultLanguage = Language,
40+
appName = AppName,
41+
}
42+
};
43+
44+
/// <summary>
45+
/// Login Provider to use when connecting the wallet, like Google, facebook etc...
46+
/// </summary>
47+
public Task<Provider> ProviderTask { get; }
48+
49+
/// <summary>
50+
/// Get the SessionId on connection from the provider.
51+
/// </summary>
52+
public Task<string> SessionTask { get; }
53+
54+
/// <summary>
55+
/// Token for cancelling a connection
56+
/// </summary>
57+
public CancellationToken CancellationToken { get; }
58+
59+
/// <summary>
60+
/// Remember this session
61+
/// </summary>
62+
public bool RememberMe { get; }
63+
64+
/// <summary>
65+
/// Remember a previous session and login automatically
66+
/// </summary>
67+
public bool AutoLogin { get; }
68+
}
69+
}

Packages/io.chainsafe.web3-unity.web3auth/Runtime/Web3AuthWalletConfig.cs.meta renamed to Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthConfig.cs.meta

File renamed without changes.

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

Packages/io.chainsafe.web3-unity.web3auth/Runtime/IWeb3AuthTransactionHandler.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Packages/io.chainsafe.web3-unity.web3auth/Runtime/WalletGUI/Prefabs/Web3AuthWalletGUI.prefab

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6292,33 +6292,22 @@ MonoBehaviour:
62926292
m_Name:
62936293
m_EditorClassIdentifier:
62946294
customTokenPlaceHolder: {fileID: 6238643033416456295}
6295-
customNftPlaceHolder: {fileID: 3893186881389953187}
62966295
customTokenDisplayErc20Parent: {fileID: 5657123885924398801}
62976296
customNftDisplayParent: {fileID: 8176955415891050272}
62986297
customTokenDisplayErc20: {fileID: 1544044832913725164}
6299-
customNftDisplay: {fileID: 6034000924353824336}
63006298
transferTokensContainer: {fileID: 6754551686753108061}
63016299
addCustomTokensMenu: {fileID: 7449198859952559396}
6302-
addCustomNftMenu: {fileID: 1102691479002500486}
63036300
selectedTokenToTransfer: {fileID: 1643824617281436576}
63046301
customTokenAddressInput: {fileID: 1450622858095165912}
63056302
customTokenSymbolInput: {fileID: 3033696630416049437}
6306-
customNftAddressInput: {fileID: 431849629550995913}
6307-
customNftSymbolInput: {fileID: 7343186495474426007}
6308-
customNftIdInput: {fileID: 6727692128954422283}
63096303
transferTokensWalletInput: {fileID: 7702073597766504067}
63106304
transferTokensAmountInput: {fileID: 3540026797197030748}
6311-
customNftAmountText: {fileID: 8143053246957829318}
6312-
customNftSymbolText: {fileID: 1935757266164244188}
63136305
customTokenAmountText: {fileID: 8346934949460858011}
63146306
customTokenSymbolText: {fileID: 6891909999124788805}
63156307
nativeTokenSymbolText: {fileID: 6256012485412186482}
63166308
nativeTokenAmountText: {fileID: 1012412206096704489}
63176309
addTokensMenuButton: {fileID: 1391477503969280662}
6318-
addNftsMenuButton: {fileID: 3285911010377504504}
63196310
closeAddTokensMenuButton: {fileID: 5417894310233579526}
6320-
closeAddNftMenuButton: {fileID: 176133887779786777}
6321-
addNftButton: {fileID: 2207920767897871812}
63226311
addTokenButton: {fileID: 3172254933871926392}
63236312
transferTokensMenuButton: {fileID: 3166722148647569110}
63246313
closeTransferTokensButton: {fileID: 3090088527211704690}

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using ChainSafe.Gaming.EmbeddedWallet;
34
using ChainSafe.Gaming.Evm.Transactions;
45
using ChainSafe.Gaming.UnityPackage;
56
using ChainSafe.GamingSdk.Web3Auth;
@@ -33,8 +34,8 @@ public class Web3AuthWalletGUITxManager : MonoBehaviour
3334
private int txHistoryDisplayCount = 20;
3435

3536
private bool _processingTransaction;
36-
private IWeb3AuthTransactionHandler _transactionHandler;
37-
private readonly Queue<TransactionRequest> _transactionQueue = new();
37+
private IEmbeddedWalletTransactionHandler _transactionHandler;
38+
private TransactionPool _transactionPool;
3839

3940
#endregion
4041

@@ -59,33 +60,30 @@ private void Awake()
5960
rejectRequestButton.onClick.AddListener(RejectRequest);
6061
autoTxToggle.onValueChanged.AddListener(ToggleAutoTx);
6162

62-
_transactionHandler = Web3Unity.Web3.ServiceProvider.GetService<IWeb3AuthTransactionHandler>();
63+
_transactionHandler = Web3Unity.Web3.ServiceProvider.GetService<IEmbeddedWalletTransactionHandler>();
64+
_transactionPool = Web3Unity.Web3.ServiceProvider.GetService<TransactionPool>();
6365
}
6466

6567
/// <summary>
6668
/// Populates the incoming transaction display.
6769
/// </summary>
68-
private void OnTransactionRequested(TransactionRequest request)
70+
private void RequestTransaction(EmbeddedWalletTransaction transaction)
6971
{
70-
_transactionQueue.Enqueue(request);
71-
7272
if (_processingTransaction)
7373
{
7474
return;
7575
}
7676

7777
_processingTransaction = true;
7878

79-
PromptTransactionRequest();
79+
PromptTransactionRequest(transaction);
8080
}
8181

8282
/// <summary>
8383
/// Prompts transaction request display.
8484
/// </summary>
85-
private void PromptTransactionRequest()
85+
private void PromptTransactionRequest(EmbeddedWalletTransaction transaction)
8686
{
87-
var transaction = _transactionQueue.Peek();
88-
8987
incomingTxNotification.SetActive(true);
9088

9189
if (AutoConfirmTransactions)
@@ -102,18 +100,17 @@ private void PromptTransactionRequest()
102100

103101
incomingTxPlaceHolder.SetActive(false);
104102
incomingTxDisplay.SetActive(true);
105-
incomingTxHashText.text = transaction.Data;
106-
incomingTxActionText.text = transaction.Value?.ToString() ?? "Sign Request";
103+
incomingTxHashText.text = transaction.Request.Data;
104+
incomingTxActionText.text = transaction.Request.Value?.ToString() ?? "Sign Request";
107105
}
108106

109107
/// <summary>
110108
/// Accepts an incoming transaction request.
111109
/// </summary>
112110
private void AcceptRequest()
113111
{
114-
var transaction = _transactionQueue.Dequeue();
115112
ShowTxLoadingMenu();
116-
_transactionHandler.TransactionApproved(transaction.Id);
113+
_transactionHandler.TransactionApproved();
117114
ResetTransactionDisplay();
118115
}
119116

@@ -122,16 +119,17 @@ private void AcceptRequest()
122119
/// </summary>
123120
private void RejectRequest()
124121
{
125-
var transaction = _transactionQueue.Dequeue();
126-
_transactionHandler.TransactionDeclined(transaction.Id);
122+
_transactionHandler.TransactionDeclined();
127123
ResetTransactionDisplay();
128124
}
129125

130126
/// <summary>
131127
/// Gets transaction data.
132128
/// </summary>
133-
private void OnTransactionConfirmed(TransactionResponse response)
129+
private void OnTransactionConfirmed(EmbeddedWalletTransaction transaction)
134130
{
131+
var response = transaction.Response.Task.Result;
132+
135133
var txHash = response.Hash;
136134
var txTime = DateTime.Now.ToString("hh:mm tt");
137135
var txAmount = response.Value?.ToString() ?? "0";
@@ -180,9 +178,9 @@ private void ResetTransactionDisplay()
180178
incomingTxDisplay.SetActive(false);
181179
incomingTxPlaceHolder.SetActive(true);
182180
// there's transactions in queue
183-
if (_transactionQueue.Count > 0)
181+
if (_transactionPool.Count > 0)
184182
{
185-
PromptTransactionRequest();
183+
RequestTransaction(_transactionPool.Peek());
186184
}
187185

188186
else
@@ -253,7 +251,7 @@ private void ToggleAutoTx(bool arg0)
253251
private void OnEnable()
254252
{
255253
Web3AuthEventManager.ConfigureTxManager += OnConfigureTxManager;
256-
_transactionHandler.OnTransactionRequested += OnTransactionRequested;
254+
_transactionHandler.OnTransactionQueued += RequestTransaction;
257255
_transactionHandler.OnTransactionConfirmed += OnTransactionConfirmed;
258256
}
259257

@@ -263,7 +261,7 @@ private void OnEnable()
263261
private void OnDisable()
264262
{
265263
Web3AuthEventManager.ConfigureTxManager -= OnConfigureTxManager;
266-
_transactionHandler.OnTransactionRequested -= OnTransactionRequested;
264+
_transactionHandler.OnTransactionQueued -= RequestTransaction;
267265
_transactionHandler.OnTransactionConfirmed -= OnTransactionConfirmed;
268266
}
269267

0 commit comments

Comments
 (0)