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 2 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 web3uiKit 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`

 

91 changes: 91 additions & 0 deletions Runtime/SolanaApi/Api/TokenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
{
public class TokenApi : ITokenApi;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add descriptive comments to all public classes and methods


{

/// <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;
3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved
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) {
3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved
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;


}

}

}
91 changes: 91 additions & 0 deletions Runtime/SolanaApi/CloudApi/TokenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
{
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;
3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow coding practices in other files - braces should be on a new line.

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;


}

}

}
2 changes: 2 additions & 0 deletions Runtime/SolanaApi/Interfaces/ISolanaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface ISolanaApi
/// TokenApi operations.
/// </summary>
INftApi Nft { get; }

3scava1i3r marked this conversation as resolved.
Show resolved Hide resolved


/// <summary>
/// Indicates that the client has been initialized.
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);
}
}
32 changes: 32 additions & 0 deletions Runtime/SolanaApi/Models/TokenPrice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace DefaultNamespace
{
public class TokenPrice
{
[DataContract]
public class TokenPrice
{

[DataMember(Name = "usdPrice", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "usdPrice")]
public string UsdPrice { get; set; }

[DataMember(Name = "exchangeName", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "exchangeName")]
public string ExchangeName { get; set; }

[DataMember(Name = "exchangeAddress", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "exchangeAddress")]
public string ExchangeAddress { get; set; }

[DataMember(Name = "nativePrice", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "nativePrice")]
public string NativePrice { get; set; }


}

}
}