1111using Newtonsoft . Json . Linq ;
1212using Org . BouncyCastle . Math ;
1313using UnityEngine ;
14- using Web3AuthSDK . Editor ;
1514
1615public 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