Skip to content

Commit

Permalink
Upcoming history endpoint, simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper committed Apr 20, 2024
1 parent cf2786d commit 89fcfd8
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 163 deletions.
7 changes: 4 additions & 3 deletions Assets/Thirdweb/Core/Scripts/Pay/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ public static class Constants
{
public const string THIRDWEB_PAY_BASE_URL = "https://pay.thirdweb-dev.com";

public const string THIRDWEB_PAY_QUOTE_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-crypto/quote/v1";
public const string THIRDWEB_PAY_STATUS_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-crypto/status/v1";
public const string THIRDWEB_PAY_HISTORY_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-crypto/history/v1";
public const string THIRDWEB_PAY_CRYPTO_QUOTE_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-crypto/quote/v1";
public const string THIRDWEB_PAY_CRYPTO_STATUS_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-crypto/status/v1";

public const string THIRDWEB_PAY_FIAT_QUOTE_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-fiat/quote/v1";
public const string THIRDWEB_PAY_FIAT_STATUS_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-fiat/status/v1";

public const string THIRDWEB_PAY_FIAT_CURRENCIES_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/buy-with-fiat/currency/v1";

public const string THIRDWEB_PAY_HISTORY_ENDPOINT = THIRDWEB_PAY_BASE_URL + "/wallet/history/v1";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static partial class ThirdwebPay
/// <param name="count">Number of records to retrieve</param>
/// <param name="cursor">Cursor for paging through the history</param>
/// <param name="pageSize">Swap statuses to query for</param>
/// <returns>Swap history object <see cref="BuyWithCryptoHistoryResult"/></returns>
/// <returns>Swap history object <see cref="BuyHistoryResult"/></returns>
/// <exception cref="Exception"></exception>
public static async Task<BuyWithCryptoHistoryResult> GetBuyWithCryptoHistory(string walletAddress, int start, int count, string cursor = null, int? pageSize = null)
public static async Task<BuyHistoryResult> GetBuyHistory(string walletAddress, int start, int count, string cursor = null, int? pageSize = null)
{
if (string.IsNullOrEmpty(Utils.GetClientId()))
{
Expand Down Expand Up @@ -83,7 +83,8 @@ public static async Task<BuyWithCryptoHistoryResult> GetBuyWithCryptoHistory(str
}

var content = request.downloadHandler.text;
var data = JsonConvert.DeserializeObject<SwapHistoryResponse>(content);
ThirdwebDebug.Log($"GetBuyHistory response: {content}");
var data = JsonConvert.DeserializeObject<BuyHistoryResponse>(content);
return data.Result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static async Task<BuyWithCryptoQuoteResult> GetBuyWithCryptoQuote(BuyWith
};

var queryStringFormatted = string.Join("&", queryString.Where(kv => kv.Value != null).Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}"));
var url = $"{Constants.THIRDWEB_PAY_QUOTE_ENDPOINT}?{queryStringFormatted}";
var url = $"{Constants.THIRDWEB_PAY_CRYPTO_QUOTE_ENDPOINT}?{queryStringFormatted}";

using var request = UnityWebRequest.Get(url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static async Task<BuyWithCryptoStatusResult> GetBuyWithCryptoStatus(strin
var queryString = new Dictionary<string, string> { { "transactionHash", transactionHash } };

var queryStringFormatted = string.Join("&", queryString.Where(kv => kv.Value != null).Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}"));
var url = $"{Constants.THIRDWEB_PAY_STATUS_ENDPOINT}?{queryStringFormatted}";
var url = $"{Constants.THIRDWEB_PAY_CRYPTO_STATUS_ENDPOINT}?{queryStringFormatted}";

using var request = UnityWebRequest.Get(url);

Expand Down
40 changes: 40 additions & 0 deletions Assets/Thirdweb/Core/Scripts/Pay/Types.GetBuyHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Numerics;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Thirdweb.Pay
{
public class BuyHistoryResponse
{
[JsonProperty("result")]
public BuyHistoryResult Result { get; set; }
}

public class BuyHistoryResult
{
[JsonProperty("walletAddress")]
public string WalletAddress { get; set; }

[JsonProperty("page")]
public List<HistoryPage> Page { get; set; }

[JsonProperty("nextCursor")]
public string NextCursor { get; set; }

[JsonProperty("pageSize")]
public int PageSize { get; set; }
}

public class HistoryPage
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("buyWithCryptoStatus")]
public BuyWithCryptoStatusResult BuyWithCryptoStatus;

[JsonProperty("buyWithFiatStatus")]
public BuyWithFiatStatusResult BuyWithFiatStatus;
}
}
118 changes: 0 additions & 118 deletions Assets/Thirdweb/Core/Scripts/Pay/Types.GetBuyWithCryptoHistory.cs

This file was deleted.

58 changes: 26 additions & 32 deletions Assets/Thirdweb/Core/Scripts/Pay/Types.GetBuyWithCryptoStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SwapStatusResponse
public class BuyWithCryptoStatusResult
{
[JsonProperty("quote")]
public Quote Quote { get; set; }
public SwapQuote Quote { get; set; }

[JsonProperty("swapType")]
public string SwapType { get; set; }
Expand Down Expand Up @@ -42,7 +42,31 @@ public class BuyWithCryptoStatusResult
public string Bridge { get; set; }
}

public class Quote
public class TransactionDetails
{
[JsonProperty("transactionHash")]
public string TransactionHash { get; set; }

[JsonProperty("token")]
public Token Token { get; set; }

[JsonProperty("amount")]
public string Amount { get; set; }

[JsonProperty("amountWei")]
public string AmountWei { get; set; }

[JsonProperty("amountUSDCents")]
public double AmountUSDCents { get; set; }

[JsonProperty("completedAt")]
public DateTime CompletedAt { get; set; }

[JsonProperty("explorerLink")]
public string ExplorerLink { get; set; }
}

public class SwapQuote
{
[JsonProperty("fromToken")]
public Token FromToken { get; set; }
Expand Down Expand Up @@ -75,30 +99,6 @@ public class Quote
public DateTime CreatedAt { get; set; }
}

public class TransactionDetails
{
[JsonProperty("transactionHash")]
public string TransactionHash { get; set; }

[JsonProperty("token")]
public Token Token { get; set; }

[JsonProperty("amount")]
public string Amount { get; set; }

[JsonProperty("amountWei")]
public string AmountWei { get; set; }

[JsonProperty("amountUSDCents")]
public double AmountUSDCents { get; set; }

[JsonProperty("completedAt")]
public DateTime CompletedAt { get; set; }

[JsonProperty("explorerLink")]
public string ExplorerLink { get; set; }
}

public enum SwapStatus
{
NOT_FOUND,
Expand All @@ -117,10 +117,4 @@ public enum SwapSubStatus
PARTIAL_SUCCESS,
UNKNOWN_ERROR
}

public enum SwapType
{
SAME_CHAIN,
CROSS_CHAIN
}
}
39 changes: 39 additions & 0 deletions Assets/Thirdweb/Core/Scripts/Pay/Types.GetBuyWithFiatStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,49 @@ public class BuyWithFiatStatusResult
[JsonProperty("status")]
public string Status { get; set; }

[JsonProperty("swapType")]
public string SwapType { get; set; }

[JsonProperty("toAddress")]
public string ToAddress { get; set; }

[JsonProperty("quote")]
public OnRampQuote Quote { get; set; }

[JsonProperty("source")]
public TransactionDetails Source { get; set; }

[JsonProperty("failureMessage")]
public string FailureMessage { get; set; }
}

public class OnRampQuote
{
[JsonProperty("createdAt")]
public string CreatedAt { get; set; }

[JsonProperty("estimatedOnRampAmountWei")]
public string EstimatedOnRampAmountWei { get; set; }

[JsonProperty("estimatedOnRampAmount")]
public string EstimatedOnRampAmount { get; set; }

[JsonProperty("estimatedToTokenAmount")]
public string EstimatedToTokenAmount { get; set; }

[JsonProperty("estimatedToTokenAmountWei")]
public string EstimatedToTokenAmountWei { get; set; }

[JsonProperty("fromCurrency")]
public string FromCurrency { get; set; }

[JsonProperty("onRampToken")]
public string OnRampToken { get; set; }

[JsonProperty("toToken")]
public string ToToken { get; set; }
}

public enum OnRampStatus
{
NONE,
Expand Down
7 changes: 7 additions & 0 deletions Assets/Thirdweb/Core/Scripts/Pay/Types.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ public class Estimated
[JsonProperty("durationSeconds")]
public int DurationSeconds { get; set; }
}

public enum SwapType
{
SAME_CHAIN,
CROSS_CHAIN,
ON_RAMP
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ MonoBehaviour:
m_Calls:
- m_Target: {fileID: 7598338171854559029}
m_TargetAssemblyTypeName: Prefab_BuyWithCrypto, Thirdweb.Examples
m_MethodName: GetSwapHistory
m_MethodName: GetBuyHistory
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
Expand Down
14 changes: 13 additions & 1 deletion Assets/Thirdweb/Examples/Prefabs/Prefab_BuyWithFiat.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 4364387796337202564}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 2613041843977987998}
m_TargetAssemblyTypeName: Prefab_BuyWithFiat, Thirdweb.Examples
m_MethodName: GetBuyHistory
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &399040240725856124
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit 89fcfd8

Please sign in to comment.