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 10, 2024
1 parent b0b7679 commit 72b39c4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void OnDestroy()
/// <param name="config"></param>
public void Init(InitConfig config)
{
UnityInnerChainInfo.SetChainInfo(config.chainInfo);
string json = JsonConvert.SerializeObject(config, Formatting.Indented);
SetInnerConfig(config.projectId, config.clientKey, config.appId, config.chainInfo);
InitParticleAuth(json);
}

Expand All @@ -137,10 +137,25 @@ public void InitWithJsonString(string json)
var chainName = (string)JObject.Parse(json)["chainName"];
var chainId = (long)JObject.Parse(json)["chainId"];
var chainInfo = ChainInfo.GetChain(chainId, chainName);
UnityInnerChainInfo.SetChainInfo(chainInfo);
var projectId = (string)JObject.Parse(json)["projectId"];
var clientKey = (string)JObject.Parse(json)["clientKey"];
var appId = (string)JObject.Parse(json)["appId"];
SetInnerConfig(projectId, clientKey, appId, chainInfo);
InitParticleAuth(json);
}

private void SetInnerConfig(string projectId, string clientKey, string appId, ChainInfo chainInfo)
{
if (projectId == "" || clientKey == "" || appId == "")
{
throw new ErrorException(0, "Init config is wrong");
}
ParticleUnityRpc.projectId = projectId;
ParticleUnityRpc.appId = appId;
ParticleUnityRpc.clientKey = clientKey;
UnityInnerChainInfo.SetChainInfo(chainInfo);
}

/// <summary>
/// Set language, support en, zh-CN, zh-TW, zh-HK, ja, ko
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ ParticleAuth.Instance.InitWithJsonString(jsonString)
// {"projectId":"34c6b829-5b89-44e8-90a9-6d982787b9c9","clientKey":"c6Z44Ml4TQeNhctvwYgdSv6DBzfjf6t6CB0JDscR","appId":"64f36641-b68c-4b19-aa10-5c5304d0eab3","chainName":"Base","chainId":84532,"securityAccount":{"promptSettingWhenSign":0,"promptMasterPasswordSettingWhenLogin":0},"wallet":{"displayWalletEntry":false,"defaultWalletEntryPosition":{"X":0.0,"Y":0.0},"supportChains":[{"id":84532,"name":"Base"},{"id":80002,"name":"Polygon"}]}}


// Enable Erc4337
ParticleAuth.Instance.SetERC4337(true);
// Enable erc4337
ParticleAuth.Instance.EnableERC4337(true);

// Set account name
ParticleAuth.Instance.SetERC4337(AAAccountName.BICONOMY_V2());

// login
var userInfo = await ParticleAuth.Instance.Login(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)

public class NodeService
{
private static string url = ParticleUnityRpc.Instance.rpcUrl;
private static string url = ParticleUnityRpc.rpcUrl;

private static string authenticate(string username, string password)
{
Expand All @@ -39,12 +39,12 @@ public async static Task<string> Request(string path, ParticleRpcRequest<object>

public async static Task<string> Request(string path, string postData)
{
Assert.IsTrue(!string.IsNullOrEmpty(ParticleUnityRpc.Instance.projectId), "Project ID is not set");
Assert.IsTrue(!string.IsNullOrEmpty(ParticleUnityRpc.Instance.clientKey),
Assert.IsTrue(!string.IsNullOrEmpty(ParticleUnityRpc.projectId), "Project ID is not set");
Assert.IsTrue(!string.IsNullOrEmpty(ParticleUnityRpc.clientKey),
"Project Client Key is not set");

string authorization = authenticate(ParticleUnityRpc.Instance.projectId,
ParticleUnityRpc.Instance.clientKey);
string authorization = authenticate(ParticleUnityRpc.projectId,
ParticleUnityRpc.clientKey);
Debug.Log($"Request params ${postData}");
byte[] postDataJson = System.Text.Encoding.UTF8.GetBytes(postData);
using (var www = UnityWebRequest.Post(url + path, UnityWebRequest.kHttpVerbPOST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
using UnityEngine;
using UnityEngine.Assertions;

public class ParticleUnityRpc : SingletonMonoBehaviour<ParticleUnityRpc>
public class ParticleUnityRpc
{
public string rpcUrl = "https://rpc.particle.network/";
public string projectId;
public string appId;
public string clientKey;

protected override void Awake()
{
base.Awake();
Assert.IsTrue(!string.IsNullOrEmpty(rpcUrl), "Please set the rpcUrl");
Assert.IsTrue(!string.IsNullOrEmpty(projectId), "Please set the projectId");
Assert.IsTrue(!string.IsNullOrEmpty(appId), "Please set the appId");
Assert.IsTrue(!string.IsNullOrEmpty(clientKey), "projectClientKey == null");
}
public static string rpcUrl = "https://rpc.particle.network/";
public static string projectId;
public static string appId;
public static string clientKey;
}

0 comments on commit 72b39c4

Please sign in to comment.