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 (default is null).</param>
33
+ /// <param name="fromChain">The ID of the source blockchain (default is null).</param>
34
+ /// <param name="toTokenAddress">The address of the token being moved to (default is null).</param>
35
+ /// <param name="toChain">The ID of the destination blockchain (default is null).</param>
36
+ /// <returns>A bridge URL.</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
+ if ( ! string . IsNullOrEmpty ( fromTokenAddress ) )
44
+ queryParams [ "fromToken" ] = fromTokenAddress ;
45
+
46
+ if ( ! string . IsNullOrEmpty ( fromChain ) )
47
+ queryParams [ "fromChain" ] = fromChain ;
48
+
49
+ if ( ! string . IsNullOrEmpty ( toTokenAddress ) )
50
+ queryParams [ "toTokenAddress" ] = toTokenAddress ;
51
+
52
+ if ( ! string . IsNullOrEmpty ( toChain ) )
53
+ queryParams [ "toChain" ] = toChain ;
54
+
55
+ var queryString = string . Join ( "&" , queryParams . Select ( kvp => $ "{ kvp . Key } ={ Uri . EscapeDataString ( kvp . Value ) } ") . ToArray ( ) ) ;
56
+ return $ "{ baseUrl } ?{ queryString } ";
57
+ }
58
+ }
59
+ }
0 commit comments