From 89e14b7832210fcf0863b0e549feb80061fbfe66 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 28 Jan 2025 18:48:03 +1300 Subject: [PATCH 1/5] refactor: marketplace query params --- .../Scripts/Marketplace/BridgeScript.cs | 11 ++- .../Scripts/Marketplace/OnRampScript.cs | 14 ++-- .../Assets/Scripts/Marketplace/SwapScript.cs | 7 +- .../Marketplace/Runtime/LinkFactory.cs | 74 ++++++++----------- .../Marketplace/Runtime/LinkQueryParams.cs | 70 ++++++++++++++++++ .../Runtime/LinkQueryParams.cs.meta | 3 + 6 files changed, 123 insertions(+), 56 deletions(-) create mode 100644 src/Packages/Marketplace/Runtime/LinkQueryParams.cs create mode 100644 src/Packages/Marketplace/Runtime/LinkQueryParams.cs.meta diff --git a/sample/Assets/Scripts/Marketplace/BridgeScript.cs b/sample/Assets/Scripts/Marketplace/BridgeScript.cs index fe6bdc47..1d75b310 100644 --- a/sample/Assets/Scripts/Marketplace/BridgeScript.cs +++ b/sample/Assets/Scripts/Marketplace/BridgeScript.cs @@ -27,10 +27,13 @@ public void OpenWidget() var link = LinkFactory.GenerateBridgeLink( environment: environment, - fromTokenAddress: FromTokenAddress.text.IsNullOrEmpty() ? null : FromTokenAddress.text, - fromChainID: FromChain.text.IsNullOrEmpty() ? null : FromChain.text, - toTokenAddress: ToTokenAddress.text.IsNullOrEmpty() ? null : ToTokenAddress.text, - toChainID: ToChain.text.IsNullOrEmpty() ? null : ToChain.text + queryParams: new BridgeQueryParams + { + FromTokenAddress = FromTokenAddress.text.IsNullOrEmpty() ? null : FromTokenAddress.text, + FromChainID = FromChain.text.IsNullOrEmpty() ? null : FromChain.text, + ToTokenAddress = ToTokenAddress.text.IsNullOrEmpty() ? null : ToTokenAddress.text, + ToChainID = ToChain.text.IsNullOrEmpty() ? null : ToChain.text + } ); Application.OpenURL(link); diff --git a/sample/Assets/Scripts/Marketplace/OnRampScript.cs b/sample/Assets/Scripts/Marketplace/OnRampScript.cs index cb6e2443..0843aa16 100644 --- a/sample/Assets/Scripts/Marketplace/OnRampScript.cs +++ b/sample/Assets/Scripts/Marketplace/OnRampScript.cs @@ -50,10 +50,13 @@ public void OpenWidget() environment: environment, email: email, address: walletAddress, - fiatCurrency: FiatCurrencyInput.text.IsNullOrEmpty() ? "USD" : FiatCurrencyInput.text, - fiatAmount: FiatAmountInput.text.IsNullOrEmpty() ? "50" : FiatAmountInput.text, - cryptoCurrency: CryptoCurrency.text.IsNullOrEmpty() ? "IMX" : CryptoCurrency.text, - cryptoCurrencyList: CryptoCurrencyList.text.IsNullOrEmpty() ? "imx,eth,usdc" : CryptoCurrencyList.text + queryParams: new OnRampQueryParams + { + FiatCurrency = FiatCurrencyInput.text.IsNullOrEmpty() ? "USD" : FiatCurrencyInput.text, + FiatAmount = FiatAmountInput.text.IsNullOrEmpty() ? "50" : FiatAmountInput.text, + CryptoCurrency = CryptoCurrency.text.IsNullOrEmpty() ? "IMX" : CryptoCurrency.text, + CryptoCurrencyList = CryptoCurrencyList.text.IsNullOrEmpty() ? "imx,eth,usdc" : CryptoCurrencyList.text + } ); Application.OpenURL(link); @@ -66,5 +69,4 @@ public void Cancel() { SceneManager.LoadScene("MarketplaceScene"); } - -} +} \ No newline at end of file diff --git a/sample/Assets/Scripts/Marketplace/SwapScript.cs b/sample/Assets/Scripts/Marketplace/SwapScript.cs index 5fc6f3ed..321f5337 100644 --- a/sample/Assets/Scripts/Marketplace/SwapScript.cs +++ b/sample/Assets/Scripts/Marketplace/SwapScript.cs @@ -44,8 +44,11 @@ public void OpenWidget() var link = LinkFactory.GenerateSwapLink( environment: environment, publishableKey: publishableKey, - fromTokenAddress: FromTokenAddress.text.IsNullOrEmpty() ? null : FromTokenAddress.text, - toTokenAddress: ToTokenAddress.text.IsNullOrEmpty() ? null : ToTokenAddress.text + queryParams: new SwapQueryParams + { + FromTokenAddress = FromTokenAddress.text.IsNullOrEmpty() ? null : FromTokenAddress.text, + ToTokenAddress = ToTokenAddress.text.IsNullOrEmpty() ? null : ToTokenAddress.text + } ); Application.OpenURL(link); diff --git a/src/Packages/Marketplace/Runtime/LinkFactory.cs b/src/Packages/Marketplace/Runtime/LinkFactory.cs index b6629e17..97b8213f 100644 --- a/src/Packages/Marketplace/Runtime/LinkFactory.cs +++ b/src/Packages/Marketplace/Runtime/LinkFactory.cs @@ -12,25 +12,19 @@ public class LinkFactory /// Specifies the environment (Sandbox or Production). /// The user's email address, pre-filled in the on-ramp flow. /// The user's wallet address, where tokens will be sent. - /// The fiat currency to use (default: "USD"). - /// The amount of fiat currency to spend when purchasing cryptocurrency (default: "50"). - /// The cryptocurrency to purchase (default: "IMX"). - /// A comma-separated list of available cryptocurrencies for purchase (default: "imx,eth,usdc"). + /// The query parameters for the on-ramp flow. Uses default values if not specified. /// The generated on-ramp URL. public static string GenerateOnRampLink( Environment environment, string email, string address, - string fiatCurrency = "USD", - string fiatAmount = "50", - string cryptoCurrency = "IMX", - string cryptoCurrencyList = "imx,eth,usdc" + OnRampQueryParams queryParams = default ) { var baseUrl = LinkConfig.GetBaseUrl(environment, Flow.OnRamp); var apiKey = LinkConfig.GetApiKey(environment, Flow.OnRamp); - var queryParams = new Dictionary + var queryParamsDictionary = new Dictionary { {"apiKey", apiKey}, {"network", "immutablezkevm"}, @@ -39,17 +33,17 @@ public static string GenerateOnRampLink( {"productsAvailed", "buy"}, {"exchangeScreenTitle", "Buy"}, {"themeColor", "0D0D0D"}, - {"defaultCryptoCurrency", cryptoCurrency}, + {"defaultCryptoCurrency", queryParams.CryptoCurrency}, {"email", Uri.EscapeDataString(email)}, {"isAutoFillUserData", "true"}, {"disableWalletAddressForm", "true"}, - {"defaultFiatAmount", fiatAmount}, - {"defaultFiatCurrency", fiatCurrency}, + {"defaultFiatAmount", queryParams.FiatAmount}, + {"defaultFiatCurrency", queryParams.FiatCurrency}, {"walletAddress", address}, - {"cryptoCurrencyList", cryptoCurrencyList} + {"cryptoCurrencyList", queryParams.CryptoCurrencyList} }; - var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}"; } @@ -58,34 +52,32 @@ public static string GenerateOnRampLink( /// /// Specifies the environment (Sandbox or Production). /// The publishable key obtained from Immutable Hub. See API keys for more details. - /// 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 + /// The query parameters for the swap flow. Uses default values if not specified. + /// A swap URL. public static string GenerateSwapLink( Environment environment, string publishableKey, - string? fromTokenAddress = null, - string? toTokenAddress = null + SwapQueryParams queryParams = default ) { var baseUrl = LinkConfig.GetBaseUrl(environment, Flow.Swap); - var queryParams = new Dictionary + var queryParamsDictionary = new Dictionary { {"publishableKey", publishableKey} }; - if (!string.IsNullOrEmpty(fromTokenAddress)) + if (!string.IsNullOrEmpty(queryParams.FromTokenAddress)) { - queryParams["fromTokenAddress"] = fromTokenAddress; + queryParamsDictionary["fromTokenAddress"] = queryParams.FromTokenAddress; } - if (!string.IsNullOrEmpty(toTokenAddress)) + if (!string.IsNullOrEmpty(queryParams.ToTokenAddress)) { - queryParams["toTokenAddress"] = toTokenAddress; + queryParamsDictionary["toTokenAddress"] = queryParams.ToTokenAddress; } - var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}"; } @@ -93,37 +85,31 @@ public static string GenerateSwapLink( /// Generates a link for the bridge flow. /// /// Specifies the environment (Sandbox or Production). - /// 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). + /// The query parameters for the bridge flow. Uses default values if not specified. /// A bridge URL. public static string GenerateBridgeLink( Environment environment, - string? fromTokenAddress = null, - string? fromChainID = null, - string? toTokenAddress = null, - string? toChainID = null + BridgeQueryParams queryParams = default ) { var baseUrl = LinkConfig.GetBaseUrl(environment, Flow.Bridge); - var queryParams = new Dictionary(); + var queryParamsDictionary = new Dictionary(); - if (!string.IsNullOrEmpty(fromTokenAddress)) - queryParams["fromToken"] = fromTokenAddress.ToLower(); + if (!string.IsNullOrEmpty(queryParams.FromTokenAddress)) + queryParamsDictionary["fromToken"] = queryParams.FromTokenAddress.ToLower(); - if (!string.IsNullOrEmpty(fromChainID)) - queryParams["fromChain"] = fromChainID; + if (!string.IsNullOrEmpty(queryParams.FromChainID)) + queryParamsDictionary["fromChain"] = queryParams.FromChainID; - if (!string.IsNullOrEmpty(toTokenAddress)) - queryParams["toToken"] = toTokenAddress.ToLower(); + if (!string.IsNullOrEmpty(queryParams.ToTokenAddress)) + queryParamsDictionary["toToken"] = queryParams.ToTokenAddress.ToLower(); - if (!string.IsNullOrEmpty(toChainID)) - queryParams["toChain"] = toChainID; + if (!string.IsNullOrEmpty(queryParams.ToChainID)) + queryParamsDictionary["toChain"] = queryParams.ToChainID; - var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + var queryString = string.Join("&", queryParamsDictionary.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/LinkQueryParams.cs b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs new file mode 100644 index 00000000..75738895 --- /dev/null +++ b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs @@ -0,0 +1,70 @@ +namespace Immutable.Marketplace +{ + /// + /// Represents the query parameters for generating an on-ramp URL. + /// + public struct OnRampQueryParams + { + /// + /// The fiat currency to use (default: "USD"). + /// + public string FiatCurrency { get; set; } + + /// + /// The amount of fiat currency to spend when purchasing cryptocurrency (default: "50"). + /// + public string FiatAmount { get; set; } + + /// + /// The cryptocurrency to purchase (default: "IMX"). + /// + public string CryptoCurrency { get; set; } + + /// + /// A comma-separated list of available cryptocurrencies for purchase (default: "imx,eth,usdc"). + /// + public string CryptoCurrencyList { get; set; } + } + + /// + /// Represents the query parameters for generating a swap URL. + /// + public struct SwapQueryParams + { + /// + /// The address of the token being swapped from (default is null). + /// + public string? FromTokenAddress { get; set; } + + /// + /// The address of the token being swapped to (default is null). + /// + public string? ToTokenAddress { get; set; } + } + + /// + /// Represents the query parameters for generating a bridge URL. + /// + public struct BridgeQueryParams + { + /// + /// The address of the token being moved from (default is null). + /// + public string? FromTokenAddress { get; set; } + + /// + /// The ID of the source blockchain (default is null). + /// + public string? FromChainID { get; set; } + + /// + /// The address of the token being moved to (default is null). + /// + public string? ToTokenAddress { get; set; } + + /// + /// The ID of the destination blockchain (default is null). + /// + public string? ToChainID { get; set; } + } +} \ No newline at end of file diff --git a/src/Packages/Marketplace/Runtime/LinkQueryParams.cs.meta b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs.meta new file mode 100644 index 00000000..31621b30 --- /dev/null +++ b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a3d4658a7ab84ad8b8b6d9cfa89b6205 +timeCreated: 1738042715 \ No newline at end of file From f06cab4e90277e3eeee2e96f9bd217a0f7a25a12 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Wed, 29 Jan 2025 08:50:56 +1300 Subject: [PATCH 2/5] feat: add extra query params field to generate on ramp link --- .../Scripts/Marketplace/OnRampScript.cs | 10 +- .../Marketplace/Runtime/LinkFactory.cs | 106 +++++++++++++----- .../Marketplace/Runtime/LinkQueryParams.cs | 12 +- 3 files changed, 94 insertions(+), 34 deletions(-) diff --git a/sample/Assets/Scripts/Marketplace/OnRampScript.cs b/sample/Assets/Scripts/Marketplace/OnRampScript.cs index 0843aa16..3a5d02a0 100644 --- a/sample/Assets/Scripts/Marketplace/OnRampScript.cs +++ b/sample/Assets/Scripts/Marketplace/OnRampScript.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using AltWebSocketSharp; using Immutable.Marketplace; using UnityEngine; @@ -52,10 +53,13 @@ public void OpenWidget() address: walletAddress, queryParams: new OnRampQueryParams { - FiatCurrency = FiatCurrencyInput.text.IsNullOrEmpty() ? "USD" : FiatCurrencyInput.text, - FiatAmount = FiatAmountInput.text.IsNullOrEmpty() ? "50" : FiatAmountInput.text, - CryptoCurrency = CryptoCurrency.text.IsNullOrEmpty() ? "IMX" : CryptoCurrency.text, + DefaultFiatCurrency = FiatCurrencyInput.text.IsNullOrEmpty() ? "USD" : FiatCurrencyInput.text, + DefaultFiatAmount = FiatAmountInput.text.IsNullOrEmpty() ? "50" : FiatAmountInput.text, + DefaultCryptoCurrency = CryptoCurrency.text.IsNullOrEmpty() ? "IMX" : CryptoCurrency.text, CryptoCurrencyList = CryptoCurrencyList.text.IsNullOrEmpty() ? "imx,eth,usdc" : CryptoCurrencyList.text + }, + extraQueryParams: new Dictionary { + {"themeColor", "000000"} } ); diff --git a/src/Packages/Marketplace/Runtime/LinkFactory.cs b/src/Packages/Marketplace/Runtime/LinkFactory.cs index 97b8213f..9cb57a9f 100644 --- a/src/Packages/Marketplace/Runtime/LinkFactory.cs +++ b/src/Packages/Marketplace/Runtime/LinkFactory.cs @@ -13,12 +13,20 @@ public class LinkFactory /// The user's email address, pre-filled in the on-ramp flow. /// The user's wallet address, where tokens will be sent. /// The query parameters for the on-ramp flow. Uses default values if not specified. + /// Optional additional query parameters. See Transak docs for possible fields. /// The generated on-ramp URL. + /// + /// If includes any fields that are already defined in , + /// the values in will take precedence. + /// For example, if contains "defaultFiatAmount", it will be ignored and the value + /// from will be used instead. + /// public static string GenerateOnRampLink( Environment environment, string email, string address, - OnRampQueryParams queryParams = default + OnRampQueryParams queryParams = default, + Dictionary? extraQueryParams = null ) { var baseUrl = LinkConfig.GetBaseUrl(environment, Flow.OnRamp); @@ -26,24 +34,74 @@ public static string GenerateOnRampLink( var queryParamsDictionary = new Dictionary { - {"apiKey", apiKey}, - {"network", "immutablezkevm"}, - {"defaultPaymentMethod", "credit_debit_card"}, - {"disablePaymentMethods", ""}, - {"productsAvailed", "buy"}, - {"exchangeScreenTitle", "Buy"}, - {"themeColor", "0D0D0D"}, - {"defaultCryptoCurrency", queryParams.CryptoCurrency}, - {"email", Uri.EscapeDataString(email)}, - {"isAutoFillUserData", "true"}, - {"disableWalletAddressForm", "true"}, - {"defaultFiatAmount", queryParams.FiatAmount}, - {"defaultFiatCurrency", queryParams.FiatCurrency}, - {"walletAddress", address}, - {"cryptoCurrencyList", queryParams.CryptoCurrencyList} + { "apiKey", apiKey }, + { "cryptoCurrencyList", queryParams.CryptoCurrencyList }, + { "defaultCryptoCurrency", queryParams.DefaultCryptoCurrency }, + { "defaultFiatAmount", queryParams.DefaultFiatAmount }, + { "defaultFiatCurrency", queryParams.DefaultFiatCurrency }, + { + "defaultPaymentMethod", + extraQueryParams != null && + extraQueryParams.TryGetValue("defaultPaymentMethod", out var defaultPaymentMethod) + ? defaultPaymentMethod + : "credit_debit_card" + }, + { + "disablePaymentMethods", + extraQueryParams != null && + extraQueryParams.TryGetValue("disablePaymentMethods", out var disablePaymentMethods) + ? disablePaymentMethods + : "" + }, + { + "disableWalletAddressForm", + extraQueryParams != null && + extraQueryParams.TryGetValue("disableWalletAddressForm", out var disableWalletAddressForm) + ? disableWalletAddressForm + : "true" + }, + { "email", Uri.EscapeDataString(email) }, + { + "exchangeScreenTitle", + extraQueryParams != null && + extraQueryParams.TryGetValue("exchangeScreenTitle", out var exchangeScreenTitle) + ? exchangeScreenTitle + : "Buy" + }, + { + "isAutoFillUserData", + extraQueryParams != null && + extraQueryParams.TryGetValue("isAutoFillUserData", out var isAutoFillUserData) + ? isAutoFillUserData + : "true" + }, + { "network", "immutablezkevm" }, + { "productsAvailed", "buy" }, + { + "themeColor", + extraQueryParams != null && extraQueryParams.TryGetValue("themeColor", out var themeColor) + ? themeColor + : "0D0D0D" + }, + { "walletAddress", address } }; - var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + + // Add any extra parameters that are not already in the queryParamsDictionary + if (extraQueryParams != null) + { + foreach (var kvp in extraQueryParams) + { + // Add to dictionary only if the key is not already in the dictionary + if (!queryParamsDictionary.ContainsKey(kvp.Key)) + { + queryParamsDictionary[kvp.Key] = kvp.Value; + } + } + } + + var queryString = string.Join("&", + queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}"; } @@ -64,20 +122,17 @@ public static string GenerateSwapLink( var queryParamsDictionary = new Dictionary { - {"publishableKey", publishableKey} + { "publishableKey", publishableKey } }; if (!string.IsNullOrEmpty(queryParams.FromTokenAddress)) - { queryParamsDictionary["fromTokenAddress"] = queryParams.FromTokenAddress; - } if (!string.IsNullOrEmpty(queryParams.ToTokenAddress)) - { queryParamsDictionary["toTokenAddress"] = queryParams.ToTokenAddress; - } - var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + var queryString = string.Join("&", + queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}"; } @@ -108,8 +163,9 @@ public static string GenerateBridgeLink( if (!string.IsNullOrEmpty(queryParams.ToChainID)) queryParamsDictionary["toChain"] = queryParams.ToChainID; - var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); + var queryString = string.Join("&", + queryParamsDictionary.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/LinkQueryParams.cs b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs index 75738895..3f7e1095 100644 --- a/src/Packages/Marketplace/Runtime/LinkQueryParams.cs +++ b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs @@ -6,19 +6,19 @@ namespace Immutable.Marketplace public struct OnRampQueryParams { /// - /// The fiat currency to use (default: "USD"). + /// The cryptocurrency to purchase (default: "IMX"). /// - public string FiatCurrency { get; set; } + public string DefaultCryptoCurrency { get; set; } /// /// The amount of fiat currency to spend when purchasing cryptocurrency (default: "50"). /// - public string FiatAmount { get; set; } + public string DefaultFiatAmount { get; set; } /// - /// The cryptocurrency to purchase (default: "IMX"). + /// The fiat currency to use (default: "USD"). /// - public string CryptoCurrency { get; set; } + public string DefaultFiatCurrency { get; set; } /// /// A comma-separated list of available cryptocurrencies for purchase (default: "imx,eth,usdc"). @@ -67,4 +67,4 @@ public struct BridgeQueryParams /// public string? ToChainID { get; set; } } -} \ No newline at end of file +} From a1dfba216283af73d5bbfa3031e33bfca0fb4a26 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Wed, 29 Jan 2025 10:40:45 +1300 Subject: [PATCH 3/5] refactor: rename on ramp address argument --- sample/Assets/Scripts/Marketplace/OnRampScript.cs | 2 +- src/Packages/Marketplace/Runtime/LinkFactory.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/Assets/Scripts/Marketplace/OnRampScript.cs b/sample/Assets/Scripts/Marketplace/OnRampScript.cs index 3a5d02a0..54886ccc 100644 --- a/sample/Assets/Scripts/Marketplace/OnRampScript.cs +++ b/sample/Assets/Scripts/Marketplace/OnRampScript.cs @@ -50,7 +50,7 @@ public void OpenWidget() var link = LinkFactory.GenerateOnRampLink( environment: environment, email: email, - address: walletAddress, + walletAddress: walletAddress, queryParams: new OnRampQueryParams { DefaultFiatCurrency = FiatCurrencyInput.text.IsNullOrEmpty() ? "USD" : FiatCurrencyInput.text, diff --git a/src/Packages/Marketplace/Runtime/LinkFactory.cs b/src/Packages/Marketplace/Runtime/LinkFactory.cs index 9cb57a9f..0ebe45ce 100644 --- a/src/Packages/Marketplace/Runtime/LinkFactory.cs +++ b/src/Packages/Marketplace/Runtime/LinkFactory.cs @@ -11,7 +11,7 @@ public class LinkFactory /// /// Specifies the environment (Sandbox or Production). /// The user's email address, pre-filled in the on-ramp flow. - /// The user's wallet address, where tokens will be sent. + /// The user's wallet address, where tokens will be sent. /// The query parameters for the on-ramp flow. Uses default values if not specified. /// Optional additional query parameters. See Transak docs for possible fields. /// The generated on-ramp URL. @@ -24,7 +24,7 @@ public class LinkFactory public static string GenerateOnRampLink( Environment environment, string email, - string address, + string walletAddress, OnRampQueryParams queryParams = default, Dictionary? extraQueryParams = null ) @@ -83,7 +83,7 @@ public static string GenerateOnRampLink( ? themeColor : "0D0D0D" }, - { "walletAddress", address } + { "walletAddress", walletAddress } }; From 465052de09854cfc23ccd3a917d2472d8ab0aab0 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Wed, 29 Jan 2025 11:28:21 +1300 Subject: [PATCH 4/5] refactor: ordering or query params --- src/Packages/Marketplace/Runtime/LinkFactory.cs | 10 +++++----- .../Marketplace/Runtime/LinkQueryParams.cs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Packages/Marketplace/Runtime/LinkFactory.cs b/src/Packages/Marketplace/Runtime/LinkFactory.cs index 0ebe45ce..2e4b7f27 100644 --- a/src/Packages/Marketplace/Runtime/LinkFactory.cs +++ b/src/Packages/Marketplace/Runtime/LinkFactory.cs @@ -151,18 +151,18 @@ public static string GenerateBridgeLink( var queryParamsDictionary = new Dictionary(); - if (!string.IsNullOrEmpty(queryParams.FromTokenAddress)) - queryParamsDictionary["fromToken"] = queryParams.FromTokenAddress.ToLower(); - if (!string.IsNullOrEmpty(queryParams.FromChainID)) queryParamsDictionary["fromChain"] = queryParams.FromChainID; - if (!string.IsNullOrEmpty(queryParams.ToTokenAddress)) - queryParamsDictionary["toToken"] = queryParams.ToTokenAddress.ToLower(); + if (!string.IsNullOrEmpty(queryParams.FromTokenAddress)) + queryParamsDictionary["fromToken"] = queryParams.FromTokenAddress.ToLower(); if (!string.IsNullOrEmpty(queryParams.ToChainID)) queryParamsDictionary["toChain"] = queryParams.ToChainID; + if (!string.IsNullOrEmpty(queryParams.ToTokenAddress)) + queryParamsDictionary["toToken"] = queryParams.ToTokenAddress.ToLower(); + var queryString = string.Join("&", queryParamsDictionary.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray()); return $"{baseUrl}?{queryString}"; diff --git a/src/Packages/Marketplace/Runtime/LinkQueryParams.cs b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs index 3f7e1095..04217aa8 100644 --- a/src/Packages/Marketplace/Runtime/LinkQueryParams.cs +++ b/src/Packages/Marketplace/Runtime/LinkQueryParams.cs @@ -47,24 +47,24 @@ public struct SwapQueryParams /// public struct BridgeQueryParams { - /// - /// The address of the token being moved from (default is null). - /// - public string? FromTokenAddress { get; set; } - /// /// The ID of the source blockchain (default is null). /// public string? FromChainID { get; set; } /// - /// The address of the token being moved to (default is null). + /// The address of the token being moved from (default is null). /// - public string? ToTokenAddress { get; set; } + public string? FromTokenAddress { get; set; } /// /// The ID of the destination blockchain (default is null). /// public string? ToChainID { get; set; } + + /// + /// The address of the token being moved to (default is null). + /// + public string? ToTokenAddress { get; set; } } -} +} \ No newline at end of file From 8a6817fad5d6f8d6a2f58dacd58c48f608ba5cb8 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Wed, 29 Jan 2025 13:09:32 +1300 Subject: [PATCH 5/5] docs: update link factory docs --- src/Packages/Marketplace/Runtime/LinkFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Packages/Marketplace/Runtime/LinkFactory.cs b/src/Packages/Marketplace/Runtime/LinkFactory.cs index 2e4b7f27..e65ae34d 100644 --- a/src/Packages/Marketplace/Runtime/LinkFactory.cs +++ b/src/Packages/Marketplace/Runtime/LinkFactory.cs @@ -111,7 +111,7 @@ public static string GenerateOnRampLink( /// Specifies the environment (Sandbox or Production). /// The publishable key obtained from Immutable Hub. See API keys for more details. /// The query parameters for the swap flow. Uses default values if not specified. - /// A swap URL. + /// The generated swap URL. public static string GenerateSwapLink( Environment environment, string publishableKey, @@ -141,7 +141,7 @@ public static string GenerateSwapLink( /// /// Specifies the environment (Sandbox or Production). /// The query parameters for the bridge flow. Uses default values if not specified. - /// A bridge URL. + /// The generated bridge URL. public static string GenerateBridgeLink( Environment environment, BridgeQueryParams queryParams = default