diff --git a/src/Packages/Marketplace/Runtime/Bridge.meta b/src/Packages/Marketplace/Runtime/Bridge.meta new file mode 100644 index 00000000..39f22cd4 --- /dev/null +++ b/src/Packages/Marketplace/Runtime/Bridge.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 26141e7abf8c424b86b1a7301e8ad20d +timeCreated: 1737318271 \ No newline at end of file diff --git a/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs b/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs new file mode 100644 index 00000000..d1b38cb5 --- /dev/null +++ b/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Immutable.Marketplace.Bridge +{ + /// + /// Provides functionality for generating a link to the bridge flow, + /// simplifying the process of moving tokens from and to the Immutable zkEVM network. + /// + public class Bridge + { + private readonly string _environment; + private static readonly Dictionary BaseUrls = new() + { + { "sandbox", "https://checkout-playground.sandbox.immutable.com/checkout/squid" }, + { "production", "https://toolkit.immutable.com/checkout/squid" } + }; + + /// + /// Initialises a new instance of the class. + /// + /// Specifies the environment (sandbox or production). + public Bridge(string environment) + { + _environment = environment; + } + + /// + /// Generates a link for the bridge flow. + /// + /// The address of the token being moved from (default is null). + /// The ID of the source blockchain (default is null). + /// The address of the token being moved to (default is null). + /// The ID of the destination blockchain (default is null). + /// A bridge URL. + public string GetLink(string? fromTokenAddress, string? fromChain, string? toTokenAddress, string? toChain) + { + var baseUrl = BaseUrls[_environment]; + + var queryParams = new Dictionary(); + + if (!string.IsNullOrEmpty(fromTokenAddress)) + queryParams["fromToken"] = fromTokenAddress; + + if (!string.IsNullOrEmpty(fromChain)) + queryParams["fromChain"] = fromChain; + + if (!string.IsNullOrEmpty(toTokenAddress)) + queryParams["toTokenAddress"] = toTokenAddress; + + if (!string.IsNullOrEmpty(toChain)) + queryParams["toChain"] = toChain; + + var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + return $"{baseUrl}?{queryString}"; + } + } +} \ No newline at end of file diff --git a/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs.meta b/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs.meta new file mode 100644 index 00000000..60af3ea0 --- /dev/null +++ b/src/Packages/Marketplace/Runtime/Bridge/Bridge.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9c9cfc4602c840068916eb5806790758 +timeCreated: 1737318271 \ No newline at end of file diff --git a/src/Packages/Marketplace/Runtime/Swap/Swap.cs b/src/Packages/Marketplace/Runtime/Swap/Swap.cs index 2b0e7f33..03035fb0 100644 --- a/src/Packages/Marketplace/Runtime/Swap/Swap.cs +++ b/src/Packages/Marketplace/Runtime/Swap/Swap.cs @@ -35,20 +35,28 @@ public Swap(string environment) /// /// Generates a link for the swap flow. /// - /// The address of the token being swapped from. - /// The address of the token being swapped to. + /// The address of the token being swapped from (default is null). + /// The address of the token being swapped to (default is null). /// A swap URL - public string GetLink(string fromTokenAddress, string toTokenAddress) + public string GetLink(string? fromTokenAddress = null, string? toTokenAddress = null) { var baseUrl = BaseUrls[_environment]; var apiKey = ApiKeys[_environment]; var queryParams = new Dictionary - { - {"publishableKey", apiKey}, - {"fromTokenAddress", fromTokenAddress}, - {"toTokenAddress", toTokenAddress} - }; + { + {"publishableKey", apiKey} + }; + + if (!string.IsNullOrEmpty(fromTokenAddress)) + { + queryParams["fromTokenAddress"] = fromTokenAddress; + } + + if (!string.IsNullOrEmpty(toTokenAddress)) + { + queryParams["toTokenAddress"] = toTokenAddress; + } var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}";