Skip to content

Commit f4d4bc3

Browse files
authored
Merge pull request #369 from immutable/refactor/nullable
refactor: remove unused imports, nullables, update readmes
2 parents da1e4ed + ce0e05f commit f4d4bc3

File tree

6 files changed

+83
-176
lines changed

6 files changed

+83
-176
lines changed

.github/workflows/diff.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ jobs:
1515
mode: strict
1616
tolerance: same
1717
output: LICENSE-diff.txt
18-
- name: Check that the README files are the exact same
19-
uses: LouisBrunner/[email protected]
20-
with:
21-
old: README.md
22-
new: src/Packages/Passport/README.md
23-
mode: strict
24-
tolerance: same
25-
output: README-diff.txt
2618
- name: Check that the CHANGELOG files are the exact same
2719
uses: LouisBrunner/[email protected]
2820
with:

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 Marketplace 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: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,11 @@
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

1717
* [Immutable X](https://docs.immutable.com/docs/x/sdks/unity)
18-
* [Immutable zkEVM](https://docs.immutable.com/docs/zkEVM/sdks/unity)
19-
20-
## Contributing
21-
22-
Thank you for your interest in contributing to our project! Here's a quick guide on how you can get started:
23-
24-
1. **Fork this Repository**: Fork the repository to your GitHub account by clicking the "Fork" button at the top right of the repository page.
25-
2. **Create a Branch**: Once you've forked the repository, create a new branch in your forked repository where you'll be making your changes. Branch naming convention is enforced [according to patterns here](https://github.com/deepakputhraya/action-branch-name).
26-
3. **Make Changes**: Make the necessary changes in your branch. Ensure that your changes are clear, well-documented, and aligned with the project's guidelines.
27-
4. **Commit Changes**: Commit your changes with clear and descriptive messages following [commit message pattern here](https://github.com/conventional-changelog/commitlint?tab=readme-ov-file#what-is-commitlint). It follows [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/#specification), which helps maintain a consistent and informative commit history. Read [here](https://www.conventionalcommits.org/en/v1.0.0/#why-use-conventional-commits) to learn more about the benefits of Conventional Commits.
28-
5. **Create a Pull Request (PR)**: After you've made and committed your changes, create a PR against the original repository. Provide a clear description of the changes you've made in the PR.
29-
6. **Example Contribution**: Refer to [this contribution](https://github.com/immutable/unity-immutable-sdk/pull/182) as an example.
30-
31-
## Getting Help
32-
33-
Immutable X is open to all to build on, with no approvals required. If you want to talk to us to learn more, or apply for developer grants, click below:
34-
35-
[Contact us](https://www.immutable.com/contact)
36-
37-
### Project Support
38-
39-
To get help from other developers, discuss ideas, and stay up-to-date on what's happening, become a part of our community on Discord.
40-
41-
[Join us on Discord](https://discord.gg/TkVumkJ9D6)
42-
43-
#### Still need help?
44-
45-
You can also apply for marketing support for your project. Or, if you need help with an issue related to what you're building with Immutable X, click below to submit an issue. Select _I have a question_ or _issue related to building on Immutable X_ as your issue type.
46-
47-
[Contact support](https://support.immutable.com/hc/en-us/requests/new)
18+
* [Immutable zkEVM](https://docs.immutable.com/docs/zkEVM/sdks/unity)

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)