From ce0e05fedd4fda7ecd098f96153928e19ec28b7e Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 17 Dec 2024 17:28:43 +1300 Subject: [PATCH] refactor: remove unused imports, nullables, update readmes --- .github/workflows/diff.yml | 8 - src/Packages/Marketplace/README.md | 72 ++------- src/Packages/Passport/README.md | 35 +---- .../Private/Model/Request/InitRequest.cs | 1 - .../Runtime/Scripts/Private/PassportImpl.cs | 139 +++++++++--------- .../Runtime/Scripts/Public/Passport.cs | 4 +- 6 files changed, 83 insertions(+), 176 deletions(-) diff --git a/.github/workflows/diff.yml b/.github/workflows/diff.yml index d18f9f65..7f812586 100644 --- a/.github/workflows/diff.yml +++ b/.github/workflows/diff.yml @@ -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/diff-action@v2.0.0 - 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/diff-action@v2.0.0 with: diff --git a/src/Packages/Marketplace/README.md b/src/Packages/Marketplace/README.md index c42ab0dd..59582d1a 100644 --- a/src/Packages/Marketplace/README.md +++ b/src/Packages/Marketplace/README.md @@ -1,65 +1,17 @@ -# Immutable.Marketplace - C# library for Immutable X Marketplace +
+

+ + + +

+
-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 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}"); - } - } -} -``` \ No newline at end of file +- [Immutable zkEVM Documentation](https://docs.immutable.com/docs/zkEVM/sdks/unity) \ No newline at end of file diff --git a/src/Packages/Passport/README.md b/src/Packages/Passport/README.md index 39eb07e8..2fdd696e 100644 --- a/src/Packages/Passport/README.md +++ b/src/Packages/Passport/README.md @@ -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) \ No newline at end of file diff --git a/src/Packages/Passport/Runtime/Scripts/Private/Model/Request/InitRequest.cs b/src/Packages/Passport/Runtime/Scripts/Private/Model/Request/InitRequest.cs index 61ceb5ce..da20f9c7 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/Model/Request/InitRequest.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/Model/Request/InitRequest.cs @@ -1,5 +1,4 @@ using System; -using Immutable.Passport.Model; namespace Immutable.Passport.Model { diff --git a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs index b7437ac7..a48a696a 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs @@ -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 pkceCompletionSource; - private string redirectUri = null; - private string logoutRedirectUri = null; + private bool pkceLoginOnly; // Used to differentiate between a login and connect + private UniTaskCompletionSource? pkceCompletionSource; + private string? redirectUri; + private string? logoutRedirectUri; #if UNITY_ANDROID // Used for the PKCE callback @@ -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; @@ -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, @@ -113,34 +113,32 @@ public async UniTask Init(string clientId, string environment, string redirectUr public async UniTask Login(bool useCachedSession = false, Nullable 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; } } @@ -176,49 +174,47 @@ private async UniTask Relogin() return false; } - public async UniTask ConnectImx(bool useCachedSession = false, Nullable timeoutMs = null) + public async UniTask 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; } } @@ -274,7 +270,7 @@ private async UniTask InitialiseDeviceCodeAuth(string callingFu private async UniTask ConfirmCode( PassportAuthEvent openingBrowserAuthEvent, PassportAuthEvent pendingAuthEvent, - string callingFunction, string functionToCall, Nullable timeoutMs = null) + string callingFunction, string functionToCall, long? timeoutMs) { if (deviceConnectResponse != null) { @@ -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); } @@ -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) diff --git a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs index cdae9617..e5d28579 100644 --- a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs +++ b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs @@ -257,7 +257,7 @@ public void SetCallTimeout(int ms) /// /// Returns true if login is successful, otherwise false. /// - public async UniTask Login(bool useCachedSession = false, Nullable timeoutMs = null) + public async UniTask Login(bool useCachedSession = false, long? timeoutMs = null) { return await GetPassportImpl().Login(useCachedSession, timeoutMs); } @@ -268,7 +268,7 @@ public async UniTask Login(bool useCachedSession = false, Nullable t /// 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. /// (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. /// - public async UniTask ConnectImx(bool useCachedSession = false, Nullable timeoutMs = null) + public async UniTask ConnectImx(bool useCachedSession = false, long? timeoutMs = null) { return await GetPassportImpl().ConnectImx(useCachedSession, timeoutMs); }