Skip to content

Commit

Permalink
fix: beacon webgl connection fix + missing kukai network parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
talha-trili committed Nov 12, 2024
1 parent 43962d6 commit ffc2b87
Show file tree
Hide file tree
Showing 10 changed files with 1,134 additions and 773 deletions.
6 changes: 1 addition & 5 deletions Runtime/Scripts/Request/Rpc/Rpc.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System.Text.Json;
using Netezos.Rpc.Queries.Post;
using Tezos.Cysharp.Threading.Tasks;
using Tezos.Cysharp.Threading.Tasks;

namespace Tezos.Request
{
public class Rpc : TezosClient
{
private const string CHAIN_ID = "NetXdQprcVkpaWU";

public Rpc(int timeOut) : base(timeOut)
{
}
Expand Down
93 changes: 41 additions & 52 deletions Runtime/Scripts/SocialLoginProvider/Kukai/Helpers/UrlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,31 @@

namespace Tezos.SocialLoginProvider
{

/// <summary>
/// Generates URLs for login and wallet operations to be opened in system browsers to be sent to Kukai Embed.
/// </summary>
public class UrlGenerator
{
private readonly string _deepLinkUrl;

public UrlGenerator(string deepLinkUrl)
{
_deepLinkUrl = deepLinkUrl;
}
public UrlGenerator(string deepLinkUrl) { _deepLinkUrl = deepLinkUrl; }

/// <summary>
/// Generates a login URL.
/// </summary>
/// <param name="nonce">The nonce for the login request.</param>
/// <param name="projectId">The project ID associated with the login request.</param>
/// <returns>A login URL to be sent to Kukai Embed.</returns>
public string GenerateLoginLink(string nonce, string projectId)
public string GenerateLoginLink(string nonce, string projectId, string network)
{
return BuildUrl(ActionTypes.LOGIN, new Dictionary<string, string>
{
{
"nonce", nonce
},
{
"projectId", projectId
}
});
return BuildUrl(
ActionTypes.LOGIN, new Dictionary<string, string>
{
{ "network", network.ToLower() },
{ "nonce", nonce },
{ "projectId", projectId }
}
);
}

/// <summary>
Expand All @@ -49,7 +44,7 @@ public string GenerateLoginLink(string nonce, string projectId)
private string BuildUrl(string action, Dictionary<string, string> queryParams)
{
var uriBuilder = new UriBuilder(_deepLinkUrl);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["action"] = action;

foreach (var param in queryParams)
Expand All @@ -68,20 +63,19 @@ private string BuildUrl(string action, Dictionary<string, string> queryParams)
/// <param name="walletAddress">The wallet address.</param>
/// <param name="typeOfLogin">The type of login.</param>
/// <returns>An operation URL to be sent to Kukai Embed.</returns>
public string GenerateOperationLink(OperationRequest req, string walletAddress, TypeOfLogin typeOfLogin)
public string GenerateOperationLink(OperationRequest req, string walletAddress, TypeOfLogin typeOfLogin, string network)
{
var serializedRequest = SerializeWalletOperationRequest(req, walletAddress);
TezosLogger.LogDebug($"JSON Payload: {serializedRequest}");

var url = BuildUrl(ActionTypes.OPERATION, new Dictionary<string, string>
{
{
"typeOfLogin", typeOfLogin.ToString().ToLower()
},
{
"operation", Uri.EscapeDataString(serializedRequest)
}
});
var url = BuildUrl(
ActionTypes.OPERATION, new Dictionary<string, string>
{
{ "network", network.ToLower() },
{ "typeOfLogin", typeOfLogin.ToString().ToLower() },
{ "operation", Uri.EscapeDataString(serializedRequest) }
}
);

TezosLogger.LogDebug($"Generated URL: {url}");
return url;
Expand All @@ -96,38 +90,33 @@ public string GenerateOperationLink(OperationRequest req, string walletAddress,
private string SerializeWalletOperationRequest(OperationRequest request, string walletAddress)
{
var jsonObject = new JObject
{
["kind"] = "transaction",
["source"] = walletAddress,
["amount"] = request.Amount.ToString(),
["destination"] = request.Destination,
["parameters"] = new JObject
{
["entrypoint"] = request.EntryPoint,
["value"] = JToken.Parse(request.Arg)
}
};
{
["kind"] = "transaction",
["source"] = walletAddress,
["amount"] = request.Amount.ToString(),
["destination"] = request.Destination,
["parameters"] = new JObject
{
["entrypoint"] = request.EntryPoint,
["value"] = JToken.Parse(request.Arg)
}
};

var jsonArray = new JArray
{
jsonObject
};
var jsonArray = new JArray { jsonObject };

return jsonArray.ToString(Formatting.None);
}

public string GenerateSignLink(SignPayloadRequest signRequest, TypeOfLogin typeOfLogin)
public string GenerateSignLink(SignPayloadRequest signRequest, TypeOfLogin typeOfLogin, string network)
{
return BuildUrl(ActionTypes.SIGN, new Dictionary<string, string>
{
{
"typeOfLogin", typeOfLogin.ToString().ToLower()
},
{
"expression", Uri.EscapeDataString(signRequest.Payload)
}
});
return BuildUrl(
ActionTypes.SIGN, new Dictionary<string, string>
{
{ "network", network.ToLower() },
{ "typeOfLogin", typeOfLogin.ToString().ToLower() },
{ "expression", Uri.EscapeDataString(signRequest.Payload) }
}
);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class KukaiMobileProvider : IAndroidProvider, IiOSProvider

private readonly UrlParser _urlParser = new();

private string _network => ConfigGetter.GetOrCreateConfig<TezosConfig>().Network.ToString();

private UniTaskCompletionSource<OperationResponse> _operationTcs;
private UniTaskCompletionSource<SignPayloadResponse> _signPayloadTcs;

Expand Down Expand Up @@ -221,7 +223,7 @@ private void InitializeDeepLinking()

private void OpenLoginLink()
{
var loginLink = _urlGenerator.GenerateLoginLink("my_nonce", "my_project_id");
var loginLink = _urlGenerator.GenerateLoginLink("my_nonce", "my_project_id", _network);

OpenLink(loginLink);
}
Expand Down Expand Up @@ -293,9 +295,9 @@ private void OpenOperationLink(OperationRequest request)
return;
}

var operationLink = _urlGenerator.GenerateOperationLink(request, SocialProviderData.WalletAddress, SocialProviderData.LoginType);
var operationLink = _urlGenerator.GenerateOperationLink(request, SocialProviderData.WalletAddress, SocialProviderData.LoginType, _network);
Debug.Log($"operationLink:{operationLink}");

OpenLink(operationLink);
}

Expand All @@ -315,10 +317,10 @@ public async UniTask<SignPayloadResponse> RequestSignPayload(SignPayloadRequest
_signPayloadTcs = new();

signPayloadRequest.SigningType = SignPayloadType.RAW;
var signLink = _urlGenerator.GenerateSignLink(signPayloadRequest, _typeOfLogin);
var signLink = _urlGenerator.GenerateSignLink(signPayloadRequest, _typeOfLogin, _network);

OpenLink(signLink);

return await _signPayloadTcs.WithTimeout(_tezosConfig.RequestTimeoutSeconds * 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion WebGLFrontend/output/StreamingAssets/webgl-frontend.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ PERFORMANCE OF THIS SOFTWARE.
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! typedarray-to-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [[email protected]]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/
2 changes: 1 addition & 1 deletion WebGLFrontend/output/StreamingAssets/webgl-frontend.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ffc2b87

Please sign in to comment.