Skip to content
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

refactor: remove unused imports, nullables, update readmes #369

Merged
merged 1 commit into from
Dec 17, 2024
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
8 changes: 0 additions & 8 deletions .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ jobs:
mode: strict
tolerance: same
output: LICENSE-diff.txt
- name: Check that the README files are the exact same
uses: LouisBrunner/[email protected]
with:
old: README.md
new: src/Packages/Passport/README.md
mode: strict
tolerance: same
output: README-diff.txt
- name: Check that the CHANGELOG files are the exact same
uses: LouisBrunner/[email protected]
with:
Expand Down
72 changes: 12 additions & 60 deletions src/Packages/Marketplace/README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,17 @@
# Immutable.Marketplace - C# library for Immutable X Marketplace
<div align="center">
<p align="center">
<a href="https://docs.x.immutable.com/docs">
<img src="https://cdn.dribbble.com/users/1299339/screenshots/7133657/media/837237d447d36581ebd59ec36d30daea.gif" width="280"/>
</a>
</p>
</div>

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

## Version Support
# Immutable Unity SDK - Marketplace

This library supports:
The Immutable SDK Marketplace package for Unity simplifies integrating marketplace functionality, such as adding funds to a player's wallet.

- Unity 2020.3 (LTS) and up
- .NET Standard 2.1 / .NET Framework
## Documentation

## Dependencies

- [UniTask](https://github.com/Cysharp/UniTask) - For asynchronous operations
- Unity Engine

## Installation

Add the dependencies to your Unity project. You can do this through the Package Manager or by adding them to your `Packages/manifest.json`:

```json
{
"dependencies": {
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
"com.unity.nuget.newtonsoft-json": "3.0.2"
}
}
```

## Usage

Here's an example of how to use the OnRamp functionality with Immutable Passport:

```csharp
using Immutable.Marketplace.OnRamp;
using Immutable.Passport;
using Immutable.Passport.Model;
using System.Collections.Generic;
using UnityEngine;

public class MarketplaceExample : MonoBehaviour
{
async void Start()
{
string environment = Environment.SANDBOX;
string email = await Passport.Instance.GetEmail();
List<string> walletAddresses = await Passport.Instance.ZkEvmRequestAccounts();

OnRamp onRamp = new OnRamp(environment, email, walletAddresses.FirstOrDefault());

try
{
string link = await onRamp.GetLink();
Debug.Log($"onRamp.GetOnRampLink: {link}");

// Open the generated link in the default browser
Application.OpenURL(link);
}
catch (System.Exception e)
{
Debug.LogError($"Error getting on-ramp link: {e.Message}");
}
}
}
```
- [Immutable zkEVM Documentation](https://docs.immutable.com/docs/zkEVM/sdks/unity)
35 changes: 3 additions & 32 deletions src/Packages/Passport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,11 @@

---

# Immutable Unity SDK
# Immutable Unity SDK - Passport

The Immutable SDK for Unity helps you integrate your game with Immutable Passport.
The Immutable SDK Passport package for Unity helps you integrate your game with Immutable Passport.

# Documentation

* [Immutable X](https://docs.immutable.com/docs/x/sdks/unity)
* [Immutable zkEVM](https://docs.immutable.com/docs/zkEVM/sdks/unity)

## Contributing

Thank you for your interest in contributing to our project! Here's a quick guide on how you can get started:

1. **Fork this Repository**: Fork the repository to your GitHub account by clicking the "Fork" button at the top right of the repository page.
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).
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.
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.
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.
6. **Example Contribution**: Refer to [this contribution](https://github.com/immutable/unity-immutable-sdk/pull/182) as an example.

## Getting Help

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:

[Contact us](https://www.immutable.com/contact)

### Project Support

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.

[Join us on Discord](https://discord.gg/TkVumkJ9D6)

#### Still need help?

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.

[Contact support](https://support.immutable.com/hc/en-us/requests/new)
* [Immutable zkEVM](https://docs.immutable.com/docs/zkEVM/sdks/unity)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Immutable.Passport.Model;

namespace Immutable.Passport.Model
{
Expand Down
139 changes: 66 additions & 73 deletions src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class PassportImpl
{
private const string TAG = "[Passport Implementation]";
public readonly IBrowserCommunicationsManager communicationsManager;
private PassportAnalytics analytics = new PassportAnalytics();
private PassportAnalytics analytics = new();

// Used for device code auth
private DeviceConnectResponse deviceConnectResponse;
private DeviceConnectResponse? deviceConnectResponse;

// Used for PKCE
private bool pkceLoginOnly = false; // Used to differentiate between a login and connect
private UniTaskCompletionSource<bool> pkceCompletionSource;
private string redirectUri = null;
private string logoutRedirectUri = null;
private bool pkceLoginOnly; // Used to differentiate between a login and connect
private UniTaskCompletionSource<bool>? pkceCompletionSource;
private string? redirectUri;
private string? logoutRedirectUri;

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

public event OnAuthEventDelegate OnAuthEvent;
public event OnAuthEventDelegate? OnAuthEvent;

public PassportImpl(IBrowserCommunicationsManager communicationsManager)
{
this.communicationsManager = communicationsManager;
}

public async UniTask Init(string clientId, string environment, string redirectUri = null,
string logoutRedirectUri = null, string deeplink = null)
public async UniTask Init(string clientId, string environment, string? redirectUri = null,
string? logoutRedirectUri = null, string? deeplink = null)
{
this.redirectUri = redirectUri;
this.logoutRedirectUri = logoutRedirectUri;
Expand Down Expand Up @@ -85,7 +85,7 @@ public async UniTask Init(string clientId, string environment, string redirectUr
}
else
{
InitRequest request = new InitRequest()
InitRequest request = new InitRequest
{
clientId = clientId,
environment = environment,
Expand Down Expand Up @@ -113,34 +113,32 @@ public async UniTask Init(string clientId, string environment, string redirectUr

public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> timeoutMs = null)
{
string functionName = "Login";
if (useCachedSession)
{
return await Relogin();
}
else

try
{
try
{
Track(PassportAnalytics.EventName.START_LOGIN);
SendAuthEvent(PassportAuthEvent.LoggingIn);

await InitialiseDeviceCodeAuth(functionName);
await ConfirmCode(
PassportAuthEvent.LoginOpeningBrowser, PassportAuthEvent.PendingBrowserLogin, functionName,
PassportFunction.LOGIN_CONFIRM_CODE, timeoutMs);

Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: true);
SendAuthEvent(PassportAuthEvent.LoginSuccess);
isLoggedIn = true;
return true;
}
catch (Exception ex)
{
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: false);
SendAuthEvent(PassportAuthEvent.LoginFailed);
throw ex;
}
const string functionName = "Login";
Track(PassportAnalytics.EventName.START_LOGIN);
SendAuthEvent(PassportAuthEvent.LoggingIn);

await InitialiseDeviceCodeAuth(functionName);
await ConfirmCode(
PassportAuthEvent.LoginOpeningBrowser, PassportAuthEvent.PendingBrowserLogin, functionName,
PassportFunction.LOGIN_CONFIRM_CODE, timeoutMs);

Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: true);
SendAuthEvent(PassportAuthEvent.LoginSuccess);
isLoggedIn = true;
return true;
}
catch (Exception ex)
{
Track(PassportAnalytics.EventName.COMPLETE_LOGIN, success: false);
SendAuthEvent(PassportAuthEvent.LoginFailed);
throw ex;
}
}

Expand Down Expand Up @@ -176,49 +174,47 @@ private async UniTask<bool> Relogin()
return false;
}

public async UniTask<bool> ConnectImx(bool useCachedSession = false, Nullable<long> timeoutMs = null)
public async UniTask<bool> ConnectImx(bool useCachedSession = false, long? timeoutMs = null)
{
string functionName = "ConnectImx";
if (useCachedSession)
{
return await Reconnect();
}
else

// If the user called Login before and then ConnectImx, there is no point triggering device flow again
bool hasCredsSaved = await HasCredentialsSaved();
if (hasCredsSaved)
{
// If the user called Login before and then ConnectImx, there is no point triggering device flow again
bool hasCredsSaved = await HasCredentialsSaved();
if (hasCredsSaved)
bool reconnected = await Reconnect();
if (reconnected)
{
bool reconnected = await Reconnect();
if (reconnected)
{
// Successfully reconnected
return reconnected;
}
// Otherwise fallback to device code flow
// Successfully reconnected
return reconnected;
}
// Otherwise fallback to device code flow
}

try
{
Track(PassportAnalytics.EventName.START_CONNECT_IMX);
SendAuthEvent(PassportAuthEvent.ConnectingImx);

await InitialiseDeviceCodeAuth(functionName);
await ConfirmCode(
PassportAuthEvent.ConnectImxOpeningBrowser, PassportAuthEvent.PendingBrowserLoginAndProviderSetup,
functionName, PassportFunction.CONNECT_CONFIRM_CODE, timeoutMs);

Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: true);
SendAuthEvent(PassportAuthEvent.ConnectImxSuccess);
isLoggedIn = true;
return true;
}
catch (Exception ex)
{
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: false);
SendAuthEvent(PassportAuthEvent.ConnectImxFailed);
throw ex;
}
try
{
const string functionName = "ConnectImx";
Track(PassportAnalytics.EventName.START_CONNECT_IMX);
SendAuthEvent(PassportAuthEvent.ConnectingImx);

await InitialiseDeviceCodeAuth(functionName);
await ConfirmCode(
PassportAuthEvent.ConnectImxOpeningBrowser, PassportAuthEvent.PendingBrowserLoginAndProviderSetup,
functionName, PassportFunction.CONNECT_CONFIRM_CODE, timeoutMs);

Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: true);
SendAuthEvent(PassportAuthEvent.ConnectImxSuccess);
isLoggedIn = true;
return true;
}
catch (Exception ex)
{
Track(PassportAnalytics.EventName.COMPLETE_CONNECT_IMX, success: false);
SendAuthEvent(PassportAuthEvent.ConnectImxFailed);
throw ex;
}
}

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

private async UniTask ConfirmCode(
PassportAuthEvent openingBrowserAuthEvent, PassportAuthEvent pendingAuthEvent,
string callingFunction, string functionToCall, Nullable<long> timeoutMs = null)
string callingFunction, string functionToCall, long? timeoutMs)
{
if (deviceConnectResponse != null)
{
Expand Down Expand Up @@ -553,9 +549,9 @@ public async UniTask Logout(bool hardLogout = true)
{
SendAuthEvent(PassportAuthEvent.LoggingOut);

string logoutUrl = await GetLogoutUrl();
if (hardLogout)
{
var logoutUrl = await GetLogoutUrl();
OpenUrl(logoutUrl);
}

Expand Down Expand Up @@ -859,10 +855,7 @@ private void TrySetPKCECanceled()
private void SendAuthEvent(PassportAuthEvent authEvent)
{
PassportLogger.Debug($"{TAG} Send auth event: {authEvent}");
if (OnAuthEvent != null)
{
OnAuthEvent.Invoke(authEvent);
}
OnAuthEvent?.Invoke(authEvent);
}

protected virtual void OpenUrl(string url)
Expand Down
4 changes: 2 additions & 2 deletions src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void SetCallTimeout(int ms)
/// <returns>
/// Returns true if login is successful, otherwise false.
/// </returns>
public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> timeoutMs = null)
public async UniTask<bool> Login(bool useCachedSession = false, long? timeoutMs = null)
{
return await GetPassportImpl().Login(useCachedSession, timeoutMs);
}
Expand All @@ -268,7 +268,7 @@ public async UniTask<bool> Login(bool useCachedSession = false, Nullable<long> t
/// <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>
/// <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>
/// </summary>
public async UniTask<bool> ConnectImx(bool useCachedSession = false, Nullable<long> timeoutMs = null)
public async UniTask<bool> ConnectImx(bool useCachedSession = false, long? timeoutMs = null)
{
return await GetPassportImpl().ConnectImx(useCachedSession, timeoutMs);
}
Expand Down
Loading