Skip to content

[DX-3548] feat: swap api key #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions sample/Assets/Scenes/SelectAuthMethod.unity
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 416242725}
m_HandleRect: {fileID: 416242724}
m_Direction: 0
m_Value: 1
m_Size: 0.9999999
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -1324,7 +1324,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 167431871}
m_Direction: 2
m_Value: 1
m_Size: 0.99999994
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -1673,8 +1673,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 1222.7355, y: 0}
m_SizeDelta: {x: 2405.471, y: 0}
m_AnchoredPosition: {x: 1016.24, y: 0}
m_SizeDelta: {x: 1992.48, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1661390145
MonoBehaviour:
Expand Down Expand Up @@ -1768,8 +1768,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 1222.7355, y: 0}
m_SizeDelta: {x: 2405.471, y: 0}
m_AnchoredPosition: {x: 1016.24, y: 0}
m_SizeDelta: {x: 1992.48, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1688502349
MonoBehaviour:
Expand Down Expand Up @@ -1822,21 +1822,21 @@ MonoBehaviour:


1.
Device Code Authorisation Device Code Authorisation is available for all supported
platforms. This method opens the player''s default browser and guides them through
the authentication flow.
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
for Android, iOS, macOS and WebGL (not officially supported). This method provides
a seamless and secure authentication experience by opening a pop-up window on
macOS or an in-app browser on mobile devices. Players are automatically redirected
back to the game once authenticated, eliminating manual switching.


2. Authorisation Code Flow with Proof Key for
Code Exchange (PKCE) PKCE is available for Android, iOS and macOS. This method
simplifies the process by opening a pop-up window on macOS or an in-app browser
on mobile devices, guiding users through the authentication flow. Once authenticated,
players are automatically redirected back to the game, eliminating the need for
manual switching.
2. Device
Code Authorisation is available for Windows, Android, iOS and macOS. This method
opens the player''s default browser and guides them through the authentication
flow.


Recommendation: For an optimal gaming experience on Android,
iOS, macOS or WebGL, it is recommended to use the PKCE flow.'
Recommendation: Whenever possible, use the PKCE flow as it is the
most secure and seamless method for authentication on Android, iOS and macOS.'
--- !u!222 &1688502351
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1912,7 +1912,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 3}
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 20
m_FontStyle: 0
m_BestFit: 0
Expand Down
24 changes: 12 additions & 12 deletions src/Packages/Marketplace/Runtime/OnRamp/OnRamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ public OnRamp(string environment, string email, string address)
}

/// <summary>
/// Generates a link for the on-ramp flow.
/// Generates a URL for the on-ramp flow.
/// </summary>
/// <param name="fiatCurrency">The fiat currency to be used (default is "USD").</param>
/// <param name="defaultFiatAmount">The default amount of fiat currency (default is "50").</param>
/// <param name="defaultCryptoCurrency">The default cryptocurrency (default is "IMX")..</param>
/// <param name="defaultCryptoCurrencyList">A comma-separated list of available cryptocurrencies to purchase (default is "imx,eth,usdc").</param>
/// <returns>An on-ramp URL</returns>
/// <param name="fiatCurrency">The fiat currency to use (default: "USD").</param>
/// <param name="fiatAmount">The amount of fiat currency to spend when purchasing cryptocurrency (default: "50").</param>
/// <param name="cryptoCurrency">The cryptocurrency to purchase (default: "IMX").</param>
/// <param name="cryptoCurrencyList">A comma-separated list of available cryptocurrencies for purchase (default: "imx,eth,usdc").</param>
/// <returns>The generated on-ramp URL.</returns>
public string GetLink(
string fiatCurrency = "USD",
string defaultFiatAmount = "50",
string defaultCryptoCurrency = "IMX",
string defaultCryptoCurrencyList = "imx,eth,usdc"
string fiatAmount = "50",
string cryptoCurrency = "IMX",
string cryptoCurrencyList = "imx,eth,usdc"
)
{
var baseUrl = BaseUrls[_environment];
Expand All @@ -65,14 +65,14 @@ public string GetLink(
{"productsAvailed", "buy"},
{"exchangeScreenTitle", "Buy"},
{"themeColor", "0D0D0D"},
{"defaultCryptoCurrency", defaultCryptoCurrency},
{"defaultCryptoCurrency", cryptoCurrency},
{"email", Uri.EscapeDataString(_email)},
{"isAutoFillUserData", "true"},
{"disableWalletAddressForm", "true"},
{"defaultFiatAmount", defaultFiatAmount},
{"defaultFiatAmount", fiatAmount},
{"defaultFiatCurrency", fiatCurrency},
{"walletAddress", _address},
{"cryptoCurrencyList", defaultCryptoCurrencyList}
{"cryptoCurrencyList", cryptoCurrencyList}
};

var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray());
Expand Down
17 changes: 7 additions & 10 deletions src/Packages/Marketplace/Runtime/Swap/Swap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,23 @@ namespace Immutable.Marketplace.Swap
public class Swap
{
private readonly string _environment;
private readonly string _publishableKey;
private static readonly Dictionary<string, string> BaseUrls = new()
{
{ "sandbox", "https://checkout-playground.sandbox.immutable.com/checkout/swap" },
{ "production", "https://toolkit.immutable.com/checkout/swap" }
};

private static readonly Dictionary<string, string> ApiKeys = new()
{
{ "sandbox", "pk_imapik-test-7-hfC5T$W$eEDE8Mc5mp" }, // This can be hardcoded as it is a public API key
{ "production", "pk_imapik-WGd9orNd8mLdtTCTb3CP" }
};

/// <summary>
/// Initialises a new instance of the <see cref="Swap"/> class.
/// </summary>
/// <param name="environment">Specifies the environment (<c>sandbox</c> or <c>production</c>).</param>
public Swap(string environment)
/// <param name="environment">The environment to use (<c>sandbox</c> or <c>production</c>).</param>
/// <param name="publishableKey">The publishable key obtained from <a href="https://hub.immutable.com/">Immutable Hub</a>.
/// See <a href="https://docs.immutable.com/api/zkEVM/apikeys">API keys</a> for more details.</param>
public Swap(string environment, string publishableKey)
{
_environment = environment;
_publishableKey = publishableKey;
}

/// <summary>
Expand All @@ -41,11 +39,10 @@ public Swap(string environment)
public string GetLink(string? fromTokenAddress = null, string? toTokenAddress = null)
{
var baseUrl = BaseUrls[_environment];
var apiKey = ApiKeys[_environment];

var queryParams = new Dictionary<string, string>
{
{"publishableKey", apiKey}
{"publishableKey", _publishableKey}
};

if (!string.IsNullOrEmpty(fromTokenAddress))
Expand Down
Loading
Loading