@@ -100,47 +100,56 @@ public void Awake()
100100// this.setResultUrl(new Uri($"http://localhost#{code}"));
101101// }
102102#endif
103- authorizeSession ( "" ) ;
104103 }
105104
106- public void setOptions ( Web3AuthOptions web3AuthOptions )
105+ public async void setOptions ( Web3AuthOptions web3AuthOptions )
107106 {
108- JsonSerializerSettings settings = new JsonSerializerSettings
107+ this . web3AuthOptions = web3AuthOptions ;
108+
109+ bool isfetchConfigSuccess = await fetchProjectConfig ( ) ;
110+
111+ if ( ! isfetchConfigSuccess )
109112 {
110- Converters = new List < JsonConverter > { new StringEnumConverter ( ) } ,
111- Formatting = Formatting . Indented
112- } ;
113+ throw new Exception ( "Failed to fetch project config. Please try again later." ) ;
114+ } else {
115+ authorizeSession ( "" ) ;
113116
114- this . web3AuthOptions = web3AuthOptions ;
117+ JsonSerializerSettings settings = new JsonSerializerSettings
118+ {
119+ Converters = new List < JsonConverter > { new StringEnumConverter ( ) } ,
120+ Formatting = Formatting . Indented
121+ } ;
122+
123+ if ( this . web3AuthOptions . redirectUrl != null )
124+ this . initParams [ "redirectUrl" ] = this . web3AuthOptions . redirectUrl ;
115125
116- if ( this . web3AuthOptions . redirectUrl != null )
117- this . initParams [ "redirectUrl " ] = this . web3AuthOptions . redirectUrl ;
126+ if ( this . web3AuthOptions . whiteLabel != null )
127+ this . initParams [ "whiteLabel " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . whiteLabel , settings ) ;
118128
119- if ( this . web3AuthOptions . whiteLabel != null )
120- this . initParams [ "whiteLabel " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . whiteLabel , settings ) ;
129+ if ( this . web3AuthOptions . loginConfig != null )
130+ this . initParams [ "loginConfig " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . loginConfig , settings ) ;
121131
122- if ( this . web3AuthOptions . loginConfig != null )
123- this . initParams [ "loginConfig " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . loginConfig , settings ) ;
132+ if ( this . web3AuthOptions . clientId != null )
133+ this . initParams [ "clientId " ] = this . web3AuthOptions . clientId ;
124134
125- if ( this . web3AuthOptions . clientId != null )
126- this . initParams [ "clientId " ] = this . web3AuthOptions . clientId ;
135+ if ( this . web3AuthOptions . buildEnv != null )
136+ this . initParams [ "buildEnv " ] = this . web3AuthOptions . buildEnv . ToString ( ) . ToLower ( ) ;
127137
128- if ( this . web3AuthOptions . buildEnv != null )
129- this . initParams [ "buildEnv" ] = this . web3AuthOptions . buildEnv . ToString ( ) . ToLowerInvariant ( ) ;
138+ this . initParams [ "network" ] = this . web3AuthOptions . network . ToString ( ) . ToLower ( ) ;
130139
131- this . initParams [ "network" ] = this . web3AuthOptions . network . ToString ( ) . ToLowerInvariant ( ) ;
140+ if ( this . web3AuthOptions . useCoreKitKey . HasValue )
141+ this . initParams [ "useCoreKitKey" ] = this . web3AuthOptions . useCoreKitKey . Value ;
132142
133- if ( this . web3AuthOptions . useCoreKitKey . HasValue )
134- this . initParams [ "useCoreKitKey " ] = this . web3AuthOptions . useCoreKitKey . Value ;
143+ if ( this . web3AuthOptions . chainNamespace != null )
144+ this . initParams [ "chainNamespace " ] = this . web3AuthOptions . chainNamespace ;
135145
136- if ( this . web3AuthOptions . chainNamespace != null )
137- this . initParams [ "chainNamespace " ] = this . web3AuthOptions . chainNamespace ;
146+ if ( this . web3AuthOptions . mfaSettings != null )
147+ this . initParams [ "mfaSettings " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . mfaSettings , settings ) ;
138148
139- if ( this . web3AuthOptions . mfaSettings != null )
140- this . initParams [ "mfaSettings " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . mfaSettings , settings ) ;
149+ if ( this . web3AuthOptions . sessionTime != null )
150+ this . initParams [ "sessionTime " ] = this . web3AuthOptions . sessionTime ;
141151
142- if ( this . web3AuthOptions . sessionTime != null )
143- this . initParams [ "sessionTime" ] = this . web3AuthOptions . sessionTime ;
152+ }
144153 }
145154
146155 private void onDeepLinkActivated ( string url )
@@ -777,6 +786,49 @@ private async Task<string> createSession(string data, long sessionTime)
777786 return await createSessionResponse . Task ;
778787 }
779788
789+ private async Task < bool > fetchProjectConfig ( )
790+ {
791+ TaskCompletionSource < bool > fetchProjectConfigResponse = new TaskCompletionSource < bool > ( ) ;
792+ StartCoroutine ( Web3AuthApi . getInstance ( ) . fetchProjectConfig ( this . web3AuthOptions . clientId , this . web3AuthOptions . network . ToString ( ) . ToLower ( ) , ( response =>
793+ {
794+ if ( response != null )
795+ {
796+ this . web3AuthOptions . originData = this . web3AuthOptions . originData . mergeMaps ( response . whitelist ? . signed_urls ) ;
797+ if ( response ? . whitelabel != null )
798+ {
799+ if ( this . web3AuthOptions . whiteLabel == null )
800+ {
801+ this . web3AuthOptions . whiteLabel = response . whitelabel ;
802+ }
803+ else
804+ {
805+ this . web3AuthOptions . whiteLabel = this . web3AuthOptions . whiteLabel ? . merge ( response . whitelabel ) ;
806+ }
807+ }
808+ //Debug.Log("this.web3AuthOptions: =>" + JsonConvert.SerializeObject(this.web3AuthOptions));
809+
810+ JsonSerializerSettings settings = new JsonSerializerSettings
811+ {
812+ Converters = new List < JsonConverter > { new StringEnumConverter ( ) } ,
813+ Formatting = Formatting . Indented
814+ } ;
815+ if ( this . web3AuthOptions . whiteLabel != null )
816+ this . initParams [ "whiteLabel" ] = JsonConvert . SerializeObject ( this . web3AuthOptions . whiteLabel , settings ) ;
817+
818+ if ( this . web3AuthOptions . originData != null )
819+ this . initParams [ "originData" ] = JsonConvert . SerializeObject ( this . web3AuthOptions . originData , settings ) ;
820+
821+ fetchProjectConfigResponse . SetResult ( true ) ;
822+ }
823+ else
824+ {
825+ Debug . Log ( "configResponse API error:" ) ;
826+ fetchProjectConfigResponse . SetResult ( false ) ;
827+ }
828+ } ) ) ) ;
829+ return await fetchProjectConfigResponse . Task ;
830+ }
831+
780832 public string getPrivKey ( )
781833 {
782834 if ( web3AuthResponse == null )
0 commit comments