Skip to content

Commit ee5d3be

Browse files
authored
Chore: adapter for thirdweb http client (#7180)
# Pull Request Description Fix #6995 [web3 test-scene ](decentraland/sdk7-test-scenes#51) ## What does this PR change? This PR replaces ThirdWeb http client with our own based on the WebRequestController. Main class to review is `DclThirdwebHttpClient.cs`. Additionally it - adds timeout for auto-login - handle auto-login for the edge case when user enters with cached ThirdWeb identity but feature-flag for this feature is disabled - added cancelations for ThirdWeb async methods ## Test Instructions ### Test Auth 1 smoke test on OTP login flow - normal otp login flow (happy path) - login/logout, changing accounts - auto-login for both OTP and Dapp accounts ### Test Auth 2 - login with OTP - close APP - open APP with disabled "alfa-email-otp-auth" feature flag - verify it takes you to new dapp login ### Test meta-transactions - test gifting - test donations - 9,49 in zone (you will need MANA on Sepolia to donate)
1 parent f1c53f0 commit ee5d3be

11 files changed

Lines changed: 332 additions & 110 deletions

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/BootstrapContainer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using DCL.Audio;
66
using DCL.Browser;
77
using DCL.DebugUtilities;
8-
using DCL.DebugUtilities.Views;
98
using DCL.Diagnostics;
109
using DCL.FeatureFlags;
1110
using DCL.Multiplayer.Connections.DecentralandUrls;
@@ -14,11 +13,11 @@
1413
using DCL.PluginSystem;
1514
using DCL.SceneLoadingScreens.SplashScreen;
1615
using DCL.Utility;
17-
using DCL.Web3;
1816
using DCL.Web3.Abstract;
1917
using DCL.Web3.Accounts.Factory;
2018
using DCL.Web3.Authenticators;
2119
using DCL.Web3.Identities;
20+
using DCL.WebRequests;
2221
using DCL.WebRequests.Analytics;
2322
using DCL.WebRequests.ChromeDevtool;
2423
using ECS.StreamableLoading.Cache.Disk;
@@ -128,7 +127,7 @@ await bootstrapContainer.InitializeContainerAsync<BootstrapContainer, BootstrapS
128127
var realmUrls = new RealmUrls(realmLaunchSettings, new RealmNamesMap(webRequestsContainer.WebRequestController), decentralandUrlsSource);
129128

130129
(container.Bootstrap, container.Analytics) = CreateBootstrapperAsync(debugSettings, applicationParametersParser, splashScreen, realmUrls, diskCache, partialsDiskCache, container, webRequestsContainer, container.settings, realmLaunchSettings, world, container.settings.BuildData, dclVersion, ct);
131-
container.CompositeWeb3Provider = CreateWeb3Dependencies(sceneLoaderSettings, web3AccountFactory, identityCache, browser, container, decentralandUrlsSource, decentralandEnvironment, applicationParametersParser);
130+
container.CompositeWeb3Provider = CreateWeb3Dependencies(sceneLoaderSettings, web3AccountFactory, identityCache, browser, container, decentralandUrlsSource, decentralandEnvironment, applicationParametersParser, webRequestsContainer.WebRequestController);
132131

133132
if (container.EnableAnalytics)
134133
{
@@ -225,7 +224,8 @@ private static ICompositeWeb3Provider CreateWeb3Dependencies(
225224
BootstrapContainer container,
226225
IDecentralandUrlsSource decentralandUrlsSource,
227226
DecentralandEnvironment dclEnvironment,
228-
IAppArgs appArgs)
227+
IAppArgs appArgs,
228+
IWebRequestController webRequestController)
229229
{
230230
int? identityExpirationDuration = appArgs.TryGetValue(AppArgsFlags.IDENTITY_EXPIRATION_DURATION, out string? v)
231231
? int.Parse(v!)
@@ -238,6 +238,7 @@ private static ICompositeWeb3Provider CreateWeb3Dependencies(
238238
new HashSet<string>(sceneLoaderSettings.Web3WhitelistMethods),
239239
new HashSet<string>(sceneLoaderSettings.Web3ReadOnlyMethods),
240240
web3AccountFactory,
241+
webRequestController,
241242
identityExpirationDuration
242243
);
243244

Explorer/Assets/DCL/Web3/Authenticators/ICompositeWeb3Provider.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
11
using Cysharp.Threading.Tasks;
2-
using System;
32

43
namespace DCL.Web3.Authenticators
54
{
6-
/// <summary>
7-
/// Information about a transaction that requires user confirmation
8-
/// </summary>
9-
public class TransactionConfirmationRequest
10-
{
11-
private const string ETH_SEND_TRANSACTION = "eth_sendTransaction";
12-
13-
public string Method { get; set; }
14-
public int ChainId { get; set; }
15-
16-
public bool IsTransaction => string.Equals(Method, ETH_SEND_TRANSACTION, StringComparison.OrdinalIgnoreCase);
17-
public string? NetworkName { get; set; }
18-
public string? To { get; set; }
19-
public string? Value { get; set; }
20-
public string? Data { get; set; }
21-
public object[]? Params { get; set; }
22-
23-
// Optional extra info (best-effort) for eth_sendTransaction UI
24-
public string? EstimatedGasFeeEth { get; set; }
25-
public string? BalanceEth { get; set; }
26-
27-
/// <summary>
28-
/// If true, hides the description text in the confirmation popup.
29-
/// Used for internal features (like Gifting) that have their own UI with description.
30-
/// </summary>
31-
public bool HideDescription { get; set; }
32-
33-
/// <summary>
34-
/// If true, hides the transaction details panel (balance, gas fee) in the confirmation popup.
35-
/// Used for internal features (like Gifting) that display this info in their own UI.
36-
/// </summary>
37-
public bool HideDetailsPanel { get; set; }
38-
}
39-
405
/// <summary>
416
/// Delegate for transaction confirmation callback.
427
/// Returns true if user confirms, false if user rejects.
@@ -55,21 +20,11 @@ public interface ICompositeWeb3Provider : IWeb3Authenticator, IEthereumApi, IDap
5520
/// </summary>
5621
AuthProvider CurrentProvider { get; set; }
5722

58-
/// <summary>
59-
/// Event fired when the authentication method changes
60-
/// </summary>
61-
event Action<AuthProvider>? OnMethodChanged;
62-
6323
/// <summary>
6424
/// Returns true if ThirdWeb OTP method is currently selected
6525
/// </summary>
6626
bool IsThirdWebOTP { get; }
6727

68-
/// <summary>
69-
/// Returns true if Dapp Wallet method is currently selected
70-
/// </summary>
71-
bool IsDappWallet { get; }
72-
7328
/// <summary>
7429
/// Sets the callback that will be invoked when a transaction requires user confirmation.
7530
/// The callback should return true if user confirms, false if user rejects.
Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Cysharp.Threading.Tasks;
2+
using DCL.FeatureFlags;
23
using DCL.PerformanceAndDiagnostics.Analytics;
34
using DCL.Prefs;
45
using DCL.Web3.Identities;
@@ -20,21 +21,7 @@ public class CompositeWeb3Provider : ICompositeWeb3Provider
2021
private readonly IWeb3IdentityCache identityCache;
2122
private readonly IAnalyticsController analytics;
2223

23-
private AuthProvider currentProvider = AuthProvider.Dapp;
24-
25-
public AuthProvider CurrentProvider
26-
{
27-
get => currentProvider;
28-
29-
set
30-
{
31-
if (currentProvider != value)
32-
{
33-
currentProvider = value;
34-
OnMethodChanged?.Invoke(value);
35-
}
36-
}
37-
}
24+
public AuthProvider CurrentProvider { get; set; } = AuthProvider.Dapp;
3825

3926
// IDappVerificationHandler - delegates to dappAuth
4027
public event Action<(int code, DateTime expiration, string requestId)>? VerificationRequired
@@ -43,13 +30,10 @@ public AuthProvider CurrentProvider
4330
remove => dappAuth.VerificationRequired -= value;
4431
}
4532

46-
public event Action<AuthProvider>? OnMethodChanged;
47-
public bool IsThirdWebOTP => currentProvider == AuthProvider.ThirdWeb;
48-
public bool IsDappWallet => currentProvider == AuthProvider.Dapp;
33+
public bool IsThirdWebOTP => CurrentProvider == AuthProvider.ThirdWeb;
4934

50-
private IWeb3Authenticator CurrentAuthenticator => currentProvider == AuthProvider.ThirdWeb ? thirdWebAuth : dappAuth;
51-
52-
private IEthereumApi CurrentEthereumApi => currentProvider == AuthProvider.ThirdWeb ? thirdWebAuth : dappAuth;
35+
private IWeb3Authenticator currentAuthenticator => CurrentProvider == AuthProvider.ThirdWeb ? thirdWebAuth : dappAuth;
36+
private IEthereumApi currentEthereumApi => CurrentProvider == AuthProvider.ThirdWeb ? thirdWebAuth : dappAuth;
5337

5438
public CompositeWeb3Provider(
5539
ThirdWebAuthenticator thirdWebAuth,
@@ -63,10 +47,17 @@ public CompositeWeb3Provider(
6347
this.analytics = analytics ?? throw new ArgumentNullException(nameof(analytics));
6448
}
6549

50+
public void Dispose()
51+
{
52+
thirdWebAuth.Dispose();
53+
dappAuth.Dispose();
54+
identityCache.Dispose();
55+
}
56+
6657
// IWeb3Authenticator
6758
public async UniTask<IWeb3Identity> LoginAsync(LoginPayload payload, CancellationToken ct)
6859
{
69-
IWeb3Identity identity = await CurrentAuthenticator.LoginAsync(payload, ct);
60+
IWeb3Identity identity = await currentAuthenticator.LoginAsync(payload, ct);
7061
identityCache.Identity = identity;
7162
analytics.Identify(identity);
7263
return identity;
@@ -75,7 +66,7 @@ public async UniTask<IWeb3Identity> LoginAsync(LoginPayload payload, Cancellatio
7566
public async UniTask LogoutAsync(CancellationToken ct)
7667
{
7768
analytics.Identify(null);
78-
await CurrentAuthenticator.LogoutAsync(ct);
69+
await currentAuthenticator.LogoutAsync(ct);
7970
identityCache.Clear();
8071
}
8172

@@ -92,30 +83,31 @@ public UniTask ResendOtpAsync(CancellationToken ct = default) =>
9283

9384
public UniTask<bool> TryAutoLoginAsync(CancellationToken ct)
9485
{
95-
// Temporary heuristic: if we have a stored email, assume ThirdWeb OTP flow; otherwise default to Dapp Wallet.
96-
string email = DCLPlayerPrefs.GetString(DCLPrefKeys.LOGGEDIN_EMAIL, string.Empty);
97-
CurrentProvider = string.IsNullOrEmpty(email) ? AuthProvider.Dapp : AuthProvider.ThirdWeb;
98-
99-
// Only ThirdWeb supports auto-login
100-
return CurrentProvider == AuthProvider.ThirdWeb
101-
? thirdWebAuth.TryAutoLoginAsync(ct)
102-
: UniTask.FromResult(true);
86+
if (OtpIsDisabled())
87+
DCLPlayerPrefs.DeleteKey(DCLPrefKeys.LOGGEDIN_EMAIL, save: true);
88+
89+
string storedEmail = DCLPlayerPrefs.GetString(DCLPrefKeys.LOGGEDIN_EMAIL, string.Empty);
90+
91+
// Heuristic: if we have a stored email, assume ThirdWeb OTP flow; otherwise default to Dapp Wallet.
92+
if (string.IsNullOrEmpty(storedEmail))
93+
{
94+
CurrentProvider = AuthProvider.Dapp;
95+
return UniTask.FromResult(true);
96+
}
97+
else
98+
{
99+
CurrentProvider = AuthProvider.ThirdWeb;
100+
return thirdWebAuth.TryAutoLoginAsync(ct);
101+
}
102+
103+
bool OtpIsDisabled() => !FeaturesRegistry.Instance.IsEnabled(FeatureId.EMAIL_OTP_AUTH);
103104
}
104105

105106
// IEthereumApi
106107
public UniTask<EthApiResponse> SendAsync(EthApiRequest request, Web3RequestSource source, CancellationToken ct) =>
107-
CurrentEthereumApi.SendAsync(request, source, ct);
108+
currentEthereumApi.SendAsync(request, source, ct);
108109

109-
public void SetTransactionConfirmationCallback(TransactionConfirmationDelegate? callback)
110-
{
110+
public void SetTransactionConfirmationCallback(TransactionConfirmationDelegate? callback) =>
111111
thirdWebAuth.SetTransactionConfirmationCallback(callback);
112-
}
113-
114-
public void Dispose()
115-
{
116-
thirdWebAuth.Dispose();
117-
dappAuth.Dispose();
118-
identityCache.Dispose();
119-
}
120112
}
121113
}

0 commit comments

Comments
 (0)