Skip to content

Commit 542b6e0

Browse files
committed
dupe import mm sdk webgl fix
1 parent 9809aea commit 542b6e0

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

Assets/Thirdweb/Core/Plugins/MetaMask/Scripts/IO/MetaMaskHttpService.cs

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#if UNITY_WEBGL && !UNITY_EDITOR
1212
using System;
1313
using UnityEngine.Scripting;
14-
using MetaMask.Unity.Utils;
1514
using Newtonsoft.Json;
1615
using System.Runtime.InteropServices;
1716
#endif
@@ -29,7 +28,7 @@ public enum RequestType
2928
POST,
3029
DELETE
3130
}
32-
31+
3332
/// <summary>
3433
/// A class that represents a single HTTP Request
3534
/// </summary>
@@ -63,13 +62,16 @@ public UnityHttpServiceProvider(string baseUrl, string authKey, string authValue
6362

6463
public Task<string> Get(string uri)
6564
{
66-
var fullUrl = string.IsNullOrWhiteSpace(baseUrl) ? uri :
67-
baseUrl.EndsWith("/") || uri.StartsWith("/") ? $"{baseUrl}{uri}" : $"{baseUrl}/{uri}";
68-
65+
var fullUrl = string.IsNullOrWhiteSpace(baseUrl)
66+
? uri
67+
: baseUrl.EndsWith("/") || uri.StartsWith("/")
68+
? $"{baseUrl}{uri}"
69+
: $"{baseUrl}/{uri}";
70+
6971
// ensure we dont end on a /
7072
if (fullUrl.EndsWith("/"))
7173
fullUrl = fullUrl.Substring(0, fullUrl.Length - 1);
72-
74+
7375
var request = new UnityHttpServiceRequest()
7476
{
7577
url = fullUrl,
@@ -78,21 +80,24 @@ public Task<string> Get(string uri)
7880
authValue = authValue,
7981
requestType = RequestType.GET
8082
};
81-
83+
8284
service.requests.Enqueue(request);
8385

8486
return request.requestTask.Task;
8587
}
8688

8789
public Task<string> Post(string uri, string @params)
8890
{
89-
var fullUrl = string.IsNullOrWhiteSpace(baseUrl) ? uri :
90-
baseUrl.EndsWith("/") || uri.StartsWith("/") ? $"{baseUrl}{uri}" : $"{baseUrl}/{uri}";
91-
91+
var fullUrl = string.IsNullOrWhiteSpace(baseUrl)
92+
? uri
93+
: baseUrl.EndsWith("/") || uri.StartsWith("/")
94+
? $"{baseUrl}{uri}"
95+
: $"{baseUrl}/{uri}";
96+
9297
// ensure we dont end on a /
9398
if (fullUrl.EndsWith("/"))
9499
fullUrl = fullUrl.Substring(0, fullUrl.Length - 1);
95-
100+
96101
var request = new UnityHttpServiceRequest()
97102
{
98103
url = fullUrl,
@@ -102,21 +107,24 @@ public Task<string> Post(string uri, string @params)
102107
authKey = authKey,
103108
authValue = authValue
104109
};
105-
110+
106111
service.requests.Enqueue(request);
107112

108113
return request.requestTask.Task;
109114
}
110-
115+
111116
public Task<string> Delete(string uri, string @params)
112117
{
113-
var fullUrl = string.IsNullOrWhiteSpace(baseUrl) ? uri :
114-
baseUrl.EndsWith("/") || uri.StartsWith("/") ? $"{baseUrl}{uri}" : $"{baseUrl}/{uri}";
115-
118+
var fullUrl = string.IsNullOrWhiteSpace(baseUrl)
119+
? uri
120+
: baseUrl.EndsWith("/") || uri.StartsWith("/")
121+
? $"{baseUrl}{uri}"
122+
: $"{baseUrl}/{uri}";
123+
116124
// ensure we dont end on a /
117125
if (fullUrl.EndsWith("/"))
118126
fullUrl = fullUrl.Substring(0, fullUrl.Length - 1);
119-
127+
120128
var request = new UnityHttpServiceRequest()
121129
{
122130
url = fullUrl,
@@ -126,7 +134,7 @@ public Task<string> Delete(string uri, string @params)
126134
authKey = authKey,
127135
authValue = authValue
128136
};
129-
137+
130138
service.requests.Enqueue(request);
131139

132140
return request.requestTask.Task;
@@ -135,7 +143,7 @@ public Task<string> Delete(string uri, string @params)
135143

136144
private Queue<UnityHttpServiceRequest> requests = new Queue<UnityHttpServiceRequest>();
137145
private bool isCheckingQueue;
138-
146+
139147
private IMetaMaskSDK _metaMaskSDK => MetaMaskSDK.SDKInstance;
140148

141149
protected override void Awake()
@@ -184,7 +192,7 @@ private IEnumerator ProcessRequest(UnityHttpServiceRequest request)
184192
method = "GET";
185193
break;
186194
}
187-
195+
188196
#if UNITY_WEBGL && !UNITY_EDITOR
189197
yield return SendRequestWebgl(method, request);
190198
#else
@@ -199,10 +207,8 @@ private IEnumerator SendRequestUnity(string method, UnityHttpServiceRequest requ
199207
bool isGet = request.requestType == RequestType.GET;
200208
string authHeaderKey = request.authKey;
201209
string authHeaderValue = request.authValue;
202-
203-
using (UnityWebRequest uwr = !isGet
204-
? new UnityWebRequest(url, method)
205-
: UnityWebRequest.Get(url))
210+
211+
using (UnityWebRequest uwr = !isGet ? new UnityWebRequest(url, method) : UnityWebRequest.Get(url))
206212
{
207213
if (!string.IsNullOrWhiteSpace(authHeaderValue) && !string.IsNullOrWhiteSpace(authHeaderKey))
208214
{
@@ -212,7 +218,10 @@ private IEnumerator SendRequestUnity(string method, UnityHttpServiceRequest requ
212218
if (Infura.IsUrl(url))
213219
{
214220
uwr.SetRequestHeader("X-Infura-User-Agent", $"metamask/sdk-csharp {_metaMaskSDK.SDKVersion}");
215-
uwr.SetRequestHeader("Metamask-Sdk-Info", $"Sdk/Unity SdkVersion/{_metaMaskSDK.SDKVersion} Platform/{SystemInfo.operatingSystem} dApp/{_metaMaskSDK.Config.AppUrl} dAppTitle/{_metaMaskSDK.Config.AppName}");
221+
uwr.SetRequestHeader(
222+
"Metamask-Sdk-Info",
223+
$"Sdk/Unity SdkVersion/{_metaMaskSDK.SDKVersion} Platform/{SystemInfo.operatingSystem} dApp/{_metaMaskSDK.Config.AppUrl} dAppTitle/{_metaMaskSDK.Config.AppName}"
224+
);
216225
}
217226

218227
if (!string.IsNullOrWhiteSpace(@params))
@@ -223,12 +232,12 @@ private IEnumerator SendRequestUnity(string method, UnityHttpServiceRequest requ
223232
uwr.uploadHandler.contentType = "application/json";
224233
uwr.SetRequestHeader("Content-Type", "application/json");
225234
}
226-
235+
227236
yield return uwr.SendWebRequest();
228237

229238
switch (uwr.result)
230239
{
231-
case UnityWebRequest.Result.ConnectionError:
240+
case UnityWebRequest.Result.ConnectionError:
232241
case UnityWebRequest.Result.DataProcessingError:
233242
case UnityWebRequest.Result.ProtocolError:
234243
request.requestTask.SetException(new IOException(uwr.error + " | " + uwr.downloadHandler.text));
@@ -306,4 +315,4 @@ public void OnFetchResponseCallback(string resultJson)
306315
}
307316
#endif
308317
}
309-
}
318+
}

0 commit comments

Comments
 (0)