Skip to content

Commit

Permalink
update webgl
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhichao Link committed Sep 11, 2024
1 parent 7ca1a48 commit 4d3b4f2
Show file tree
Hide file tree
Showing 7 changed files with 1,308 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Authorization(string message, bool uniq)
public struct LoginConfig
{
/// <summary>
/// email,phone,jwt
/// support email | phone | jwt | google | apple | facebook | discord | twitter | twitch | microsoft | linkedin
/// </summary>
public string preferredAuthType;

Expand All @@ -144,7 +144,7 @@ public struct LoginConfig
public Authorization? authorization;

public LoginConfig(string preferredAuthType, string account, bool? hideLoading, string socialLoginPrompt,
Authorization authorization)
Authorization? authorization)
{
this.preferredAuthType = preferredAuthType;
this.account = account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public Task<string> Login(LoginConfig? config)
// Called from browser
public void OnLogin(string json)
{
loginTask?.TrySetResult(json);
HandleLoginResult(json, loginTask);
}

/// <summary>
Expand All @@ -232,7 +232,7 @@ public Task<bool> Logout()
LogoutParticle();
return logoutTask.Task;
}

// Called from browser
public void OnLogout()
{
Expand Down Expand Up @@ -269,6 +269,7 @@ public Task<string> GetSecurityAccount()
return getSecurityAccountTask.Task;
}

// Called from browser
public void OnGetSecurityAccount(string json)
{
getSecurityAccountTask?.TrySetResult(json);
Expand All @@ -292,12 +293,21 @@ public void OpenBuy(string options)
{
OpenParticleBuy(options);
}


/// <summary>
/// Get address base on current chainInfo
/// </summary>
/// <returns></returns>
public string GetWalletAddress()
{
return GetParticleWalletAddress();
}

/// <summary>
/// Switch chain
/// </summary>
/// <param name="chainInfo"></param>
/// <returns></returns>
public Task<string> SwitchChain(ChainInfo chainInfo)
{
switchChainTask = new TaskCompletionSource<string>();
Expand All @@ -311,6 +321,11 @@ public void OnSwitchChain(string json)
switchChainTask?.TrySetResult(json);
}

/// <summary>
/// EVM send transaction
/// </summary>
/// <param name="transaction">The EVM transaction requires a hexadecimal string.</param>
/// <returns></returns>
public Task<string> EVMSendTransaction(string transaction)
{
var jsonString = "";
Expand All @@ -335,9 +350,9 @@ public void OnEVMSendTransaction(string json)
}

/// <summary>
/// Personal sign
/// EVM personal sign
/// </summary>
/// <param name="message">Message</param>
/// <param name="message">The message requires a hexadecimal string.</param>
/// <param name="accountName">Optional, if you are using smart account, should provide this value</param>
/// <returns></returns>
public Task<string> EVMPersonalSign(string message, [CanBeNull] AAAccountName accountName = null)
Expand All @@ -358,6 +373,11 @@ public void OnEVMPersonalSign(string json)
}


/// <summary>
/// EVM personal sign unique
/// </summary>
/// <param name="message">The message requires a hexadecimal string.</param>
/// <returns></returns>
public Task<string> EVMPersonalSignUniq(string message)
{
evmPersonalSignUniqTask = new TaskCompletionSource<string>();
Expand All @@ -370,6 +390,11 @@ public void OnEVMPersonalSignUniq(string json)
HandleSignResult(json, evmPersonalSignUniqTask);
}

/// <summary>
/// EVM sign typed data
/// </summary>
/// <param name="message">The message requires a json string.</param>
/// <returns></returns>
public Task<string> EVMSignTypedData(string message)
{
evmSignTypedDataTask = new TaskCompletionSource<string>();
Expand All @@ -382,6 +407,11 @@ public void OnEVMSignTypedData(string json)
HandleSignResult(json, evmSignTypedDataTask);
}

/// <summary>
/// EVM sign typed data unique
/// </summary>
/// <param name="message">The message requires a json string.</param>
/// <returns></returns>
public Task<string> EVMSignTypedDataUniq(string message)
{
evmSignTypedDataUniqTask = new TaskCompletionSource<string>();
Expand All @@ -394,6 +424,11 @@ public void OnEVMSignTypedDataUniq(string json)
HandleSignResult(json, evmSignTypedDataUniqTask);
}

/// <summary>
/// Solana sign and send transaction
/// </summary>
/// <param name="transaction">The Solana transaction requires a base58 string.</param>
/// <returns></returns>
public Task<string> SolanaSignAndSendTransaction(string transaction)
{
solanaSignAndSendTransactionTask = new TaskCompletionSource<string>();
Expand All @@ -406,6 +441,11 @@ public void OnSolanaSignAndSendTransaction(string json)
HandleSignResult(json, solanaSignAndSendTransactionTask);
}

/// <summary>
/// Solana sign message
/// </summary>
/// <param name="transaction">The message requires a base58 string.</param>
/// <returns></returns>
public Task<string> SolanaSignMessage(string transaction)
{
solanaSignMessageTask = new TaskCompletionSource<string>();
Expand All @@ -418,6 +458,11 @@ public void OnSolanaSignMessage(string json)
HandleSignResult(json, solanaSignMessageTask);
}

/// <summary>
/// Solana sign transaction
/// </summary>
/// <param name="transaction">The Solana transaction requires a base58 string.</param>
/// <returns></returns>
public Task<string> SolanaSignTransaction(string transaction)
{
solanaSignTransactionTask = new TaskCompletionSource<string>();
Expand All @@ -430,6 +475,11 @@ public void OnSolanaSignTransaction(string json)
HandleSignResult(json, solanaSignTransactionTask);
}

/// <summary>
/// Solana sign all transactions
/// </summary>
/// <param name="transactions">Each Solana transaction requires a base58 string.</param>
/// <returns></returns>
public Task<List<string>> SolanaSignAllTransactions(string[] transactions)
{
solanaSignAllTransactionsTask = new TaskCompletionSource<List<string>>();
Expand All @@ -443,17 +493,22 @@ public void OnSolanaSignAllTransactions(string json)
HandleSignResult(json, solanaSignAllTransactionsTask);
}

private void HandleLoginResult<T>(string json, TaskCompletionSource<T> task)
{
HandleResult(json, task, "");
}

private void HandleSignResult<T>(string json, TaskCompletionSource<T> task)
{
HandleResult(json, task, "signature");
}

private void HandleResult<T>(string json, TaskCompletionSource<T> task, string key)
{
Debug.Log($"handle result {json}");
var jsonObject = JObject.Parse(json);

if (jsonObject.ContainsKey("signature"))
{
var signature = jsonObject["signature"]!.ToObject<T>();
task?.TrySetResult(signature);
}
else if (jsonObject.ContainsKey("error"))

if (jsonObject.ContainsKey("error"))
{
var error = jsonObject.GetValue("error");

Expand All @@ -479,6 +534,15 @@ private void HandleSignResult<T>(string json, TaskCompletionSource<T> task)
task.SetException(new ErrorException(0, "Unknown error: 'error' object missing"));
}
}
else if (jsonObject.ContainsKey(key))
{
var value = jsonObject[key]!.ToObject<T>();
task?.TrySetResult(value);
}
else
{
task?.TrySetResult((T)(object)json);
}
}

private string HexToString(string hex)
Expand Down
Loading

0 comments on commit 4d3b4f2

Please sign in to comment.