Skip to content

Commit

Permalink
chore: update unity examples with new async versions (#160)
Browse files Browse the repository at this point in the history
* chore: update unity examples with new async versions

* chore: reword
  • Loading branch information
lewinskimaciej authored Jun 24, 2024
1 parent 9487cea commit 228a15c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 67 deletions.
4 changes: 2 additions & 2 deletions pages/service/implementation-player-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<BeamClient>()
.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;
```
Expand Down
31 changes: 14 additions & 17 deletions pages/service/operations/processing-operations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// (...)
}
```


Expand Down
46 changes: 16 additions & 30 deletions pages/service/sessions/creating-sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```


Expand All @@ -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
));
```
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.
33 changes: 15 additions & 18 deletions pages/service/sessions/signing-with-sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// (...)
}
```

0 comments on commit 228a15c

Please sign in to comment.