Skip to content

Commit a149aa7

Browse files
committed
feat: function to generate bridge URL
1 parent 6fa9ce7 commit a149aa7

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/Packages/Marketplace/Runtime/Bridge.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Immutable.Marketplace.Bridge
6+
{
7+
/// <summary>
8+
/// Provides functionality for generating a link to the bridge flow,
9+
/// simplifying the process of moving tokens from and to the Immutable zkEVM network.
10+
/// </summary>
11+
public class Bridge
12+
{
13+
private readonly string _environment;
14+
private static readonly Dictionary<string, string> BaseUrls = new()
15+
{
16+
{ "sandbox", "https://checkout-playground.sandbox.immutable.com/checkout/squid" },
17+
{ "production", "https://toolkit.immutable.com/checkout/squid" }
18+
};
19+
20+
/// <summary>
21+
/// Initialises a new instance of the <see cref="Bridge"/> class.
22+
/// </summary>
23+
/// <param name="environment">Specifies the environment (<c>sandbox</c> or <c>production</c>).</param>
24+
public Bridge(string environment)
25+
{
26+
_environment = environment;
27+
}
28+
29+
/// <summary>
30+
/// Generates a link for the bridge flow.
31+
/// </summary>
32+
/// <param name="fromTokenAddress">The address of the token being moved from.</param>
33+
/// <param name="fromChain">The ID of the source blockchain.</param>
34+
/// <param name="toTokenAddress">The address of the token being moved to.</param>
35+
/// <param name="toChain">The ID of the destination blockchain.</param>
36+
/// <returns>A URL string for the bridge flow, including all necessary query parameters.</returns>
37+
public string GetLink(string fromTokenAddress, string fromChain, string toTokenAddress, string toChain)
38+
{
39+
var baseUrl = BaseUrls[_environment];
40+
41+
var queryParams = new Dictionary<string, string>
42+
{
43+
{"fromToken", fromTokenAddress},
44+
{"fromChain", fromChain},
45+
{"toTokenAddress", toTokenAddress},
46+
{"toChain", toChain}
47+
};
48+
49+
var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray());
50+
return $"{baseUrl}?{queryString}";
51+
}
52+
}
53+
}

src/Packages/Marketplace/Runtime/Bridge/Bridge.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)