Skip to content

Commit 63cbe92

Browse files
committed
feat: make swap url params optional
1 parent 7a5e1ef commit 63cbe92

File tree

1 file changed

+14
-6
lines changed
  • src/Packages/Marketplace/Runtime/Swap

1 file changed

+14
-6
lines changed

src/Packages/Marketplace/Runtime/Swap/Swap.cs

+14-6
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ public Swap(string environment)
3838
/// <param name="fromTokenAddress">The address of the token being swapped from.</param>
3939
/// <param name="toTokenAddress">The address of the token being swapped to.</param>
4040
/// <returns>A swap URL</returns>
41-
public string GetLink(string fromTokenAddress, string toTokenAddress)
41+
public string GetLink(string? fromTokenAddress = null, string? toTokenAddress = null)
4242
{
4343
var baseUrl = BaseUrls[_environment];
4444
var apiKey = ApiKeys[_environment];
4545

4646
var queryParams = new Dictionary<string, string>
47-
{
48-
{"publishableKey", apiKey},
49-
{"fromTokenAddress", fromTokenAddress},
50-
{"toTokenAddress", toTokenAddress}
51-
};
47+
{
48+
{"publishableKey", apiKey}
49+
};
50+
51+
if (!string.IsNullOrEmpty(fromTokenAddress))
52+
{
53+
queryParams["fromTokenAddress"] = fromTokenAddress;
54+
}
55+
56+
if (!string.IsNullOrEmpty(toTokenAddress))
57+
{
58+
queryParams["toTokenAddress"] = toTokenAddress;
59+
}
5260

5361
var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray());
5462
return $"{baseUrl}?{queryString}";

0 commit comments

Comments
 (0)