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

fix: web3 transactions & readonly methods #3447

Merged
merged 7 commits into from
Feb 28, 2025
Merged
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 @@ -321,6 +321,8 @@ private async UniTask FetchProfileAsync(CancellationToken ct)

// When the profile was already in cache, for example your previous account after logout, we need to ensure that all systems related to the profile will update
profile.IsDirty = true;
// Catalysts don't manipulate this field, so at this point we assume that the user is connected to web3
profile.HasConnectedWeb3 = true;
profileNameLabel!.Value = profile.Name;
characterPreviewController?.Initialize(profile.Avatar);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum DecentralandUrl
ApiEvents,

ApiAuth,
AuthSignature,
AuthSignatureWebApp,
ApiRpc,

GateKeeperSceneAdapter,
LocalGateKeeperSceneAdapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@ public class DecentralandUrlsSource : IDecentralandUrlsSource


private readonly Dictionary<DecentralandUrl, string> cache = new ();
private readonly string environmentDomainLowerCase;
private readonly ILaunchMode launchMode;

public string DecentralandDomain => environmentDomainLowerCase;
public string DecentralandDomain { get; }
public DecentralandEnvironment Environment { get; }

public DecentralandUrlsSource(DecentralandEnvironment environment, ILaunchMode launchMode)
{
environmentDomainLowerCase = environment.ToString()!.ToLower();
Environment = environment;
DecentralandDomain = environment.ToString()!.ToLower();
this.launchMode = launchMode;

switch (environment)
{
case DecentralandEnvironment.Org:
case DecentralandEnvironment.Zone:
ASSET_BUNDLE_URL = string.Format(ASSET_BUNDLE_URL_TEMPLATE, environmentDomainLowerCase);
GENESIS_URL = string.Format(GENESIS_URL_TEMPLATE, environmentDomainLowerCase);
ASSET_BUNDLE_URL = string.Format(ASSET_BUNDLE_URL_TEMPLATE, DecentralandDomain);
GENESIS_URL = string.Format(GENESIS_URL_TEMPLATE, DecentralandDomain);
break;
case DecentralandEnvironment.Today:

//The today environemnt is a mixture of the org and today enviroments.
//We want to fetch pointers from org, but asset bundles from today
//Thats because how peer-testing.decentraland.org works.
//Its a catalyst that replicates the org environment and eth network, but doesnt propagate back to the production catalysts
environmentDomainLowerCase = DecentralandEnvironment.Org.ToString()!.ToLower();
DecentralandDomain = DecentralandEnvironment.Org.ToString()!.ToLower();
ASSET_BUNDLE_URL = "https://ab-cdn.decentraland.today";

//On staging, we hardcode the catalyst because its the only valid one with a valid comms configuration
Expand All @@ -53,7 +54,7 @@ public string Url(DecentralandUrl decentralandUrl)
{
if (cache.TryGetValue(decentralandUrl, out string? url) == false)
{
url = RawUrl(decentralandUrl).Replace(ENV, environmentDomainLowerCase);
url = RawUrl(decentralandUrl).Replace(ENV, DecentralandDomain);
cache[decentralandUrl] = url;
}

Expand All @@ -76,7 +77,8 @@ private static string RawUrl(DecentralandUrl decentralandUrl) =>
DecentralandUrl.TermsOfUse => $"https://decentraland.{ENV}/terms",
DecentralandUrl.ApiPlaces => $"https://places.decentraland.{ENV}/api/places",
DecentralandUrl.ApiAuth => $"https://auth-api.decentraland.{ENV}",
DecentralandUrl.AuthSignature => $"https://decentraland.{ENV}/auth/requests",
DecentralandUrl.ApiRpc => $"wss://rpc.decentraland.{ENV}",
DecentralandUrl.AuthSignatureWebApp => $"https://decentraland.{ENV}/auth/requests",
DecentralandUrl.BuilderApiDtos => $"https://builder-api.decentraland.{ENV}/v1/collections/[COL-ID]/items",
DecentralandUrl.BuilderApiContent => $"https://builder-api.decentraland.{ENV}/v1/storage/contents/",
DecentralandUrl.POI => $"https://dcl-lists.decentraland.{ENV}/pois",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IDecentralandUrlsSource
const string LAUNCHER_DOWNLOAD_URL = "https://github.com/decentraland/launcher/releases/download";

string DecentralandDomain { get; }
DecentralandEnvironment Environment { get; }

string Url(DecentralandUrl decentralandUrl);
string GetHostnameForFeatureFlag();
Expand Down
2 changes: 1 addition & 1 deletion Explorer/Assets/DCL/Profiles/Components/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal set
}
}

public bool HasConnectedWeb3 { get; internal set; }
public bool HasConnectedWeb3 { get; set; }
public string? Description { get; set; }
public int TutorialStep { get; set; }
public string? Email { get; internal set; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using CommunicationData.URLHelpers;
using Cysharp.Threading.Tasks;
using DCL.Browser;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Web3.Abstract;
using DCL.Web3.Identities;
using System.Collections.Generic;
using System.Threading;

namespace DCL.Web3.Authenticators
{
public partial class DappWeb3Authenticator
{
public class Default : IWeb3VerifiedAuthenticator, IVerifiedEthereumApi
{
private readonly IWeb3VerifiedAuthenticator originAuth;
private readonly IVerifiedEthereumApi originApi;

public Default(IWeb3IdentityCache identityCache, IDecentralandUrlsSource decentralandUrlsSource, IWeb3AccountFactory web3AccountFactory)
{
URLAddress authApiUrl = URLAddress.FromString(decentralandUrlsSource.Url(DecentralandUrl.ApiAuth));
URLAddress signatureUrl = URLAddress.FromString(decentralandUrlsSource.Url(DecentralandUrl.AuthSignatureWebApp));
URLDomain rpcServerUrl = URLDomain.FromString(decentralandUrlsSource.Url(DecentralandUrl.ApiRpc));

var origin = new DappWeb3Authenticator(
new UnityAppWebBrowser(decentralandUrlsSource),
authApiUrl,
signatureUrl,
rpcServerUrl,
identityCache,
web3AccountFactory,
new HashSet<string>(
new[]
{
"eth_getBalance",
"eth_call",
"eth_blockNumber",
"eth_signTypedData_v4",
}
),
new HashSet<string>
{
"eth_getTransactionReceipt",
"eth_estimateGas",
"eth_call",
"eth_getBalance",
"eth_getStorageAt",
"eth_blockNumber",
"eth_gasPrice",
"eth_protocolVersion",
"net_version",
"web3_sha3",
"web3_clientVersion",
"eth_getTransactionCount",
"eth_getBlockByNumber",
"eth_getCode",
},
decentralandUrlsSource.Environment
);

originApi = origin;
originAuth = origin;
}

public void Dispose()
{
originAuth.Dispose(); // Disposes both
}

public UniTask<EthApiResponse> SendAsync(EthApiRequest request, CancellationToken ct) =>
originApi.SendAsync(request, ct);

public void AddVerificationListener(IVerifiedEthereumApi.VerificationDelegate callback) =>
originApi.AddVerificationListener(callback);

public UniTask<IWeb3Identity> LoginAsync(CancellationToken ct) =>
originAuth.LoginAsync(ct);

public UniTask LogoutAsync(CancellationToken cancellationToken) =>
originAuth.LogoutAsync(cancellationToken);

public void SetVerificationListener(IWeb3VerifiedAuthenticator.VerificationDelegate? callback) =>
originAuth.SetVerificationListener(callback);
}
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace DCL.Web3.Authenticators
{
public partial class DappWeb3Authenticator
{
[Serializable]
public struct LoginAuthApiRequest
{
public string method;
public object[] @params;
}
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ namespace DCL.Web3.Authenticators
public partial class DappWeb3Authenticator
{
[Serializable]
private struct LoginResponse
private struct LoginAuthApiResponse
{
public string requestId;
public string result;
public string sender;
}

[Serializable]
private struct MethodResponse<T>
{
public string requestId;
public T result;
public string sender;
}
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace DCL.Web3.Authenticators
{
public partial class DappWeb3Authenticator
{
[Serializable]
private struct MethodResponse
{
public string requestId;
public object result;
public string sender;
}
}
}

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

Loading