From bb485a0e7adb6225fa092270125962bc91ec4a4a Mon Sep 17 00:00:00 2001 From: Justin Gaffney Date: Fri, 29 Dec 2017 14:47:37 +1000 Subject: [PATCH] Merged changes in commit d4162f2 in neo-project/neo-gui (#114) --- Neo.Gui.Base/Controllers/IWalletController.cs | 2 +- Neo.Gui.Base/Controllers/WalletController.cs | 4 +- .../Resources/Strings.Designer.cs | 18 ++++ .../Resources/Strings.es-Es.resx | 7 ++ Neo.Gui.Globalization/Resources/Strings.resx | 6 ++ .../Resources/Strings.zh-Hans.resx | 6 ++ .../Wallets/TransferViewModel.cs | 86 ++++++++++++++++--- Neo.Gui.Wpf/Views/Wallets/TransferView.xaml | 25 +++++- 8 files changed, 140 insertions(+), 14 deletions(-) diff --git a/Neo.Gui.Base/Controllers/IWalletController.cs b/Neo.Gui.Base/Controllers/IWalletController.cs index 5d23d986..e994b6dd 100644 --- a/Neo.Gui.Base/Controllers/IWalletController.cs +++ b/Neo.Gui.Base/Controllers/IWalletController.cs @@ -144,6 +144,6 @@ InvocationTransaction MakeContractCreationTransaction(byte[] script, byte[] para void ExecuteInvocationTransaction(InvocationTransaction transaction); - void ExecuteTransferTransaction(IEnumerable items, string remark); + void ExecuteTransferTransaction(IEnumerable items, string remark, UInt160 changeAddress = null, Fixed8 fee = default(Fixed8)); } } \ No newline at end of file diff --git a/Neo.Gui.Base/Controllers/WalletController.cs b/Neo.Gui.Base/Controllers/WalletController.cs index 1f8dffdd..ce48a8c9 100644 --- a/Neo.Gui.Base/Controllers/WalletController.cs +++ b/Neo.Gui.Base/Controllers/WalletController.cs @@ -756,7 +756,7 @@ public void ExecuteInvocationTransaction(InvocationTransaction transaction) this.SignAndRelayTransaction(transactionWithFee); } - public void ExecuteTransferTransaction(IEnumerable items, string remark) + public void ExecuteTransferTransaction(IEnumerable items, string remark, UInt160 changeAddress = null, Fixed8 fee = default(Fixed8)) { var cOutputs = items.Where(p => p.AssetId is UInt160).GroupBy(p => new { @@ -865,7 +865,7 @@ public void ExecuteTransferTransaction(IEnumerable items, if (tx is ContractTransaction ctx) { - tx = this.MakeTransaction(ctx); + tx = this.MakeTransaction(ctx, changeAddress, fee); } if (tx == null) return; diff --git a/Neo.Gui.Globalization/Resources/Strings.Designer.cs b/Neo.Gui.Globalization/Resources/Strings.Designer.cs index 233eede6..4eb34748 100644 --- a/Neo.Gui.Globalization/Resources/Strings.Designer.cs +++ b/Neo.Gui.Globalization/Resources/Strings.Designer.cs @@ -177,6 +177,15 @@ public static string Admin { } } + /// + /// Looks up a localized string similar to Advanced. + /// + public static string Advanced { + get { + return ResourceManager.GetString("Advanced", resourceCulture); + } + } + /// /// Looks up a localized string similar to Ad_vanced. /// @@ -411,6 +420,15 @@ public static string CertificateApplicationTitle { } } + /// + /// Looks up a localized string similar to Change Address. + /// + public static string ChangeAddress { + get { + return ResourceManager.GetString("ChangeAddress", resourceCulture); + } + } + /// /// Looks up a localized string similar to Change logs. /// diff --git a/Neo.Gui.Globalization/Resources/Strings.es-Es.resx b/Neo.Gui.Globalization/Resources/Strings.es-Es.resx index 8701ff2f..bc9f817e 100644 --- a/Neo.Gui.Globalization/Resources/Strings.es-Es.resx +++ b/Neo.Gui.Globalization/Resources/Strings.es-Es.resx @@ -156,6 +156,9 @@ A_vanzado + + Avanzado + Cantidad @@ -850,4 +853,8 @@ Aviso: los ficheros actualizados no podran ser abiertos por clientes de versione Ver solo + + + Change Address + \ No newline at end of file diff --git a/Neo.Gui.Globalization/Resources/Strings.resx b/Neo.Gui.Globalization/Resources/Strings.resx index 90e21b3b..1ea0febc 100644 --- a/Neo.Gui.Globalization/Resources/Strings.resx +++ b/Neo.Gui.Globalization/Resources/Strings.resx @@ -156,6 +156,9 @@ Ad_vanced + + Advanced + Amount @@ -853,4 +856,7 @@ Note: updated files cannot be openned by clients in older versions! Watch Only + + Change Address + \ No newline at end of file diff --git a/Neo.Gui.Globalization/Resources/Strings.zh-Hans.resx b/Neo.Gui.Globalization/Resources/Strings.zh-Hans.resx index 183ee2f8..d3fe3401 100644 --- a/Neo.Gui.Globalization/Resources/Strings.zh-Hans.resx +++ b/Neo.Gui.Globalization/Resources/Strings.zh-Hans.resx @@ -156,6 +156,9 @@ 高级(_V) + + 高级 + 数额 @@ -850,4 +853,7 @@ 只看 + + 找零地址 + \ No newline at end of file diff --git a/Neo.Gui.ViewModels/Wallets/TransferViewModel.cs b/Neo.Gui.ViewModels/Wallets/TransferViewModel.cs index 7a59e0c8..2cf84823 100644 --- a/Neo.Gui.ViewModels/Wallets/TransferViewModel.cs +++ b/Neo.Gui.ViewModels/Wallets/TransferViewModel.cs @@ -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 @@ -22,7 +20,12 @@ public class TransferViewModel : ViewModelBase, IDialogViewModel Items { get; } + public ObservableCollection 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)); @@ -42,14 +88,15 @@ public class TransferViewModel : ViewModelBase, IDialogViewModel(); + + this.Addresses = new ObservableCollection( + this.walletController.GetAccounts().Select(account => account.Address)); } #endregion @@ -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); } diff --git a/Neo.Gui.Wpf/Views/Wallets/TransferView.xaml b/Neo.Gui.Wpf/Views/Wallets/TransferView.xaml index dc6fd917..9018fbd2 100644 --- a/Neo.Gui.Wpf/Views/Wallets/TransferView.xaml +++ b/Neo.Gui.Wpf/Views/Wallets/TransferView.xaml @@ -12,6 +12,7 @@ + @@ -23,8 +24,30 @@ + + + + + + + + + + + + + + + + +