Skip to content

Commit

Permalink
Merge branch 'master' into feature/milestone-01
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/aoWebWallet/Services/DataService.cs
#	src/aoWebWallet/ViewModels/MainViewModel.cs
  • Loading branch information
michielpost committed May 9, 2024
2 parents 8c9154c + bcbb5d5 commit 8e87799
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 29 deletions.
15 changes: 15 additions & 0 deletions src/aoWebWallet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libs", "Libs", "{06E5BC39-7
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "webvNext.DataLoader", "webvNext.DataLoader\webvNext.DataLoader.csproj", "{17CA4374-64D0-4618-852F-8A76D0A57166}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aoww.Services", "aoww.Services\aoww.Services.csproj", "{178C3213-D574-4B39-A2DA-1FB1D2806242}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{89AC47DF-65AD-4870-AA1D-74ABF1F3D8FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aoww.Services.Tests", "aoww.Services.Tests\aoww.Services.Tests.csproj", "{322F4807-05CF-431D-B400-7420E1B29936}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,12 +29,21 @@ Global
{17CA4374-64D0-4618-852F-8A76D0A57166}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17CA4374-64D0-4618-852F-8A76D0A57166}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17CA4374-64D0-4618-852F-8A76D0A57166}.Release|Any CPU.Build.0 = Release|Any CPU
{178C3213-D574-4B39-A2DA-1FB1D2806242}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{178C3213-D574-4B39-A2DA-1FB1D2806242}.Debug|Any CPU.Build.0 = Debug|Any CPU
{178C3213-D574-4B39-A2DA-1FB1D2806242}.Release|Any CPU.ActiveCfg = Release|Any CPU
{178C3213-D574-4B39-A2DA-1FB1D2806242}.Release|Any CPU.Build.0 = Release|Any CPU
{322F4807-05CF-431D-B400-7420E1B29936}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{322F4807-05CF-431D-B400-7420E1B29936}.Debug|Any CPU.Build.0 = Debug|Any CPU
{322F4807-05CF-431D-B400-7420E1B29936}.Release|Any CPU.ActiveCfg = Release|Any CPU
{322F4807-05CF-431D-B400-7420E1B29936}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{17CA4374-64D0-4618-852F-8A76D0A57166} = {06E5BC39-764A-48B9-B4F9-F48387A2C965}
{322F4807-05CF-431D-B400-7420E1B29936} = {89AC47DF-65AD-4870-AA1D-74ABF1F3D8FE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {432E3F8E-53FF-4D9C-869D-48449BD3B8B4}
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Width="100" Class="pt-2" Alt="AOWW"/>
</MudLink>
<MudSpacer />
<MudIconButton title="menu" Icon="@Icons.Material.Filled.Workspaces" Color="MudBlazor.Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudIconButton title="menu" Icon="@Icons.Material.Filled.Workspaces" Color="MudBlazor.Color.Inherit" Edge="MudBlazor.Edge.Start" OnClick="@((e) => DrawerToggle())" />
@*<MudText Typo="Typo.h5" Class="ml-3">aoWebWallet</MudText>*@
@*<MudIconButton Icon="@Icons.Material.Filled.MoreVert" Color="Color.Inherit" Edge="Edge.End" />*@
@* <ApiConnectionDisplay />*@
Expand Down
1 change: 1 addition & 0 deletions src/aoWebWallet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ArweaveBlazor;
using System.Globalization;
using ClipLazor.Extention;
using aoww.Services;

namespace aoWebWallet
{
Expand Down
11 changes: 10 additions & 1 deletion src/aoWebWallet/Shared/Components/TransactionComponent.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using aoWebWallet.Models

@inherits MvvmComponentBase<MainViewModel>
@inject TokenDataService dataService

Expand Down Expand Up @@ -47,7 +48,15 @@
else if(isReceive)
{
<MudText Typo="Typo.h6" style="color:green">+ @BalanceHelper.FormatBalance(transfer.Quantity, tokenData?.Denomination ?? 0)</MudText>
<MudIcon Icon="@Icons.Material.Filled.South" aria-label="Receive"></MudIcon>

@if(transfer.TokenTransferType == aoww.Services.Enums.TokenTransferType.Mint)
{
<MudText Typo="Typo.h6" style="color:green">MINT</MudText>
}
else
{
<MudIcon Icon="@Icons.Material.Filled.South" aria-label="Receive"></MudIcon>
}
<MudLink Class="KodeMono tx-wrap" Href="@detailUrlFrom" Typo="Typo.h6">
@transfer.From
</MudLink>
Expand Down
2 changes: 2 additions & 0 deletions src/aoWebWallet/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using aoWebWallet.Models;
using aoWebWallet.Pages;
using aoWebWallet.Services;
using aoww.Services;
using aoww.Services.Models;
using ArweaveAO;
using ArweaveAO.Models.Token;
using ArweaveBlazor;
Expand Down
2 changes: 2 additions & 0 deletions src/aoWebWallet/ViewModels/TokenDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using aoWebWallet.Models;
using aoWebWallet.Services;
using aoww.Services;
using aoww.Services.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using webvNext.DataLoader;
using static MudBlazor.Colors;
Expand Down
2 changes: 2 additions & 0 deletions src/aoWebWallet/ViewModels/TransactionDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using aoWebWallet.Models;
using aoWebWallet.Services;
using aoww.Services;
using aoww.Services.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using webvNext.DataLoader;

Expand Down
2 changes: 2 additions & 0 deletions src/aoWebWallet/ViewModels/WalletDetailViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using aoWebWallet.Models;
using aoWebWallet.Services;
using aoww.Services;
using aoww.Services.Models;
using ArweaveAO;
using ArweaveBlazor;
using CommunityToolkit.Mvvm.ComponentModel;
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/ViewModels/WalletProcessDataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using aoWebWallet.Models;
using aoww.Services.Models;
using ArweaveAO.Models.Token;

namespace aoWebWallet.ViewModels
Expand Down
3 changes: 2 additions & 1 deletion src/aoWebWallet/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
@using webvNext.DataLoader
@using ArweaveAO
@using ArweaveBlazor
@using aoWebWallet.Extensions
@using aoWebWallet.Extensions
@using aoww.Services.Models
1 change: 1 addition & 0 deletions src/aoWebWallet/aoWebWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\aoww.Services\aoww.Services.csproj" />
<ProjectReference Include="..\webvNext.DataLoader\webvNext.DataLoader.csproj" />
</ItemGroup>

Expand Down
26 changes: 26 additions & 0 deletions src/aoww.Services.Tests/GraphqlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace aoww.Services.Tests
{
[TestClass]
public class GraphqlTests
{
[TestMethod]
public async Task GetTransactionsTest()
{
var graph = new GraphqlClient(new HttpClient());

var result = await graph.GetTransactionsIn("4NdFkWsgFQIEmJnzFSYrO88UmRPf0ABfVh_fRc2u130");

Assert.IsNotNull(result);
}

[TestMethod]
public async Task GetMintTest()
{
var graph = new GraphqlClient(new HttpClient());

var result = await graph.GetTransactionsIn("CeiYr2VjUVAFXmPJvfj-Pfk6zmprBzeqNeRWAbImbOo");

Assert.IsNotNull(result);
}
}
}
27 changes: 27 additions & 0 deletions src/aoww.Services.Tests/aoww.Services.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\aoww.Services\aoww.Services.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/aoww.Services/Enums/TokenTransferType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aoww.Services.Enums
{
public enum TokenTransferType
{
Transfer,
Mint
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using aoWebWallet.Models;
using ArweaveAO.Models.Token;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using aoww.Services.Models;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using static System.Net.WebRequestMethods;

namespace aoWebWallet.Services
namespace aoww.Services
{
/// <summary>
/// https://arweave.net/graphql
/// </summary>
public class GraphqlClient
{
private readonly HttpClient httpClient;
Expand All @@ -22,7 +17,38 @@ public GraphqlClient(HttpClient httpClient)

public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string? fromTxId = null)
{
string query = "query {\r\n transactions(\r\n first: 100\r\n sort: HEIGHT_DESC\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n { name: \"Recipient\", values: [\"" + adddress + "\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
string query = $$"""
query {
transactions(
first: 100
sort: HEIGHT_DESC
tags: [
{ name: "Data-Protocol", values: ["ao"] }
{ name: "Action", values: ["Transfer", "Mint-Token"] }
{ name: "Recipient", values: ["{{adddress}}"] }
]
) {
edges {
node {
id
recipient
owner {
address
}
block {
timestamp
height
}
tags {
name
value
}
}
}
}
}
""";
var queryResult = await PostQueryAsync(query);
var result = new List<TokenTransfer>();
Expand All @@ -31,7 +57,7 @@ public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string
{
TokenTransfer? transaction = GetTransaction(edge);
if(transaction != null)
if (transaction != null)
result.Add(transaction);
}
Expand All @@ -44,15 +70,21 @@ public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string
return null;
var isTransfer = edge.Node.Tags.Where(x => x.Name == "Action" && x.Value == "Transfer").Any();
if (!isTransfer)
var isMint = edge.Node.Tags.Where(x => x.Name == "Action" && x.Value == "Mint-Token").Any();
if (!isTransfer && !isMint)
return null;

var transaction = new TokenTransfer()
{
Id = edge.Node.Id,
From = edge.Node.Owner?.Address ?? string.Empty
From = edge.Node.Owner?.Address ?? string.Empty,
TokenTransferType = Enums.TokenTransferType.Transfer
};

if (isMint)
transaction.TokenTransferType = Enums.TokenTransferType.Mint;


if (edge.Node.Block != null)
{
transaction.Timestamp = DateTimeOffset.FromUnixTimeSeconds(edge.Node.Block.Timestamp);
Expand All @@ -65,9 +97,13 @@ public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string
if (!string.IsNullOrEmpty(fromProcess))
transaction.From = fromProcess;

transaction.TokenId = edge.Node.Recipient;
if (isMint)
transaction.TokenId = edge.Node.Tags.Where(x => x.Name == "TokenId").Select(x => x.Value).FirstOrDefault();
else
transaction.TokenId = edge.Node.Recipient;

transaction.To = edge.Node.Tags.Where(x => x.Name == "Recipient").Select(x => x.Value).FirstOrDefault();

string? quantity = edge.Node.Tags.Where(x => x.Name == "Quantity").Select(x => x.Value).FirstOrDefault();
if (!string.IsNullOrWhiteSpace(quantity) && long.TryParse(quantity, out long quantityLong))
transaction.Quantity = quantityLong;
Expand Down Expand Up @@ -374,7 +410,7 @@ public async Task<List<AoProcessInfo>> GetAoProcessesForAddress(string address)

protected async Task<GraphqlResponse?> PostQueryAsync(string query)
{
var request = new GraphqlRequest { Query = query};
var request = new GraphqlRequest { Query = query };

HttpResponseMessage res = await httpClient.PostAsJsonAsync("https://arweave.net/graphql", request);
if (res.IsSuccessStatusCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace aoWebWallet.Models
namespace aoww.Services.Models
{
public class AoProcessInfo
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace aoWebWallet.Models
namespace aoww.Services.Models
{
public class GraphqlRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using ArweaveAO.Models;
using MudBlazor;
using System.Text.Json.Serialization;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Text.Json.Serialization;

namespace aoWebWallet.Models
namespace aoww.Services.Models
{
public class GraphqlResponse
{
Expand Down
15 changes: 15 additions & 0 deletions src/aoww.Services/Models/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Diagnostics;
using System.Text.Json.Serialization;

namespace aoww.Services.Models
{
[DebuggerDisplay("{Name}: {Value}")]
public class Tag
{
[JsonPropertyName("name")]
public required string Name { get; set; }

[JsonPropertyName("value")]
public required string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using aoww.Services.Enums;

namespace aoWebWallet.Models
namespace aoww.Services.Models
{
public class TokenTransfer
{
Expand All @@ -15,5 +16,7 @@ public class TokenTransfer
public required string From { get; set; }
public string? To { get; set; }
public long Quantity { get; set; }

public TokenTransferType TokenTransferType { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/aoww.Services/aoww.Services.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

0 comments on commit 8e87799

Please sign in to comment.