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

Feat: token endpoint added for SolanaApi #60

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
91 changes: 91 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# web3-unity-sdk

The web3-unity-sdk is aimed at helping developers build web3 based unity games fast, delivering a quality DX to our developers plus an inclusive and reliable UX to your end users.
Thank you for taking an interest in contributing

 

# Our core goals for this SDK 📈

 

# About our stack

 

# Getting started

 

# Got an idea for a component?

You can start coding right away but in order for us to organize the build, please follow these steps

1. Open an issue in our gitHub repo https://github.com/MoralisWeb3/web3-unity-sdk/issues
2. Give the issue a title prefixed with feature, bugFix, docs or chore
3. Describe what you will build, or fix as best you can so we know what to expect
4. Add any examples like images, design ideas or CodePen mockups
5. Be open to refinement of your idea
6. Stay in communication, once we accept the proposal we want that update. If you disappear we might finish it for you or pass it to another dev
7. To complete your task and be merged, you should read about Pull Requests below
8. In need of inspiration? Keep an eye on the issue board as our team will open issues for you and even add new designs for components we need, hot from our Moralis design UX team.

 

# NewComp

Just a friendly heads up incase you missed that above...
We have made a component called `NewComp` you can copy and paste this component to get started but don't change it or we will reject your pull request, sorry. Suggestions are welcome but we are pretty happy with it.
This component has an example of just about everything with a friendly non programmer comment to help you learn, how we do things, why we do them and what we expect when it comes to a pull request.

Lets take a tour and look at some of our standards


# Pull Request

For your pull request please follow this guide

## Branch Name

`pull request type + task`

- so if i add a new tokenapi addon my branch is `feat-addedTokenApi`

**Pull request types:**

- feat = new feature
- fix = bug fix
- docs = added or changed documentation
- chore = some mindless work, like reformatting

So if i fix the validation to the `Form` my branch is `fix-form-validation`... you get it, right? 😅

## Conventional Commits

We follow a strict convectional commits pattern, and please if you change more than one component, then have 1 commit per components. No monster PRs please, its hard to review them if you change 500 files in one go, lol
https://www.conventionalcommits.org/en/v1.0.0/

## PR Feedback

We are all students in this journey of life, so please accept any critique given. We are just trying to help you out or align your code with our base perhaps. This is a difficult but important part of collaboration and team work.
lets **review each others code and PRs**

**Q:** Why peer review?

**A:** So we can all learn from each other, the rising tide brings up all ships.

 

# Approval

Don't forget we can approve and merge your code but you need to add your component to the projects base `index.ts` so the next dev can use it.

 


# Any questions?

Jump over to the Moralis Discord and checkout the channel `game-dev`

 

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions Runtime/SolanaApi/Api/TokenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using System.Net;
using MoralisUnity.SolanaApi.Client;
using MoralisUnity.SolanaApi.Interfaces;
using MoralisUnity.SolanaApi.Models;

namespace MoralisUnity.SolanaApi.Api
{
/// <summary>
/// Class for TokenApi endpoint under SolanaApi
/// </summary>

public class TokenApi : ITokenApi;
{

/// <summary>
/// Initializes a new instance of the <see cref="TokenApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
/// <returns></returns>
public TokenApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
{
this.ApiClient = Configuration.DefaultApiClient;
}
else
{
this.ApiClient = apiClient;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="NativeApi"/> class.
/// </summary>
/// <returns></returns>
public TokenApi(String basePath)
{
this.ApiClient = new ApiClient(basePath);
}

/// <summary>
/// Sets the base path of the API client.
/// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value>
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}

/// <summary>
/// Gets the base path of the API client.
/// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value>
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}

/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>An instance of the ApiClient</value>
public ApiClient ApiClient { get; set; }


public async UniTask<TokenPrice> GetTokenPrice(NetworkTypes network, string address)
{
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetTokenPrice");

var headerParams = new Dictionary<String, String>();

var path = "/token/{network}/{address}/price";
path = path.Replace("{" + "network" + "}", ApiClient.ParameterToString(network.ToString()));
path = path.Replace("{" + "address" + "}", ApiClient.ParameterToString(address));

// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };

Tuple<HttpStatusCode, Dictionary<string, string>, string> response = await ApiClient.CallApi(path, Method.GET, null, null, headerParams, null, null, authSettings);

if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling GetTokenPrice: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling GetTokenPrice: " + response.Item3, response.Item3);


return ((CloudFunctionResult<TokenPrice>)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult<TokenPrice>), response.Item2)).Result;
}

}

}
11 changes: 11 additions & 0 deletions Runtime/SolanaApi/Api/TokenApi.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Runtime/SolanaApi/Client/SolanaApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class SolanaApiClient : ISolanaApi
/// DefiApi operations
/// </summary>
public INftApi Nft { get; private set; }

/// <summary>
/// TokenApi operations
/// </summary>
public ITokenApi Token { get; private set; }

/// <summary>
/// Indicates that the client has been initialized.
Expand Down
99 changes: 99 additions & 0 deletions Runtime/SolanaApi/CloudApi/TokenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using System.Net;
using MoralisUnity.SolanaApi.Client;
using MoralisUnity.SolanaApi.Interfaces;
using MoralisUnity.SolanaApi.Models;

namespace MoralisUnity.SolanaApi.CloudApi;
{
/// <summary>
/// Class for TokenApi endpoint under SolanaApi
/// </summary>

public class TokenApi : ITokenApi;
3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved
{

/// <summary>
/// Initializes a new instance of the <see cref="TokenApi"/> class.
/// </summary>
/// <param name="apiClient"> an instance of ApiClient (optional)</param>
/// <returns></returns>
public TokenApi(ApiClient apiClient = null)
{
if (apiClient == null) // use the default one in Configuration
{
this.ApiClient = Configuration.DefaultApiClient;
}
else
{
this.ApiClient = apiClient;
}
}

/// <summary>
/// Initializes a new instance of the <see cref="NativeApi"/> class.
/// </summary>
/// <returns></returns>
public TokenApi(String basePath)
{
this.ApiClient = new ApiClient(basePath);
}

/// <summary>
/// Sets the base path of the API client.
/// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value>
public void SetBasePath(String basePath)
{
this.ApiClient.BasePath = basePath;
}

/// <summary>
/// Gets the base path of the API client.
/// </summary>
/// <param name="basePath">The base path</param>
/// <value>The base path</value>
public String GetBasePath(String basePath)
{
return this.ApiClient.BasePath;
}

/// <summary>
/// Gets or sets the API client.
/// </summary>
/// <value>An instance of the ApiClient</value>
public ApiClient ApiClient { get; set; }


public async UniTask<TokenPrice> GetTokenPrice(NetworkTypes network, string address)
{
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling GetTokenPrice");

var headerParams = new Dictionary<String, String>();

var path = "/functions/sol-getTokenPrice";
postBody.Add("network", ApiClient.ParameterToString(network.ToString()));
if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));

// Authentication setting, if any
String[] authSettings = new String[] { "ApiKeyAuth" };

string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;

Tuple<HttpStatusCode, Dictionary<string, string>, string> response = await ApiClient.CallApi(path, Method.POST, null, bodyData, headerParams, null, null, authSettings);

if (((int)response.Item1) >= 400)
throw new ApiException((int)response.Item1, "Error calling GetTokenPrice: " + response.Item3, response.Item3);
else if (((int)response.Item1) == 0)
throw new ApiException((int)response.Item1, "Error calling GetTokenPrice: " + response.Item3, response.Item3);


return ((CloudFunctionResult<TokenPrice>)ApiClient.Deserialize(response.Item3, typeof(CloudFunctionResult<TokenPrice>), response.Item2)).Result;
}

}

}
11 changes: 11 additions & 0 deletions Runtime/SolanaApi/CloudApi/TokenApi.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Runtime/SolanaApi/Interfaces/ISolanaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ public interface ISolanaApi
IAccountApi Account { get; }

/// <summary>
/// TokenApi operations.
/// NftApi operations.
/// </summary>
INftApi Nft { get; }


3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// TokenApi operations.
/// </summary>
ITokenApi Token { get; }

/// <summary>
/// Indicates that the client has been initialized.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Runtime/SolanaApi/Interfaces/ITokenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Cysharp.Threading.Tasks;
using MoralisUnity.SolanaApi.Models;

namespace MoralisUnity.SolanaApi.Interfaces
{
public interface ITokenApi
{
Unitask<TokenPrice> GetTokenPrice(string address, NetworkTypes network);
}
}
11 changes: 11 additions & 0 deletions Runtime/SolanaApi/Interfaces/ITokenApi.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading