Skip to content

Commit b1d1dd1

Browse files
authored
Merge pull request #385 from immutable/feat/swap-api-key
[DX-3548] feat: swap api key
2 parents 62db9e3 + f7d6199 commit b1d1dd1

File tree

4 files changed

+7433
-41
lines changed

4 files changed

+7433
-41
lines changed

sample/Assets/Scenes/SelectAuthMethod.unity

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ MonoBehaviour:
206206
m_TargetGraphic: {fileID: 416242725}
207207
m_HandleRect: {fileID: 416242724}
208208
m_Direction: 0
209-
m_Value: 1
210-
m_Size: 0.9999999
209+
m_Value: 0
210+
m_Size: 1
211211
m_NumberOfSteps: 0
212212
m_OnValueChanged:
213213
m_PersistentCalls:
@@ -1324,7 +1324,7 @@ MonoBehaviour:
13241324
m_HandleRect: {fileID: 167431871}
13251325
m_Direction: 2
13261326
m_Value: 1
1327-
m_Size: 0.99999994
1327+
m_Size: 1
13281328
m_NumberOfSteps: 0
13291329
m_OnValueChanged:
13301330
m_PersistentCalls:
@@ -1673,8 +1673,8 @@ RectTransform:
16731673
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
16741674
m_AnchorMin: {x: 0, y: 0}
16751675
m_AnchorMax: {x: 0, y: 0}
1676-
m_AnchoredPosition: {x: 1222.7355, y: 0}
1677-
m_SizeDelta: {x: 2405.471, y: 0}
1676+
m_AnchoredPosition: {x: 1016.24, y: 0}
1677+
m_SizeDelta: {x: 1992.48, y: 0}
16781678
m_Pivot: {x: 0.5, y: 0.5}
16791679
--- !u!114 &1661390145
16801680
MonoBehaviour:
@@ -1768,8 +1768,8 @@ RectTransform:
17681768
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
17691769
m_AnchorMin: {x: 0, y: 0}
17701770
m_AnchorMax: {x: 0, y: 0}
1771-
m_AnchoredPosition: {x: 1222.7355, y: 0}
1772-
m_SizeDelta: {x: 2405.471, y: 0}
1771+
m_AnchoredPosition: {x: 1016.24, y: 0}
1772+
m_SizeDelta: {x: 1992.48, y: 0}
17731773
m_Pivot: {x: 0.5, y: 0.5}
17741774
--- !u!114 &1688502349
17751775
MonoBehaviour:
@@ -1822,21 +1822,21 @@ MonoBehaviour:
18221822
18231823
18241824
1.
1825-
Device Code Authorisation Device Code Authorisation is available for all supported
1826-
platforms. This method opens the player''s default browser and guides them through
1827-
the authentication flow.
1825+
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
1826+
for Android, iOS, macOS and WebGL (not officially supported). This method provides
1827+
a seamless and secure authentication experience by opening a pop-up window on
1828+
macOS or an in-app browser on mobile devices. Players are automatically redirected
1829+
back to the game once authenticated, eliminating manual switching.
18281830
18291831
1830-
2. Authorisation Code Flow with Proof Key for
1831-
Code Exchange (PKCE) PKCE is available for Android, iOS and macOS. This method
1832-
simplifies the process by opening a pop-up window on macOS or an in-app browser
1833-
on mobile devices, guiding users through the authentication flow. Once authenticated,
1834-
players are automatically redirected back to the game, eliminating the need for
1835-
manual switching.
1832+
2. Device
1833+
Code Authorisation is available for Windows, Android, iOS and macOS. This method
1834+
opens the player''s default browser and guides them through the authentication
1835+
flow.
18361836
18371837
1838-
Recommendation: For an optimal gaming experience on Android,
1839-
iOS, macOS or WebGL, it is recommended to use the PKCE flow.'
1838+
Recommendation: Whenever possible, use the PKCE flow as it is the
1839+
most secure and seamless method for authentication on Android, iOS and macOS.'
18401840
--- !u!222 &1688502351
18411841
CanvasRenderer:
18421842
m_ObjectHideFlags: 0
@@ -1912,7 +1912,7 @@ MonoBehaviour:
19121912
m_PersistentCalls:
19131913
m_Calls: []
19141914
m_FontData:
1915-
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 3}
1915+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
19161916
m_FontSize: 20
19171917
m_FontStyle: 0
19181918
m_BestFit: 0

src/Packages/Marketplace/Runtime/OnRamp/OnRamp.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ public OnRamp(string environment, string email, string address)
3939
}
4040

4141
/// <summary>
42-
/// Generates a link for the on-ramp flow.
42+
/// Generates a URL for the on-ramp flow.
4343
/// </summary>
44-
/// <param name="fiatCurrency">The fiat currency to be used (default is "USD").</param>
45-
/// <param name="defaultFiatAmount">The default amount of fiat currency (default is "50").</param>
46-
/// <param name="defaultCryptoCurrency">The default cryptocurrency (default is "IMX")..</param>
47-
/// <param name="defaultCryptoCurrencyList">A comma-separated list of available cryptocurrencies to purchase (default is "imx,eth,usdc").</param>
48-
/// <returns>An on-ramp URL</returns>
44+
/// <param name="fiatCurrency">The fiat currency to use (default: "USD").</param>
45+
/// <param name="fiatAmount">The amount of fiat currency to spend when purchasing cryptocurrency (default: "50").</param>
46+
/// <param name="cryptoCurrency">The cryptocurrency to purchase (default: "IMX").</param>
47+
/// <param name="cryptoCurrencyList">A comma-separated list of available cryptocurrencies for purchase (default: "imx,eth,usdc").</param>
48+
/// <returns>The generated on-ramp URL.</returns>
4949
public string GetLink(
5050
string fiatCurrency = "USD",
51-
string defaultFiatAmount = "50",
52-
string defaultCryptoCurrency = "IMX",
53-
string defaultCryptoCurrencyList = "imx,eth,usdc"
51+
string fiatAmount = "50",
52+
string cryptoCurrency = "IMX",
53+
string cryptoCurrencyList = "imx,eth,usdc"
5454
)
5555
{
5656
var baseUrl = BaseUrls[_environment];
@@ -65,14 +65,14 @@ public string GetLink(
6565
{"productsAvailed", "buy"},
6666
{"exchangeScreenTitle", "Buy"},
6767
{"themeColor", "0D0D0D"},
68-
{"defaultCryptoCurrency", defaultCryptoCurrency},
68+
{"defaultCryptoCurrency", cryptoCurrency},
6969
{"email", Uri.EscapeDataString(_email)},
7070
{"isAutoFillUserData", "true"},
7171
{"disableWalletAddressForm", "true"},
72-
{"defaultFiatAmount", defaultFiatAmount},
72+
{"defaultFiatAmount", fiatAmount},
7373
{"defaultFiatCurrency", fiatCurrency},
7474
{"walletAddress", _address},
75-
{"cryptoCurrencyList", defaultCryptoCurrencyList}
75+
{"cryptoCurrencyList", cryptoCurrencyList}
7676
};
7777

7878
var queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}").ToArray());

src/Packages/Marketplace/Runtime/Swap/Swap.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@ namespace Immutable.Marketplace.Swap
1111
public class Swap
1212
{
1313
private readonly string _environment;
14+
private readonly string _publishableKey;
1415
private static readonly Dictionary<string, string> BaseUrls = new()
1516
{
1617
{ "sandbox", "https://checkout-playground.sandbox.immutable.com/checkout/swap" },
1718
{ "production", "https://toolkit.immutable.com/checkout/swap" }
1819
};
1920

20-
private static readonly Dictionary<string, string> ApiKeys = new()
21-
{
22-
{ "sandbox", "pk_imapik-test-7-hfC5T$W$eEDE8Mc5mp" }, // This can be hardcoded as it is a public API key
23-
{ "production", "pk_imapik-WGd9orNd8mLdtTCTb3CP" }
24-
};
25-
2621
/// <summary>
2722
/// Initialises a new instance of the <see cref="Swap"/> class.
2823
/// </summary>
29-
/// <param name="environment">Specifies the environment (<c>sandbox</c> or <c>production</c>).</param>
30-
public Swap(string environment)
24+
/// <param name="environment">The environment to use (<c>sandbox</c> or <c>production</c>).</param>
25+
/// <param name="publishableKey">The publishable key obtained from <a href="https://hub.immutable.com/">Immutable Hub</a>.
26+
/// See <a href="https://docs.immutable.com/api/zkEVM/apikeys">API keys</a> for more details.</param>
27+
public Swap(string environment, string publishableKey)
3128
{
3229
_environment = environment;
30+
_publishableKey = publishableKey;
3331
}
3432

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

4643
var queryParams = new Dictionary<string, string>
4744
{
48-
{"publishableKey", apiKey}
45+
{"publishableKey", _publishableKey}
4946
};
5047

5148
if (!string.IsNullOrEmpty(fromTokenAddress))

0 commit comments

Comments
 (0)