Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Merged changes in commit d4162f2 in neo-project/neo-gui (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
justingaffney committed Dec 29, 2017
1 parent f0174ec commit bb485a0
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Neo.Gui.Base/Controllers/IWalletController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ InvocationTransaction MakeContractCreationTransaction(byte[] script, byte[] para

void ExecuteInvocationTransaction(InvocationTransaction transaction);

void ExecuteTransferTransaction(IEnumerable<TransactionOutputItem> items, string remark);
void ExecuteTransferTransaction(IEnumerable<TransactionOutputItem> items, string remark, UInt160 changeAddress = null, Fixed8 fee = default(Fixed8));
}
}
4 changes: 2 additions & 2 deletions Neo.Gui.Base/Controllers/WalletController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public void ExecuteInvocationTransaction(InvocationTransaction transaction)
this.SignAndRelayTransaction(transactionWithFee);
}

public void ExecuteTransferTransaction(IEnumerable<TransactionOutputItem> items, string remark)
public void ExecuteTransferTransaction(IEnumerable<TransactionOutputItem> items, string remark, UInt160 changeAddress = null, Fixed8 fee = default(Fixed8))
{
var cOutputs = items.Where(p => p.AssetId is UInt160).GroupBy(p => new
{
Expand Down Expand Up @@ -865,7 +865,7 @@ public void ExecuteTransferTransaction(IEnumerable<TransactionOutputItem> items,

if (tx is ContractTransaction ctx)
{
tx = this.MakeTransaction(ctx);
tx = this.MakeTransaction(ctx, changeAddress, fee);
}

if (tx == null) return;
Expand Down
18 changes: 18 additions & 0 deletions Neo.Gui.Globalization/Resources/Strings.Designer.cs

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

7 changes: 7 additions & 0 deletions Neo.Gui.Globalization/Resources/Strings.es-Es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<data name="AdvancedMenuHeader" xml:space="preserve">
<value>A_vanzado</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>Avanzado</value>
</data>
<data name="Amount" xml:space="preserve">
<value>Cantidad</value>
</data>
Expand Down Expand Up @@ -850,4 +853,8 @@ Aviso: los ficheros actualizados no podran ser abiertos por clientes de versione
<data name="WatchOnly" xml:space="preserve">
<value>Ver solo</value>
</data>
<data name="ChangeAddress" xml:space="preserve">
<!-- TODO Translate -->
<value>Change Address</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Neo.Gui.Globalization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<data name="AdvancedMenuHeader" xml:space="preserve">
<value>Ad_vanced</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>Advanced</value>
</data>
<data name="Amount" xml:space="preserve">
<value>Amount</value>
</data>
Expand Down Expand Up @@ -853,4 +856,7 @@ Note: updated files cannot be openned by clients in older versions!</value>
<data name="WatchOnly" xml:space="preserve">
<value>Watch Only</value>
</data>
<data name="ChangeAddress" xml:space="preserve">
<value>Change Address</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Neo.Gui.Globalization/Resources/Strings.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<data name="AdvancedMenuHeader" xml:space="preserve">
<value>高级(_V)</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>高级</value>
</data>
<data name="Amount" xml:space="preserve">
<value>数额</value>
</data>
Expand Down Expand Up @@ -850,4 +853,7 @@
<data name="WatchOnly" xml:space="preserve">
<value>只看</value>
</data>
<data name="ChangeAddress" xml:space="preserve">
<value>找零地址</value>
</data>
</root>
86 changes: 76 additions & 10 deletions Neo.Gui.ViewModels/Wallets/TransferViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

using Neo.Gui.Globalization.Resources;

using Neo.Gui.Base.Controllers;
using Neo.Gui.Base.Data;
using Neo.Gui.Base.Dialogs.Interfaces;
using Neo.Gui.Base.Dialogs.LoadParameters.Contracts;
using Neo.Gui.Base.Dialogs.Results;
using Neo.Gui.Base.Dialogs.Results.Contracts;
using Neo.Gui.Base.Dialogs.Results.Wallets;
using Neo.Gui.Base.Messaging.Interfaces;
using Neo.Gui.Globalization.Resources;
using Neo.Gui.Base.Managers;

namespace Neo.Gui.ViewModels.Wallets
Expand All @@ -22,18 +20,66 @@ public class TransferViewModel : ViewModelBase, IDialogViewModel<TransferDialogR
#region Private Fields
private readonly IDialogManager dialogManager;
private readonly IWalletController walletController;
private readonly IMessagePublisher messagePublisher;

private bool showAdvancedSection;

private string fee = "0";

private string selectedChangeAddress;

private string remark = string.Empty;
#endregion

#region Public Properties
public ObservableCollection<TransactionOutputItem> Items { get; }

public ObservableCollection<string> Addresses { get; }

public bool ShowAdvancedSection
{
get => this.showAdvancedSection;
set
{
if (this.showAdvancedSection == value) return;

this.showAdvancedSection = value;

RaisePropertyChanged();
}
}

public string Fee
{
get => this.fee;
set
{
if (this.fee == value) return;

this.fee = value;

RaisePropertyChanged();
}
}

public string SelectedChangeAddress
{
get => this.selectedChangeAddress;
set
{
if (this.selectedChangeAddress == value) return;

this.selectedChangeAddress = value;

RaisePropertyChanged();
}
}

public bool OkEnabled => this.Items.Count > 0;

public RelayCommand RemarkCommand => new RelayCommand(this.Remark);

public RelayCommand AdvancedCommand => new RelayCommand(this.ToggleAdvancedSection);

public RelayCommand OkCommand => new RelayCommand(this.Ok);

public RelayCommand CancelCommand => new RelayCommand(() => this.Close(this, EventArgs.Empty));
Expand All @@ -42,14 +88,15 @@ public class TransferViewModel : ViewModelBase, IDialogViewModel<TransferDialogR
#region Constructor
public TransferViewModel(
IDialogManager dialogManager,
IWalletController walletController,
IMessagePublisher messagePublisher)
IWalletController walletController)
{
this.dialogManager = dialogManager;
this.walletController = walletController;
this.messagePublisher = messagePublisher;

this.Items = new ObservableCollection<TransactionOutputItem>();

this.Addresses = new ObservableCollection<string>(
this.walletController.GetAccounts().Select(account => account.Address));
}
#endregion

Expand Down Expand Up @@ -80,9 +127,28 @@ private void Remark()
this.remark = result;
}

private void ToggleAdvancedSection()
{
this.ShowAdvancedSection = !this.ShowAdvancedSection;
}

private void Ok()
{
this.walletController.ExecuteTransferTransaction(this.Items, this.remark);
if (!this.OkEnabled) return;

UInt160 transferChangeAddress = null;

if (!Fixed8.TryParse(this.fee, out var transferFee))
{
transferFee = Fixed8.Zero;
}

if (!string.IsNullOrEmpty(this.SelectedChangeAddress))
{
transferChangeAddress = this.walletController.ToScriptHash(this.SelectedChangeAddress);
}

this.walletController.ExecuteTransferTransaction(this.Items, this.remark, transferChangeAddress, transferFee);

this.Close(this, EventArgs.Empty);
}
Expand Down
25 changes: 24 additions & 1 deletion Neo.Gui.Wpf/Views/Wallets/TransferView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<GroupBox Grid.Row="0" Header="{x:Static globalization:Strings.RecipientList}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
Expand All @@ -23,8 +24,30 @@
</Button>
</Grid>
</GroupBox>

<GroupBox Grid.Row="1" Header="{x:Static globalization:Strings.Advanced}" Visibility="{Binding ShowAdvancedSection, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Hidden}">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" Content="{x:Static globalization:Strings.Fee}" Margin="0 0 4 0" VerticalAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Fee, UpdateSourceTrigger=PropertyChanged}" Margin="4" Padding="4" HorizontalAlignment="Stretch" />

<Label Grid.Row="1" Grid.Column="0" Content="{x:Static globalization:Strings.ChangeAddress}" Margin="0 0 4 0" VerticalAlignment="Center" />
<ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Addresses}" SelectedItem="{Binding SelectedChangeAddress}" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
</Grid>
</GroupBox>

<Button Grid.Row="2" Width="70" Margin="0 8 0 0" Content="{x:Static globalization:Strings.Advanced}" HorizontalAlignment="Left" Command="{Binding AdvancedCommand}" />

<DockPanel Grid.Row="1" Margin="0 8 0 0" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<DockPanel Grid.Row="2" Margin="0 8 0 0" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Button Content="{x:Static globalization:Strings.OK}" Width="70" Margin="0 0 8 0" Command="{Binding OkCommand}" IsEnabled="{Binding OkEnabled}" />
<Button Content="{x:Static globalization:Strings.Cancel}" Width="70" Command="{Binding CancelCommand}" />
</DockPanel>
Expand Down

0 comments on commit bb485a0

Please sign in to comment.