Skip to content

Commit 805ba80

Browse files
Marketplace API now takes the chainId in via json body instead of url… (#295)
* Marketplace API now takes the chainId in via json body instead of url path * Fix typo
1 parent 2c87d37 commit 805ba80

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/HttpClient.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Linq;
89
using Sequence.Config;
910
using Sequence.Utils;
1011
using 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+
}

Packages/Sequence-Unity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xyz.0xsequence.waas-unity",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"displayName": "Sequence Embedded Wallet SDK",
55
"description": "A Unity SDK for Sequence APIs",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)