From 228a15c081b0b588a10c3edc54a25cd52d123b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Lewi=C5=84ski?= Date: Mon, 24 Jun 2024 16:16:26 +0200 Subject: [PATCH] chore: update unity examples with new async versions (#160) * chore: update unity examples with new async versions * chore: reword --- pages/service/implementation-player-api.mdx | 4 +- .../operations/processing-operations.mdx | 31 ++++++------- pages/service/sessions/creating-sessions.mdx | 46 +++++++------------ .../sessions/signing-with-sessions.mdx | 33 ++++++------- 4 files changed, 47 insertions(+), 67 deletions(-) diff --git a/pages/service/implementation-player-api.mdx b/pages/service/implementation-player-api.mdx index c0b8e15..3632bd9 100644 --- a/pages/service/implementation-player-api.mdx +++ b/pages/service/implementation-player-api.mdx @@ -37,8 +37,8 @@ In order to interact with these clients, you will need a new type of API key - t ```csharp var beamClient = gameObject.AddComponent() - .SetBeamApiKey("your-publishable-api-key") // set your Publishable(!) API key - .SetEnvironment(BeamEnvironment.Testnet) // defaults to Testnet + .SetBeamApiKey("your-publishable-api-key") // required, sets your Publishable(!) API key + .SetEnvironment(BeamEnvironment.Testnet) // optional, defaults to Testnet .SetDebugLogging(true) // optional, defaults to false .SetStorage(yourCustomStorageImplementation); // optional, defaults to PlayerPrefs storage; ``` diff --git a/pages/service/operations/processing-operations.mdx b/pages/service/operations/processing-operations.mdx index 0b21b69..c308aaa 100644 --- a/pages/service/operations/processing-operations.mdx +++ b/pages/service/operations/processing-operations.mdx @@ -15,23 +15,20 @@ When using our SDK, processing an operation is as simple as providing the user e ```csharp -StartCoroutine(m_BeamClient.SignOperation( - "entityIdOfYourUser", - operationId, // operationId from Beam API - actionResult => - { - if (actionResult.Status == BeamResultType.Success) - { - // you can now check for actual Status of the signing f.e.: - var isApproved = actionResult.Result == BeamOperationStatus.Executed; - var isRejected = actionResult.Result == BeamOperationStatus.Rejected; - // (...) - } - }, - chainId: 13337, // optional chainId, defaults to 13337 - fallbackToBrowser: true, // if true, will automatically open browser for the user to sign the operation, if there is no valid session - secondsTimeout: 240 // timeout in seconds for getting a result of message signing from the browser, used if there was no valid session - )); + var operationId = "clxn9u(...)0c4bz7av"; + var operationResult = await m_BeamClient.SignOperationAsync( + entityId: "your-entity-id", + operationId: operationId, + signingBy: OperationSigningBy.Auto // accepts Auto, Browser and Session + ); + + if (operationResult.Status == BeamResultType.Success) + { + var operationStatus = operationResult.Result; + var isApproved = operationResult.Result == CommonOperationResponse.StatusEnum.Executed; + var isRejected = operationResult.Result == CommonOperationResponse.StatusEnum.Rejected; + // (...) + } ``` diff --git a/pages/service/sessions/creating-sessions.mdx b/pages/service/sessions/creating-sessions.mdx index 22126f0..03c53bd 100644 --- a/pages/service/sessions/creating-sessions.mdx +++ b/pages/service/sessions/creating-sessions.mdx @@ -10,19 +10,12 @@ In order to get started a Session going, you will need to call the following met ```csharp -StartCoroutine(beamClient.CreateSession( - "entityIdOfYourUser", - actionResult => - { - if (actionResult.Status == BeamResultType.Success) - { - var session = actionResult.Result; - // you now have an active session that can sign operations - } - }, - chainId: 13337, // optional chainId, defaults to 13337 - secondsTimeout: 240 // timeout in seconds for getting a result of Session signing from the browser - )); + var activeSessionResult = await m_BeamClient.CreateSessionAsync("your-entity-id"); + if (activeSessionResult.Status == BeamResultType.Success) + { + var session = activeSessionResult.Result; + // you can now sign Operations without leaving the game + } ``` @@ -41,20 +34,13 @@ Once handled, the session (private key) is able to sign transaction on behalf of You can retrieve current valid and active Session for your user. If local storage was cleared out, your game contracts changed, or the session simply expired - we will not return an active session. ``` csharp -StartCoroutine(beamClient.GetActiveSession( - "entityIdOfYourUser", - actionResult => - { - if (actionResult.Status == BeamResultType.Success) - { - var session = actionResult.Result; - // you have an active session that can sign operations - } - else - { - // you need to create a session using CreateSession(), or User will sign operations using browser - } - }, - chainId: 13337 // optional chainId, defaults to 13337 - )); -``` \ No newline at end of file + var activeSessionResult = await m_BeamClient.GetActiveSessionAsync("your-entity-id"); + if (activeSessionResult.Status == BeamResultType.Success) + { + var session = activeSessionResult.Result; + var validUntil = session.EndTime; + // (...) + } +``` + +* NOTE: You can make development and testing easier by clearing out Player Preferences. This allows you to create Sessions multiple times for the same User, as the private key owning them is lost on removal. \ No newline at end of file diff --git a/pages/service/sessions/signing-with-sessions.mdx b/pages/service/sessions/signing-with-sessions.mdx index 56dbe23..a378205 100644 --- a/pages/service/sessions/signing-with-sessions.mdx +++ b/pages/service/sessions/signing-with-sessions.mdx @@ -7,25 +7,22 @@ title: Signing with sessions Once the session is successfully created, it's authorized to sign [Operations](/service/operations/introduction). As the game developer, you're simply able to apply the same method as was described in [Processing Operations](/service/operations/processing-operations). -If a session is active for the user, the session key is still available in the local storage of the game client and the session is authorized to sign - `beamClient.SignOperation()` will automatically sign the Operation, without having the user ever seeing a browser. +If a session is active for the user, the session key is still available in the local storage of the game client and the session is authorized to sign - `SignOperationAsync()` will automatically sign the Operation, without user ever seeing a browser. ```csharp -StartCoroutine(beamClient.SignOperation( - "entityIdOfYourUser", - operationId, // operationId from Beam API - actionResult => - { - if (actionResult.Status == BeamResultType.Success) - { - // you can now check for actual Status of the signing f.e.: - var isApproved = actionResult.Result == BeamOperationStatus.Executed; - var isRejected = actionResult.Result == BeamOperationStatus.Rejected; - // (...) - } - }, - chainId: 13337, // optional chainId, defaults to 13337 - fallbackToBrowser: true, // if true, will automatically open browser for the user to sign the operation, if there is no valid session - secondsTimeout: 240 // timeout in seconds for getting a result of message signing from the browser, used if there was no valid session - )); + var operationId = "clxn9u(...)0c4bz7av"; + var operationResult = await m_BeamClient.SignOperationAsync( + entityId: "your-entity-id", + operationId: operationId, + signingBy: OperationSigningBy.Auto // accepts Auto, Browser and Session + ); + + if (operationResult.Status == BeamResultType.Success) + { + var operationStatus = operationResult.Result; + var isApproved = operationResult.Result == CommonOperationResponse.StatusEnum.Executed; + var isRejected = operationResult.Result == CommonOperationResponse.StatusEnum.Rejected; + // (...) + } ``` \ No newline at end of file