Skip to content

Commit 1a00e8d

Browse files
authored
Merge branch 'main' into firekeeper/7702-wallet
2 parents 31c0119 + 29601c8 commit 1a00e8d

File tree

11 files changed

+142
-47
lines changed

11 files changed

+142
-47
lines changed

.github/workflows/docfx.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ permissions:
1313
concurrency:
1414
group: "pages"
1515
cancel-in-progress: false
16-
16+
1717
jobs:
1818
publish-docs:
1919
environment:
2020
name: github-pages
2121
url: ${{ steps.deployment.outputs.page_url }}
2222
runs-on: ubuntu-latest
2323
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v4
26-
- name: Dotnet Setup
27-
uses: actions/setup-dotnet@v3
28-
with:
29-
dotnet-version: 8.x
24+
- name: Checkout
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
- name: Dotnet Setup
27+
uses: actions/setup-dotnet@b2ace4b12f4cec1b96b6361ff2694ba9e931ceb4 # v3.3.1
28+
with:
29+
dotnet-version: 8.x
3030

31-
- run: dotnet tool update -g docfx
32-
- run: docfx docfx.json
31+
- run: dotnet tool update -g docfx
32+
- run: docfx docfx.json
3333

34-
- name: Upload artifact
35-
uses: actions/upload-pages-artifact@v3
36-
with:
37-
path: '_site'
38-
- name: Deploy to GitHub Pages
39-
id: deployment
40-
uses: actions/deploy-pages@v4
34+
- name: Upload artifact
35+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
36+
with:
37+
path: "_site"
38+
- name: Deploy to GitHub Pages
39+
id: deployment
40+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

.github/workflows/dotnet-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919

2020
- name: Setup
21-
uses: actions/setup-dotnet@v3
21+
uses: actions/setup-dotnet@b2ace4b12f4cec1b96b6361ff2694ba9e931ceb4 # v3.3.1
2222
with:
2323
dotnet-version: |
2424
8.0.x
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Codecov
4747
if: always() && steps.test.outcome != 'cancelled'
48-
uses: codecov/codecov-action@v4
48+
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
4949
with:
5050
token: ${{ secrets.CODECOV_TOKEN }}
5151
directory: ./

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v4
14+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1515

1616
- name: Setup .NET
17-
uses: actions/setup-dotnet@v3
17+
uses: actions/setup-dotnet@b2ace4b12f4cec1b96b6361ff2694ba9e931ceb4 # v3.3.1
1818
with:
1919
dotnet-version: "8.0.x"
2020

@@ -30,7 +30,7 @@ jobs:
3030
run: dotnet nuget push "./Thirdweb/bin/Release/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
3131

3232
- name: Upload build artifacts
33-
uses: actions/upload-artifact@v4
33+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
3434
with:
3535
name: build-artifacts
3636
path: |

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<DefaultVersion>2.18.4</DefaultVersion>
4+
<DefaultVersion>2.18.5</DefaultVersion>
55
<DefaultTargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</DefaultTargetFrameworks>
66
</PropertyGroup>
77

Thirdweb.Console/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
// // Create a ThirdwebInsight instance
4747
// var insight = await ThirdwebInsight.Create(client);
4848

49+
// var ethPriceToday = await insight.GetTokenPrice(addressOrSymbol: "ETH", chainId: 1);
50+
// Console.WriteLine($"ETH price today: {ethPriceToday.PriceUsd}");
51+
52+
// var ethPriceYesterday = await insight.GetTokenPrice(addressOrSymbol: "ETH", chainId: 1, timestamp: Utils.GetUnixTimeStampNow() - 86400);
53+
// Console.WriteLine($"ETH price yesterday: {ethPriceYesterday.PriceUsd}");
54+
55+
// var multiTokenPrices = await insight.GetTokenPrices(addressOrSymbols: new[] { "POL", "APE" }, chainIds: new BigInteger[] { 137, 33139 });
56+
// Console.WriteLine($"Multi token prices: {JsonConvert.SerializeObject(multiTokenPrices, Formatting.Indented)}");
57+
4958
// // Setup some filters
5059
// var address = await Utils.GetAddressFromENS(client, "vitalik.eth");
5160
// var chains = new BigInteger[] { 1, 137, 42161 };

Thirdweb.Tests/Thirdweb.RPC/Thirdweb.RPC.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public async Task TestAuth()
107107
var client = ThirdwebClient.Create(clientId: "hi", fetchTimeoutOptions: new TimeoutOptions(rpc: 60000));
108108
var rpc = ThirdwebRPC.GetRpcInstance(client, 1);
109109
var ex = await Assert.ThrowsAsync<HttpRequestException>(async () => await rpc.SendRequestAsync<string>("eth_blockNumber"));
110-
Assert.Contains("Unauthorized", ex.Message);
110+
Assert.Contains("401", ex.Message);
111111
}
112112

113113
[Fact(Timeout = 120000)]

Thirdweb/Thirdweb.Extensions/ThirdwebExtensions.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,40 +1227,46 @@ public static async Task<NFT> ERC721_GetNFT(this ThirdwebContract contract, BigI
12271227
throw new ArgumentNullException(nameof(contract));
12281228
}
12291229

1230-
var uri = await contract.ERC721_TokenURI(tokenId).ConfigureAwait(false);
1231-
NFTMetadata metadata;
1232-
try
1233-
{
1234-
metadata = await ThirdwebStorage.Download<NFTMetadata>(contract.Client, uri).ConfigureAwait(false);
1235-
}
1236-
catch (Exception e)
1230+
var nft = new NFT
12371231
{
1238-
#pragma warning disable IDE0059 // Unnecessary assignment of a value
1239-
metadata = new NFTMetadata { Description = e.Message };
1240-
#pragma warning restore IDE0059 // Unnecessary assignment of a value
1241-
}
1242-
metadata.Id = tokenId.ToString();
1232+
Owner = Constants.ADDRESS_ZERO,
1233+
Type = NFTType.ERC721,
1234+
Supply = 1,
1235+
QuantityOwned = 1
1236+
};
12431237

1244-
var owner = Constants.ADDRESS_ZERO;
12451238
if (fillOwner)
12461239
{
12471240
try
12481241
{
1249-
owner = await contract.ERC721_OwnerOf(tokenId).ConfigureAwait(false);
1242+
nft.Owner = await contract.ERC721_OwnerOf(tokenId).ConfigureAwait(false);
12501243
}
1251-
catch (Exception)
1244+
catch
12521245
{
1253-
owner = Constants.ADDRESS_ZERO;
1246+
nft.Owner = Constants.ADDRESS_ZERO;
12541247
}
12551248
}
12561249

1257-
return new NFT
1250+
#pragma warning disable IDE0059 // Unnecessary assignment of a value
1251+
var nftMetadata = new NFTMetadata();
1252+
#pragma warning restore IDE0059 // Unnecessary assignment of a value
1253+
try
12581254
{
1259-
Metadata = metadata,
1260-
Owner = owner,
1261-
Type = NFTType.ERC721,
1262-
Supply = 1,
1263-
QuantityOwned = 1
1255+
var uri = await contract.ERC721_TokenURI(tokenId).ConfigureAwait(false);
1256+
nftMetadata = await ThirdwebStorage.Download<NFTMetadata>(contract.Client, uri).ConfigureAwait(false);
1257+
}
1258+
catch (Exception e)
1259+
{
1260+
nftMetadata.Description = $"Metadata not found: {e.Message}";
1261+
}
1262+
finally
1263+
{
1264+
nftMetadata.Id = tokenId.ToString();
1265+
}
1266+
1267+
return nft with
1268+
{
1269+
Metadata = nftMetadata
12641270
};
12651271
}
12661272

Thirdweb/Thirdweb.Indexer/ThirdwebInsight.Types.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ public class Meta
4747
public BigInteger TotalPages { get; set; }
4848
}
4949

50+
#region Price API
51+
52+
public class Token_Price
53+
{
54+
[JsonProperty("chain_id")]
55+
public BigInteger ChainId { get; set; }
56+
57+
[JsonProperty("address")]
58+
public string Address { get; set; }
59+
60+
[JsonProperty("symbol")]
61+
public string Symbol { get; set; }
62+
63+
[JsonProperty("price_usd")]
64+
public double PriceUsd { get; set; }
65+
66+
[JsonProperty("price_usd_cents")]
67+
public double PriceUsdCents { get; set; }
68+
69+
public override string ToString()
70+
{
71+
return JsonConvert.SerializeObject(this);
72+
}
73+
}
74+
75+
#endregion
76+
5077
#region Tokens API
5178

5279
public class Token_ERC20 : Token { }

Thirdweb/Thirdweb.Indexer/ThirdwebInsight.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@ public static Task<ThirdwebInsight> Create(ThirdwebClient client)
4747
return Task.FromResult(new ThirdwebInsight(client));
4848
}
4949

50+
public async Task<Token_Price> GetTokenPrice(string addressOrSymbol, BigInteger chainId, long? timestamp = null)
51+
{
52+
var prices = await this.GetTokenPrices(new[] { addressOrSymbol }, new[] { chainId }, timestamp).ConfigureAwait(false);
53+
if (prices.Length == 0)
54+
{
55+
throw new Exception("Token price not found.");
56+
}
57+
return prices[0];
58+
}
59+
60+
public async Task<Token_Price[]> GetTokenPrices(string[] addressOrSymbols, BigInteger[] chainIds, long? timestamp = null)
61+
{
62+
var addresses = addressOrSymbols.Where(Utils.IsValidAddress).ToArray();
63+
var symbols = addressOrSymbols.Except(addresses).ToArray();
64+
65+
var url = AppendChains($"{Constants.INSIGHT_API_URL}/v1/tokens/price", chainIds);
66+
67+
if (addresses.Length > 0)
68+
{
69+
url += $"&address={string.Join("&address=", addresses)}";
70+
}
71+
72+
if (symbols.Length > 0)
73+
{
74+
url += $"&symbol={string.Join("&symbol=", symbols)}";
75+
}
76+
77+
if (timestamp.HasValue)
78+
{
79+
url += $"&timestamp={timestamp}";
80+
}
81+
82+
var response = await this._httpClient.GetAsync(url).ConfigureAwait(false);
83+
_ = response.EnsureSuccessStatusCode();
84+
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
85+
return JsonConvert.DeserializeObject<ResponseModel<Token_Price>>(responseContent).Data;
86+
}
87+
5088
/// <summary>
5189
/// Get the token balances of an address.
5290
/// </summary>

Thirdweb/Thirdweb.Utils/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public static class Constants
44
{
5-
public const string VERSION = "2.18.4";
5+
public const string VERSION = "2.18.5";
66

77
public const string IERC20_INTERFACE_ID = "0x36372b07";
88
public const string IERC721_INTERFACE_ID = "0x80ac58cd";

0 commit comments

Comments
 (0)