Skip to content

Commit

Permalink
Corrected the display of transactions; added support for TX merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojatekok committed Jun 3, 2014
1 parent 806910f commit cf31291
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 27 deletions.
20 changes: 19 additions & 1 deletion MoneroApi.Net/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
using System.Globalization;
using System.Collections.ObjectModel;
using System.Globalization;

namespace Jojatekok.MoneroAPI
{
static class Helper
{
public static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture;

public static void AddOrMergeTransaction(this ObservableCollection<Transaction> collection, Transaction item)
{
for (var i = collection.Count - 1; i >= 0; i--) {
var currentItem = collection[i];

if (currentItem.TransactionId == item.TransactionId && currentItem.IsAmountSpendable == item.IsAmountSpendable) {
// TODO: Determine whether checking for the transaction's type is worthless
if (currentItem.Type == item.Type) {
currentItem.Amount += item.Amount;
return;
}
}
}

collection.Add(item);
}
}
}
6 changes: 4 additions & 2 deletions MoneroApi.Net/Objects/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
public class Transaction
{
public TransactionType Type { get; private set; }
public double Amount { get; private set; }
public bool IsAmountSpendable { get; private set; }
public double Amount { get; internal set; }
public string TransactionId { get; private set; }

public Transaction(TransactionType type, double amount, string transactionId)
public Transaction(TransactionType type, bool isAmountSpendable, double amount, string transactionId)
{
Type = type;
IsAmountSpendable = isAmountSpendable;
Amount = amount;
TransactionId = transactionId;
}
Expand Down
5 changes: 3 additions & 2 deletions MoneroApi.Net/Objects/TransactionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
public enum TransactionType
{
Receive = 0,
Send = 1
Unknown = 0,
Receive = 1,
Send = 2
}
}
12 changes: 9 additions & 3 deletions MoneroApi.Net/ProcessManagers/WalletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ private void Process_OutputReceived(object sender, string e)
var transactionId = match.Groups[2].Value;
var type = match.Groups[3].Value == "received" ? TransactionType.Receive : TransactionType.Send;
var amount = double.Parse(match.Groups[4].Value, Helper.InvariantCulture);
var isAmountSpendable = type == TransactionType.Receive;

TransactionsPrivate.Add(new Transaction(type, amount, transactionId));
TransactionsPrivate.AddOrMergeTransaction(new Transaction(type, isAmountSpendable, amount, transactionId));

if (type == TransactionType.Send) {
// TODO: Refresh funds' availability
}

return;
}
Expand All @@ -152,10 +157,11 @@ private void Process_OutputReceived(object sender, string e)
var newTransactionMatch = Regex.Match(data, "([0-9]+\\.[0-9]+)[\\s]+([tf])[\\s]+[0-9]+[\\s]+<([0-9a-z]+)>");
if (newTransactionMatch.Success) {
var amount = double.Parse(newTransactionMatch.Groups[1].Value, Helper.InvariantCulture);
var type = newTransactionMatch.Groups[2].Value == "t" ? TransactionType.Send : TransactionType.Receive;
var isAmountSpendable = newTransactionMatch.Groups[2].Value == "t";
var transactionId = newTransactionMatch.Groups[3].Value;

TransactionsPrivate.Add(new Transaction(type, amount, transactionId));
// TODO: Fetch the transaction's type if possible
TransactionsPrivate.AddOrMergeTransaction(new Transaction(TransactionType.Unknown, isAmountSpendable, amount, transactionId));

return;
}
Expand Down
4 changes: 2 additions & 2 deletions MoneroApi.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("0.10.0")]
[assembly: AssemblyFileVersion("0.10.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]
17 changes: 17 additions & 0 deletions MoneroGui/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<Application x:Class="Jojatekok.MoneroGUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:Jojatekok.MoneroGUI.Properties"
xmlns:main="clr-namespace:Jojatekok.MoneroGUI"
StartupUri="Windows\MainWindow.xaml">
<Application.Resources>
<main:ConverterBooleanToString x:Key="ConverterBooleanToStringYesNo" FalseValue="{x:Static p:Resources.TextNo}" TrueValue="{x:Static p:Resources.TextYes}"/>
<main:ConverterTransactionTypeToString x:Key="ConverterTransactionTypeToString" UnknownValue="{x:Static p:Resources.TransactionTypeUnknown}" ReceiveValue="{x:Static p:Resources.TransactionTypeReceive}" SendValue="{x:Static p:Resources.TransactionTypeSend}"/>

<Style x:Key="StyleSeparatorVertical" TargetType="{x:Type Separator}" BasedOn="{StaticResource {x:Type Separator}}">
<Setter Property="LayoutTransform">
<Setter.Value>
Expand All @@ -20,6 +25,14 @@
<Setter Property="Margin" Value="0 2"/>
</Style>

<Style x:Key="StyleTextBlockAlignedCenter" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="TextAlignment" Value="Center"/>
</Style>

<Style x:Key="StyleTextBlockAlignedRight" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="TextAlignment" Value="Right"/>
</Style>

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Padding" Value="5 0"/>
</Style>
Expand All @@ -29,6 +42,10 @@
<Setter Property="HorizontalGridLinesBrush" Value="#26000000"/>
</Style>

<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>

<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderThickness" Value="0"/>
Expand Down
2 changes: 2 additions & 0 deletions MoneroGui/MoneroGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="Objects\ConverterTransactionTypeToString.cs" />
<Compile Include="Objects\ConverterBooleanToString.cs" />
<Compile Include="Objects\Helper.cs" />
<Compile Include="Objects\Logger.cs" />
<Compile Include="Properties\Resources.hu-HU.Designer.cs">
Expand Down
23 changes: 23 additions & 0 deletions MoneroGui/Objects/ConverterBooleanToString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace Jojatekok.MoneroGUI
{
public class ConverterBooleanToString : IValueConverter
{
public string FalseValue { get; set; }
public string TrueValue { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return FalseValue;
return (bool)value ? TrueValue : FalseValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null && value.Equals(TrueValue);
}
}
}
39 changes: 39 additions & 0 deletions MoneroGui/Objects/ConverterTransactionTypeToString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Jojatekok.MoneroAPI;
using System;
using System.Globalization;
using System.Windows.Data;

namespace Jojatekok.MoneroGUI
{
public class ConverterTransactionTypeToString : IValueConverter
{
public string UnknownValue { get; set; }
public string ReceiveValue { get; set; }
public string SendValue { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return UnknownValue;

switch ((TransactionType)value) {
case TransactionType.Receive:
return ReceiveValue;

case TransactionType.Send:
return SendValue;

default:
return UnknownValue;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var valueString = value as string;

if (valueString == ReceiveValue) return TransactionType.Receive;
if (valueString == SendValue) return TransactionType.Send;
return TransactionType.Unknown;
}
}
}
4 changes: 2 additions & 2 deletions MoneroGui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.12.0")]
[assembly: AssemblyFileVersion("0.12.0")]
[assembly: AssemblyVersion("0.13.0")]
[assembly: AssemblyFileVersion("0.13.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]
[assembly: GuidAttribute("1ed6dec2-f23e-4880-aaa4-4b2b6ce74def")]
56 changes: 55 additions & 1 deletion MoneroGui/Properties/Resources.Designer.cs

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

24 changes: 21 additions & 3 deletions MoneroGui/Properties/Resources.hu-HU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DataCurrencyCode" xml:space="preserve">
<value>MRO</value>
</data>
<data name="DebugConsoleClear" xml:space="preserve">
<value>Ürítés</value>
</data>
Expand Down Expand Up @@ -258,4 +255,25 @@
<data name="TransactionsType" xml:space="preserve">
<value>Típus</value>
</data>
<data name="TransactionsSpendable" xml:space="preserve">
<value>Elkölthető?</value>
</data>
<data name="DataCurrencyCode" xml:space="preserve">
<value>XMR</value>
</data>
<data name="TextNo" xml:space="preserve">
<value>Nem</value>
</data>
<data name="TextYes" xml:space="preserve">
<value>Igen</value>
</data>
<data name="TransactionTypeReceive" xml:space="preserve">
<value>Fogadás</value>
</data>
<data name="TransactionTypeSend" xml:space="preserve">
<value>Küldés</value>
</data>
<data name="TransactionTypeUnknown" xml:space="preserve">
<value>Ismeretlen</value>
</data>
</root>
20 changes: 19 additions & 1 deletion MoneroGui/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DataCurrencyCode" xml:space="preserve">
<value>MRO</value>
<value>XMR</value>
</data>
<data name="DebugConsoleClear" xml:space="preserve">
<value>Clear</value>
Expand Down Expand Up @@ -258,4 +258,22 @@
<data name="TransactionsType" xml:space="preserve">
<value>Type</value>
</data>
<data name="TransactionsSpendable" xml:space="preserve">
<value>Spendable?</value>
</data>
<data name="TextNo" xml:space="preserve">
<value>No</value>
</data>
<data name="TextYes" xml:space="preserve">
<value>Yes</value>
</data>
<data name="TransactionTypeReceive" xml:space="preserve">
<value>Receive</value>
</data>
<data name="TransactionTypeSend" xml:space="preserve">
<value>Send</value>
</data>
<data name="TransactionTypeUnknown" xml:space="preserve">
<value>Unknown</value>
</data>
</root>
24 changes: 14 additions & 10 deletions MoneroGui/Views/TransactionsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
<Grid>
<DataGrid ItemsSource="{Binding Path=DataSource}" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column">
<DataGrid.Columns>
<!-- TODO: Fix column data (Status, date, type, address, amount) -->
<!-- TODO: Fix column data (Status, Date, Type, Spendable, Payment ID, Amount) -->
<!--<DataGridTextColumn/>-->
<!--<DataGridTextColumn Header="Date" Binding="{Binding Path=Date}" SortDirection="Descending"/>-->
<DataGridTextColumn Header="{x:Static p:Resources.TransactionsType}" Binding="{Binding Path=Type}" Width="Auto"/>

<DataGridTextColumn Header="{x:Static p:Resources.TransactionsType}" Binding="{Binding Path=Type, Converter={StaticResource ConverterTransactionTypeToString}}" ElementStyle="{StaticResource StyleTextBlockAlignedCenter}" Width="Auto"/>
<DataGridTextColumn Header="{x:Static p:Resources.TransactionsSpendable}" Binding="{Binding Path=IsAmountSpendable, Converter={StaticResource ConverterBooleanToStringYesNo}}" ElementStyle="{StaticResource StyleTextBlockAlignedCenter}" Width="Auto"/>
<!--<DataGridTextColumn Header="Payment ID" Binding="{Binding Path=PaymentId}"/>-->
<DataGridTextColumn Header="{x:Static p:Resources.TextAmount}" Binding="{Binding Path=Amount, StringFormat={}{0:0.000000000000}}" Width="Auto"/>
<DataGridTextColumn Header="{x:Static p:Resources.TextAmount}" Binding="{Binding Path=Amount, StringFormat={}{0:0.000000000000}}" ElementStyle="{StaticResource StyleTextBlockAlignedRight}" Width="Auto"/>

<DataGridTemplateColumn Header="Transaction ID" Width="1*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=TransactionId}" ToolTipService.ToolTip="{Binding Path=TransactionId}" TextTrimming="CharacterEllipsis" d:DataContext="{d:DesignInstance Type=api:Transaction}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Transaction ID" Binding="{Binding Path=TransactionId}" Width="1*">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="ToolTip" Value="{Binding Path=(api:Transaction.TransactionId)}"/>
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
<Setter Property="TextAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
Expand Down

0 comments on commit cf31291

Please sign in to comment.