Skip to content

Commit ae3786d

Browse files
committed
refactor: remove unused imports, nullables, update readmes
1 parent da1e4ed commit ae3786d

File tree

5 files changed

+82
-138
lines changed

5 files changed

+82
-138
lines changed

src/Packages/Marketplace/README.md

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,17 @@
1-
# Immutable.Marketplace - C# library for Immutable X Marketplace
1+
<div align="center">
2+
<p align="center">
3+
<a href="https://docs.x.immutable.com/docs">
4+
<img src="https://cdn.dribbble.com/users/1299339/screenshots/7133657/media/837237d447d36581ebd59ec36d30daea.gif" width="280"/>
5+
</a>
6+
</p>
7+
</div>
28

3-
This C# library provides functionality for interacting with the Immutable X Marketplace, including on-ramp services.
9+
---
410

5-
## Version Support
11+
# Immutable Unity SDK - Marketplace
612

7-
This library supports:
13+
The Immutable SDK Commerce package for Unity simplifies integrating marketplace functionality, such as adding funds to a player's wallet.
814

9-
- Unity 2020.3 (LTS) and up
10-
- .NET Standard 2.1 / .NET Framework
15+
## Documentation
1116

12-
## Dependencies
13-
14-
- [UniTask](https://github.com/Cysharp/UniTask) - For asynchronous operations
15-
- Unity Engine
16-
17-
## Installation
18-
19-
Add the dependencies to your Unity project. You can do this through the Package Manager or by adding them to your `Packages/manifest.json`:
20-
21-
```json
22-
{
23-
"dependencies": {
24-
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
25-
"com.unity.nuget.newtonsoft-json": "3.0.2"
26-
}
27-
}
28-
```
29-
30-
## Usage
31-
32-
Here's an example of how to use the OnRamp functionality with Immutable Passport:
33-
34-
```csharp
35-
using Immutable.Marketplace.OnRamp;
36-
using Immutable.Passport;
37-
using Immutable.Passport.Model;
38-
using System.Collections.Generic;
39-
using UnityEngine;
40-
41-
public class MarketplaceExample : MonoBehaviour
42-
{
43-
async void Start()
44-
{
45-
string environment = Environment.SANDBOX;
46-
string email = await Passport.Instance.GetEmail();
47-
List<string> walletAddresses = await Passport.Instance.ZkEvmRequestAccounts();
48-
49-
OnRamp onRamp = new OnRamp(environment, email, walletAddresses.FirstOrDefault());
50-
51-
try
52-
{
53-
string link = await onRamp.GetLink();
54-
Debug.Log($"onRamp.GetOnRampLink: {link}");
55-
56-
// Open the generated link in the default browser
57-
Application.OpenURL(link);
58-
}
59-
catch (System.Exception e)
60-
{
61-
Debug.LogError($"Error getting on-ramp link: {e.Message}");
62-
}
63-
}
64-
}
65-
```
17+
- [Immutable zkEVM Documentation](https://docs.immutable.com/docs/zkEVM/sdks/unity)

src/Packages/Passport/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
---
1010

11-
# Immutable Unity SDK
11+
# Immutable Unity SDK - Passport
1212

13-
The Immutable SDK for Unity helps you integrate your game with Immutable Passport.
13+
The Immutable SDK Passport package for Unity helps you integrate your game with Immutable Passport.
1414

1515
# Documentation
1616

src/Packages/Passport/Runtime/Scripts/Private/Model/Request/InitRequest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Immutable.Passport.Model;
32

43
namespace Immutable.Passport.Model
54
{

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 66 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public class PassportImpl
2222
{
2323
private const string TAG = "[Passport Implementation]";
2424
public readonly IBrowserCommunicationsManager communicationsManager;
25-
private PassportAnalytics analytics = new PassportAnalytics();
25+
private PassportAnalytics analytics = new();
2626

2727
// Used for device code auth
28-
private DeviceConnectResponse deviceConnectResponse;
28+
private DeviceConnectResponse? deviceConnectResponse;
2929

3030
// Used for PKCE
31-
private bool pkceLoginOnly = false; // Used to differentiate between a login and connect
32-
private UniTaskCompletionSource<bool> pkceCompletionSource;
33-
private string redirectUri = null;
34-
private string logoutRedirectUri = null;
31+
private bool pkceLoginOnly; // Used to differentiate between a login and connect
32+
private UniTaskCompletionSource<bool>? pkceCompletionSource;
33+
private string? redirectUri;
34+
private string? logoutRedirectUri;
3535

3636
#if UNITY_ANDROID
3737
// Used for the PKCE callback
@@ -42,15 +42,15 @@ public class PassportImpl
4242
// Used to prevent calling login/connect functions multiple times
4343
private bool isLoggedIn = false;
4444

45-
public event OnAuthEventDelegate OnAuthEvent;
45+
public event OnAuthEventDelegate? OnAuthEvent;
4646

4747
public PassportImpl(IBrowserCommunicationsManager communicationsManager)
4848
{
4949
this.communicationsManager = communicationsManager;
5050
}
5151

52-
public async UniTask Init(string clientId, string environment, string redirectUri = null,
53-
string logoutRedirectUri = null, string deeplink = null)
52+
public async UniTask Init(string clientId, string environment, string? redirectUri = null,
53+
string? logoutRedirectUri = null, string? deeplink = null)
5454
{
5555
this.redirectUri = redirectUri;
5656
this.logoutRedirectUri = logoutRedirectUri;
@@ -85,7 +85,7 @@ public async UniTask Init(string clientId, string environment, string redirectUr
8585
}
8686
else
8787
{
88-
InitRequest request = new InitRequest()
88+
InitRequest request = new InitRequest
8989
{
9090
clientId = clientId,
9191
environment = environment,
@@ -113,34 +113,32 @@ public async UniTask Init(string clientId, string environment, string redirectUr
113113

114114
public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> timeoutMs = null)
115115
{
116-
string functionName = "Login";
117116
if (useCachedSession)
118117
{
119118
return await Relogin();
120119
}
121-
else
120+
121+
try
122122
{
123-
try
124-
{
125-
Track(PassportAnalytics.EventName.START_LOGIN);
126-
SendAuthEvent(PassportAuthEvent.LoggingIn);
127-
128-
await InitialiseDeviceCodeAuth(functionName);
129-
await ConfirmCode(
130-
PassportAuthEvent.LoginOpeningBrowser, PassportAuthEvent.PendingBrowserLogin, functionName,
131-
PassportFunction.LOGIN_CONFIRM_CODE, timeoutMs);
132-
133-
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: true);
134-
SendAuthEvent(PassportAuthEvent.LoginSuccess);
135-
isLoggedIn = true;
136-
return true;
137-
}
138-
catch (Exception ex)
139-
{
140-
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: false);
141-
SendAuthEvent(PassportAuthEvent.LoginFailed);
142-
throw ex;
143-
}
123+
const string functionName = "Login";
124+
Track(PassportAnalytics.EventName.START_LOGIN);
125+
SendAuthEvent(PassportAuthEvent.LoggingIn);
126+
127+
await InitialiseDeviceCodeAuth(functionName);
128+
await ConfirmCode(
129+
PassportAuthEvent.LoginOpeningBrowser, PassportAuthEvent.PendingBrowserLogin, functionName,
130+
PassportFunction.LOGIN_CONFIRM_CODE, timeoutMs);
131+
132+
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: true);
133+
SendAuthEvent(PassportAuthEvent.LoginSuccess);
134+
isLoggedIn = true;
135+
return true;
136+
}
137+
catch (Exception ex)
138+
{
139+
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: false);
140+
SendAuthEvent(PassportAuthEvent.LoginFailed);
141+
throw ex;
144142
}
145143
}
146144

@@ -176,49 +174,47 @@ private async UniTask<bool> Relogin()
176174
return false;
177175
}
178176

179-
public async UniTask<bool> ConnectImx(bool useCachedSession = false, Nullable<long> timeoutMs = null)
177+
public async UniTask<bool> ConnectImx(bool useCachedSession = false, long? timeoutMs = null)
180178
{
181-
string functionName = "ConnectImx";
182179
if (useCachedSession)
183180
{
184181
return await Reconnect();
185182
}
186-
else
183+
184+
// If the user called Login before and then ConnectImx, there is no point triggering device flow again
185+
bool hasCredsSaved = await HasCredentialsSaved();
186+
if (hasCredsSaved)
187187
{
188-
// If the user called Login before and then ConnectImx, there is no point triggering device flow again
189-
bool hasCredsSaved = await HasCredentialsSaved();
190-
if (hasCredsSaved)
188+
bool reconnected = await Reconnect();
189+
if (reconnected)
191190
{
192-
bool reconnected = await Reconnect();
193-
if (reconnected)
194-
{
195-
// Successfully reconnected
196-
return reconnected;
197-
}
198-
// Otherwise fallback to device code flow
191+
// Successfully reconnected
192+
return reconnected;
199193
}
194+
// Otherwise fallback to device code flow
195+
}
200196

201-
try
202-
{
203-
Track(PassportAnalytics.EventName.START_CONNECT_IMX);
204-
SendAuthEvent(PassportAuthEvent.ConnectingImx);
205-
206-
await InitialiseDeviceCodeAuth(functionName);
207-
await ConfirmCode(
208-
PassportAuthEvent.ConnectImxOpeningBrowser, PassportAuthEvent.PendingBrowserLoginAndProviderSetup,
209-
functionName, PassportFunction.CONNECT_CONFIRM_CODE, timeoutMs);
210-
211-
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: true);
212-
SendAuthEvent(PassportAuthEvent.ConnectImxSuccess);
213-
isLoggedIn = true;
214-
return true;
215-
}
216-
catch (Exception ex)
217-
{
218-
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: false);
219-
SendAuthEvent(PassportAuthEvent.ConnectImxFailed);
220-
throw ex;
221-
}
197+
try
198+
{
199+
const string functionName = "ConnectImx";
200+
Track(PassportAnalytics.EventName.START_CONNECT_IMX);
201+
SendAuthEvent(PassportAuthEvent.ConnectingImx);
202+
203+
await InitialiseDeviceCodeAuth(functionName);
204+
await ConfirmCode(
205+
PassportAuthEvent.ConnectImxOpeningBrowser, PassportAuthEvent.PendingBrowserLoginAndProviderSetup,
206+
functionName, PassportFunction.CONNECT_CONFIRM_CODE, timeoutMs);
207+
208+
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: true);
209+
SendAuthEvent(PassportAuthEvent.ConnectImxSuccess);
210+
isLoggedIn = true;
211+
return true;
212+
}
213+
catch (Exception ex)
214+
{
215+
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: false);
216+
SendAuthEvent(PassportAuthEvent.ConnectImxFailed);
217+
throw ex;
222218
}
223219
}
224220

@@ -274,7 +270,7 @@ private async UniTask<ConnectResponse> InitialiseDeviceCodeAuth(string callingFu
274270

275271
private async UniTask ConfirmCode(
276272
PassportAuthEvent openingBrowserAuthEvent, PassportAuthEvent pendingAuthEvent,
277-
string callingFunction, string functionToCall, Nullable<long> timeoutMs = null)
273+
string callingFunction, string functionToCall, long? timeoutMs)
278274
{
279275
if (deviceConnectResponse != null)
280276
{
@@ -553,9 +549,9 @@ public async UniTask Logout(bool hardLogout = true)
553549
{
554550
SendAuthEvent(PassportAuthEvent.LoggingOut);
555551

556-
string logoutUrl = await GetLogoutUrl();
557552
if (hardLogout)
558553
{
554+
var logoutUrl = await GetLogoutUrl();
559555
OpenUrl(logoutUrl);
560556
}
561557

@@ -859,10 +855,7 @@ private void TrySetPKCECanceled()
859855
private void SendAuthEvent(PassportAuthEvent authEvent)
860856
{
861857
PassportLogger.Debug($"{TAG} Send auth event: {authEvent}");
862-
if (OnAuthEvent != null)
863-
{
864-
OnAuthEvent.Invoke(authEvent);
865-
}
858+
OnAuthEvent?.Invoke(authEvent);
866859
}
867860

868861
protected virtual void OpenUrl(string url)

src/Packages/Passport/Runtime/Scripts/Public/Passport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void SetCallTimeout(int ms)
257257
/// <returns>
258258
/// Returns true if login is successful, otherwise false.
259259
/// </returns>
260-
public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> timeoutMs = null)
260+
public async UniTask<bool> Login(bool useCachedSession = false, long? timeoutMs = null)
261261
{
262262
return await GetPassportImpl().Login(useCachedSession, timeoutMs);
263263
}
@@ -268,7 +268,7 @@ public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> t
268268
/// <param name="useCachedSession">If true, the saved access token or refresh token will be used to connect the user. If this fails, it will not fallback to device code auth.</param>
269269
/// <param name="timeoutMs">(Optional) The maximum time, in milliseconds, the function is allowed to take before a TimeoutException is thrown. If not set, the function will wait indefinitely.</param>
270270
/// </summary>
271-
public async UniTask<bool> ConnectImx(bool useCachedSession = false, Nullable<long> timeoutMs = null)
271+
public async UniTask<bool> ConnectImx(bool useCachedSession = false, long? timeoutMs = null)
272272
{
273273
return await GetPassportImpl().ConnectImx(useCachedSession, timeoutMs);
274274
}

0 commit comments

Comments
 (0)