@@ -87,49 +87,56 @@ public void Awake()
8787// this.setResultUrl(new Uri($"http://localhost#{code}"));
8888// }
8989#endif
90-
91- authorizeSession ( "" ) ;
9290 }
9391
94- public void setOptions ( Web3AuthOptions web3AuthOptions )
92+ public async void setOptions ( Web3AuthOptions web3AuthOptions )
9593 {
9694 this . web3AuthOptions = web3AuthOptions ;
97- fetchProjectConfig ( ) ;
9895
99- JsonSerializerSettings settings = new JsonSerializerSettings
96+ bool isfetchConfigSuccess = await fetchProjectConfig ( ) ;
97+
98+ if ( ! isfetchConfigSuccess )
10099 {
101- Converters = new List < JsonConverter > { new StringEnumConverter ( ) } ,
102- Formatting = Formatting . Indented
103- } ;
100+ throw new Exception ( "Failed to fetch project config. Please try again later." ) ;
101+ } else {
102+ authorizeSession ( "" ) ;
103+
104+ JsonSerializerSettings settings = new JsonSerializerSettings
105+ {
106+ Converters = new List < JsonConverter > { new StringEnumConverter ( ) } ,
107+ Formatting = Formatting . Indented
108+ } ;
109+
110+ if ( this . web3AuthOptions . redirectUrl != null )
111+ this . initParams [ "redirectUrl" ] = this . web3AuthOptions . redirectUrl ;
104112
105- if ( this . web3AuthOptions . redirectUrl != null )
106- this . initParams [ "redirectUrl " ] = this . web3AuthOptions . redirectUrl ;
113+ if ( this . web3AuthOptions . whiteLabel != null )
114+ this . initParams [ "whiteLabel " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . whiteLabel , settings ) ;
107115
108- if ( this . web3AuthOptions . whiteLabel != null )
109- this . initParams [ "whiteLabel " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . whiteLabel , settings ) ;
116+ if ( this . web3AuthOptions . loginConfig != null )
117+ this . initParams [ "loginConfig " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . loginConfig , settings ) ;
110118
111- if ( this . web3AuthOptions . loginConfig != null )
112- this . initParams [ "loginConfig " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . loginConfig , settings ) ;
119+ if ( this . web3AuthOptions . clientId != null )
120+ this . initParams [ "clientId " ] = this . web3AuthOptions . clientId ;
113121
114- if ( this . web3AuthOptions . clientId != null )
115- this . initParams [ "clientId " ] = this . web3AuthOptions . clientId ;
122+ if ( this . web3AuthOptions . buildEnv != null )
123+ this . initParams [ "buildEnv " ] = this . web3AuthOptions . buildEnv . ToString ( ) . ToLower ( ) ;
116124
117- if ( this . web3AuthOptions . buildEnv != null )
118- this . initParams [ "buildEnv" ] = this . web3AuthOptions . buildEnv . ToString ( ) . ToLower ( ) ;
125+ this . initParams [ "network" ] = this . web3AuthOptions . network . ToString ( ) . ToLower ( ) ;
119126
120- this . initParams [ "network" ] = this . web3AuthOptions . network . ToString ( ) . ToLower ( ) ;
127+ if ( this . web3AuthOptions . useCoreKitKey . HasValue )
128+ this . initParams [ "useCoreKitKey" ] = this . web3AuthOptions . useCoreKitKey . Value ;
121129
122- if ( this . web3AuthOptions . useCoreKitKey . HasValue )
123- this . initParams [ "useCoreKitKey " ] = this . web3AuthOptions . useCoreKitKey . Value ;
130+ if ( this . web3AuthOptions . chainNamespace != null )
131+ this . initParams [ "chainNamespace " ] = this . web3AuthOptions . chainNamespace ;
124132
125- if ( this . web3AuthOptions . chainNamespace != null )
126- this . initParams [ "chainNamespace " ] = this . web3AuthOptions . chainNamespace ;
133+ if ( this . web3AuthOptions . mfaSettings != null )
134+ this . initParams [ "mfaSettings " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . mfaSettings , settings ) ;
127135
128- if ( this . web3AuthOptions . mfaSettings != null )
129- this . initParams [ "mfaSettings " ] = JsonConvert . SerializeObject ( this . web3AuthOptions . mfaSettings , settings ) ;
136+ if ( this . web3AuthOptions . sessionTime != null )
137+ this . initParams [ "sessionTime " ] = this . web3AuthOptions . sessionTime ;
130138
131- if ( this . web3AuthOptions . sessionTime != null )
132- this . initParams [ "sessionTime" ] = this . web3AuthOptions . sessionTime ;
139+ }
133140 }
134141
135142 private void onDeepLinkActivated ( string url )
@@ -652,8 +659,9 @@ private async Task<string> createSession(string data, long sessionTime)
652659 return await createSessionResponse . Task ;
653660 }
654661
655- private void fetchProjectConfig ( )
662+ private async Task < bool > fetchProjectConfig ( )
656663 {
664+ TaskCompletionSource < bool > fetchProjectConfigResponse = new TaskCompletionSource < bool > ( ) ;
657665 StartCoroutine ( Web3AuthApi . getInstance ( ) . fetchProjectConfig ( this . web3AuthOptions . clientId , this . web3AuthOptions . network . ToString ( ) . ToLower ( ) , ( response =>
658666 {
659667 if ( response != null )
@@ -682,12 +690,16 @@ private void fetchProjectConfig()
682690
683691 if ( this . web3AuthOptions . originData != null )
684692 this . initParams [ "originData" ] = JsonConvert . SerializeObject ( this . web3AuthOptions . originData , settings ) ;
693+
694+ fetchProjectConfigResponse . SetResult ( true ) ;
685695 }
686696 else
687697 {
688698 Debug . Log ( "configResponse API error:" ) ;
699+ fetchProjectConfigResponse . SetResult ( false ) ;
689700 }
690701 } ) ) ) ;
702+ return await fetchProjectConfigResponse . Task ;
691703 }
692704
693705 public string getPrivKey ( )
0 commit comments