55using System . Text ;
66using System . Threading . Tasks ;
77using Newtonsoft . Json ;
8+ using Newtonsoft . Json . Linq ;
89using Sequence . Config ;
910using Sequence . Utils ;
1011using UnityEngine . Networking ;
@@ -17,7 +18,7 @@ public class HttpClient : IHttpClient
1718 private const string _prodUrl = "https://marketplace-api.sequence.app/" ;
1819 private const string _devUrl = "https://dev-marketplace-api.sequence-dev.app/" ;
1920 private static string _baseUrl = "https://marketplace-api.sequence.app/" ;
20- private const string _endUrl = "/ rpc/Marketplace/" ;
21+ private const string _endUrl = "rpc/Marketplace/" ;
2122 private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
2223 {
2324 NullValueHandling = NullValueHandling . Ignore
@@ -41,17 +42,40 @@ public async Task<ReturnType> SendRequest<ReturnType>(Chain chain, string url)
4142
4243 public async Task < ReturnType > SendRequest < ArgType , ReturnType > ( Chain chain , string endpoint , ArgType args )
4344 {
44- string url = _baseUrl + ChainDictionaries . PathOf [ chain ] + _endUrl + endpoint ;
45- return await SendRequest < ArgType , ReturnType > ( url , args ) ;
45+ string url = _baseUrl + _endUrl + endpoint ;
46+ string requestJson = ToJson ( args ) ;
47+ if ( string . IsNullOrWhiteSpace ( requestJson ) )
48+ {
49+ requestJson = "{}" ;
50+ }
51+ string chainId = ChainDictionaries . ChainIdOf [ chain ] ;
52+ JObject jsonObj = JsonConvert . DeserializeObject < JObject > ( requestJson ) ;
53+ jsonObj [ "chainId" ] = chainId ;
54+ requestJson = jsonObj . ToString ( Formatting . None ) ;
55+
56+ return await SendRequest < ReturnType > ( url , requestJson ) ;
4657 }
4758
48- public async Task < ReturnType > SendRequest < ArgType , ReturnType > ( string url , ArgType args )
59+ private string ToJson < ArgType > ( ArgType args )
4960 {
5061 string requestJson = "" ;
5162 if ( args != null )
5263 {
5364 requestJson = JsonConvert . SerializeObject ( args , serializerSettings ) ;
5465 }
66+
67+ return requestJson ;
68+ }
69+
70+ public async Task < ReturnType > SendRequest < ArgType , ReturnType > ( string url , ArgType args )
71+ {
72+ string requestJson = ToJson ( args ) ;
73+
74+ return await SendRequest < ReturnType > ( url , requestJson ) ;
75+ }
76+
77+ private async Task < ReturnType > SendRequest < ReturnType > ( string url , string requestJson )
78+ {
5579 using UnityWebRequest request = UnityWebRequest . Get ( url ) ;
5680 request . method = UnityWebRequest . kHttpVerbPOST ;
5781 byte [ ] requestData = Encoding . UTF8 . GetBytes ( requestJson ) ;
@@ -143,4 +167,4 @@ private string ExtractHeaders(UnityWebRequest request)
143167 return headerBuilder . ToString ( ) ;
144168 }
145169 }
146- }
170+ }
0 commit comments