Skip to content

Commit e1bfdce

Browse files
committed
Merge remote-tracking branch 'origin/feat/auth_service_v10_change_plus_input_changes' into feat/auth_service_v10_change_plus_input_changes
2 parents 5819fd6 + 70cae01 commit e1bfdce

File tree

3 files changed

+66
-45
lines changed

3 files changed

+66
-45
lines changed

Assets/Plugins/Web3AuthSDK/Api/Models/ProjectConfigResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public class ProjectConfigResponse
1919
public List<AuthConnectionConfig> embeddedWalletAuth { get; set; }
2020
public bool sms_otp_enabled { get; set; }
2121
public bool wallet_connect_enabled { get; set; }
22-
public string wallet_connect_project_id { get; set; }
22+
public string walletConnectProjectId { get; set; }
2323
public WhiteLabelData whitelabel { get; set; }
2424
}

Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,19 @@ public IEnumerator createSession(LogoutApiRequest logoutApiRequest, Action<JObje
9999
callback(null);
100100
}
101101

102-
public IEnumerator fetchProjectConfig(string project_id, string network, Action<ProjectConfigResponse> callback)
102+
public IEnumerator fetchProjectConfig(string project_id, string network, string build_env, Action<ProjectConfigResponse> callback)
103103
{
104104
//Debug.Log("network =>" + network);
105105
string baseUrl = SIGNER_MAP[network];
106-
var requestURL = $"{baseUrl}/api/configuration?project_id={project_id}&network={network}&whitelist=true";
106+
var requestURL = $"{baseUrl}/api/v2/configuration?project_id={project_id}&network={network}&build_env={build_env}";
107107
var request = UnityWebRequest.Get(requestURL);
108108

109109
yield return request.SendWebRequest();
110110

111111
if (request.result == UnityWebRequest.Result.Success)
112112
{
113113
string result = request.downloadHandler.text;
114+
//Debug.Log("fetch config raw API result: " + result);
114115
callback(Newtonsoft.Json.JsonConvert.DeserializeObject<ProjectConfigResponse>(result));
115116
}
116117
else

Assets/Plugins/Web3AuthSDK/Web3Auth.cs

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Newtonsoft.Json.Linq;
1212
using Org.BouncyCastle.Math;
1313
using UnityEngine;
14-
using Web3AuthSDK.Editor;
1514

1615
public class Web3Auth : MonoBehaviour
1716
{
@@ -88,7 +87,7 @@ public void Awake()
8887
onDeepLinkActivated(Application.absoluteURL);
8988

9089
#if UNITY_EDITOR
91-
Web3AuthDebug.onURLRecieved += (Uri url) =>
90+
Web3AuthSDK.Editor.Web3AuthDebug.onURLRecieved += (Uri url) =>
9291
{
9392
this.setResultUrl(url);
9493
};
@@ -370,17 +369,28 @@ public async void showWalletUI(string path = "wallet")
370369
this.initParams["redirectUrl"] = Utils.GetCurrentURL();
371370
#endif
372371

373-
if (projectConfigResponse?.chains != null)
374-
{
375-
string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings
376-
{
377-
Converters = new List<JsonConverter> { new StringEnumConverter() },
378-
NullValueHandling = NullValueHandling.Ignore
379-
});
380-
this.initParams["chains"] = chainsJson;
381-
}
382-
383-
this.initParams["chainId"] = web3AuthOptions.defaultChainId ?? "0x1";
372+
if (projectConfigResponse?.chains != null && projectConfigResponse.chains.Count > 0)
373+
{
374+
string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings
375+
{
376+
Converters = new List<JsonConverter> { new StringEnumConverter() },
377+
NullValueHandling = NullValueHandling.Ignore
378+
});
379+
380+
this.initParams["chains"] = chainsJson;
381+
382+
// Set defaultChainId and chainId based on the first chain
383+
var firstChainId = projectConfigResponse.chains[0]?.chainId ?? web3AuthOptions.defaultChainId ?? "0x1";
384+
this.initParams["defaultChainId"] = firstChainId;
385+
this.initParams["chainId"] = firstChainId;
386+
}
387+
else
388+
{
389+
// Fallback to web3AuthOptions.defaultChainId or "0x1"
390+
string fallbackChainId = web3AuthOptions.defaultChainId ?? "0x1";
391+
this.initParams["defaultChainId"] = fallbackChainId;
392+
this.initParams["chainId"] = fallbackChainId;
393+
}
384394

385395
if (projectConfigResponse?.embeddedWalletAuth != null)
386396
{
@@ -643,16 +653,29 @@ public async void request(string method, JArray requestParams, string path = "wa
643653
this.initParams["redirectUrl"] = Utils.GetCurrentURL();
644654
#endif
645655

646-
if (projectConfigResponse?.chains != null)
647-
{
648-
string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings
649-
{
650-
Converters = new List<JsonConverter> { new StringEnumConverter() },
651-
NullValueHandling = NullValueHandling.Ignore
652-
});
653-
this.initParams["chains"] = chainsJson;
654-
}
655-
this.initParams["chainId"] = web3AuthOptions.defaultChainId ?? "0x1";
656+
if (projectConfigResponse?.chains != null && projectConfigResponse.chains.Count > 0)
657+
{
658+
string chainsJson = JsonConvert.SerializeObject(projectConfigResponse.chains, Formatting.None, new JsonSerializerSettings
659+
{
660+
Converters = new List<JsonConverter> { new StringEnumConverter() },
661+
NullValueHandling = NullValueHandling.Ignore
662+
});
663+
Debug.Log("Chain JSON:\n" + chainsJson);
664+
this.initParams["chains"] = chainsJson;
665+
666+
// Set defaultChainId and chainId based on the first chain
667+
var firstChainId = projectConfigResponse.chains[0]?.chainId ?? web3AuthOptions.defaultChainId ?? "0x1";
668+
this.initParams["defaultChainId"] = firstChainId;
669+
this.initParams["chainId"] = firstChainId;
670+
}
671+
else
672+
{
673+
// Fallback to web3AuthOptions.defaultChainId or "0x1"
674+
string fallbackChainId = web3AuthOptions.defaultChainId ?? "0x1";
675+
this.initParams["defaultChainId"] = fallbackChainId;
676+
this.initParams["chainId"] = fallbackChainId;
677+
}
678+
656679
if (projectConfigResponse?.embeddedWalletAuth != null)
657680
{
658681
this.initParams["embeddedWalletAuth"] = projectConfigResponse.embeddedWalletAuth;
@@ -671,6 +694,7 @@ public async void request(string method, JArray requestParams, string path = "wa
671694
}
672695

673696
var newSessionId = KeyStoreManagerUtils.generateRandomSessionKey();
697+
//Debug.Log("paramMap durinr request func: =>" + JsonConvert.SerializeObject(paramMap));
674698
string loginId = await createSession(JsonConvert.SerializeObject(paramMap, Formatting.None,
675699
new JsonSerializerSettings
676700
{
@@ -729,7 +753,7 @@ private void authorizeSession(string newSessionId, string origin)
729753
if (string.IsNullOrEmpty(newSessionId))
730754
{
731755
sessionId = KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID);
732-
Debug.Log("sessionId during authorizeSession in if part =>" + sessionId);
756+
//Debug.Log("sessionId during authorizeSession in if part =>" + sessionId);
733757
}
734758
else
735759
{
@@ -742,7 +766,7 @@ private void authorizeSession(string newSessionId, string origin)
742766
//Debug.Log("origin: =>" + origin);
743767
StartCoroutine(Web3AuthApi.getInstance().authorizeSession(pubKey, origin, (response =>
744768
{
745-
if (response != null)
769+
if (response != null && !string.IsNullOrEmpty(response.message))
746770
{
747771
var shareMetadata = JsonConvert.DeserializeObject<ShareMetadata>(response.message);
748772

@@ -913,29 +937,25 @@ private async Task<string> createSession(string data, long sessionTime, string a
913937
private async Task<bool> fetchProjectConfig()
914938
{
915939
TaskCompletionSource<bool> fetchProjectConfigResponse = new TaskCompletionSource<bool>();
916-
StartCoroutine(Web3AuthApi.getInstance().fetchProjectConfig(this.web3AuthOptions.clientId, this.web3AuthOptions.web3AuthNetwork.ToString().ToLower(), (response =>
940+
StartCoroutine(Web3AuthApi.getInstance().fetchProjectConfig(this.web3AuthOptions.clientId, this.web3AuthOptions.web3AuthNetwork.ToString().ToLower(),
941+
this.web3AuthOptions.authBuildEnv.ToString().ToLower(), (response =>
917942
{
918943
projectConfigResponse = response;
919944
if (response != null)
920945
{
921946
this.web3AuthOptions.originData = this.web3AuthOptions.originData.mergeMaps(response.whitelist?.signed_urls);
922947
if (response?.whitelabel != null)
923-
{
924-
if (this.web3AuthOptions.whiteLabel == null)
925-
{
926-
this.web3AuthOptions.whiteLabel = response.whitelabel;
927-
}
928-
else
929-
{
930-
this.web3AuthOptions.whiteLabel = this.web3AuthOptions.whiteLabel?.merge(response.whitelabel);
931-
}
932-
}
933-
934-
if (response?.whitelabel != null)
935-
{
936-
this.web3AuthOptions.whiteLabel = this.web3AuthOptions.whiteLabel == null ? response.whitelabel : this.web3AuthOptions.whiteLabel?.merge(response.whitelabel);
937-
this.web3AuthOptions.walletServicesConfig.whiteLabel = this.web3AuthOptions.walletServicesConfig.whiteLabel == null ? response.whitelabel : this.web3AuthOptions.walletServicesConfig.whiteLabel?.merge(response.whitelabel);
938-
}
948+
{
949+
var whitelabel = response.whitelabel;
950+
951+
this.web3AuthOptions.whiteLabel = this.web3AuthOptions.whiteLabel?.merge(whitelabel) ?? whitelabel;
952+
953+
if (this.web3AuthOptions.walletServicesConfig != null)
954+
{
955+
this.web3AuthOptions.walletServicesConfig.whiteLabel =
956+
this.web3AuthOptions.walletServicesConfig.whiteLabel?.merge(whitelabel) ?? whitelabel;
957+
}
958+
}
939959

940960
//Debug.Log("this.web3AuthOptions: =>" + JsonConvert.SerializeObject(this.web3AuthOptions));
941961

0 commit comments

Comments
 (0)