From 3a20931982e94578bb94510f5e67321f42619646 Mon Sep 17 00:00:00 2001 From: Igor Matsak Date: Mon, 9 Dec 2019 20:25:02 +0300 Subject: [PATCH] fix delegation views --- Atomex.Client.Core | 2 +- Atomex.Client.Wpf.Installer/Product.wxs | 2 +- Atomex.Client.Wpf/Atomex.Client.Wpf.csproj | 7 + Atomex.Client.Wpf/Common/Navigation.cs | 13 +- .../DelegateConfirmationViewModel.cs | 2 + .../SendViewModels/DelegateViewModel.cs | 121 ++++-- Atomex.Client.Wpf/Views/DelegatingPage.xaml | 31 ++ .../Views/DelegatingPage.xaml.cs | 12 + Atomex.Client.Wpf/Views/FrameView.xaml.cs | 1 + .../Views/SendViews/DelegatePage.xaml | 341 ++++++++-------- .../Views/SendViews/SendPage.xaml | 367 +++++++++--------- 11 files changed, 497 insertions(+), 402 deletions(-) create mode 100644 Atomex.Client.Wpf/Views/DelegatingPage.xaml create mode 100644 Atomex.Client.Wpf/Views/DelegatingPage.xaml.cs diff --git a/Atomex.Client.Core b/Atomex.Client.Core index 83dfe41..8a3e5eb 160000 --- a/Atomex.Client.Core +++ b/Atomex.Client.Core @@ -1 +1 @@ -Subproject commit 83dfe41b806eafac4c35f50c78c23e95992e4305 +Subproject commit 8a3e5ebcca5f454ba881590d2918ff38743f9d6b diff --git a/Atomex.Client.Wpf.Installer/Product.wxs b/Atomex.Client.Wpf.Installer/Product.wxs index eb3dc5e..1748b7a 100644 --- a/Atomex.Client.Wpf.Installer/Product.wxs +++ b/Atomex.Client.Wpf.Installer/Product.wxs @@ -3,7 +3,7 @@ - + diff --git a/Atomex.Client.Wpf/Atomex.Client.Wpf.csproj b/Atomex.Client.Wpf/Atomex.Client.Wpf.csproj index 79ad9f5..2309894 100644 --- a/Atomex.Client.Wpf/Atomex.Client.Wpf.csproj +++ b/Atomex.Client.Wpf/Atomex.Client.Wpf.csproj @@ -406,6 +406,9 @@ ConversionConfirmationPage.xaml + + DelegatingPage.xaml + DelegateConfirmationPage.xaml @@ -541,6 +544,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/Atomex.Client.Wpf/Common/Navigation.cs b/Atomex.Client.Wpf/Common/Navigation.cs index 8ab1937..59556f4 100644 --- a/Atomex.Client.Wpf/Common/Navigation.cs +++ b/Atomex.Client.Wpf/Common/Navigation.cs @@ -11,6 +11,7 @@ public class Navigation public const string DelegateConfirmationAlias = "DelegateConfirmationPage"; public const string ConversionConfirmationAlias = "ConversionConfirmationPage"; public const string SendingAlias = "SendingPage"; + public const string DelegatingAlias = "DelegatingPage"; public const string MessageAlias = "MessagePage"; public const string DelegateAlias = "DelegatePage"; @@ -71,10 +72,8 @@ public static void Navigate(Page page, object context) navigationState: context); } - public static void Navigate(Page page) - { + public static void Navigate(Page page) => Navigate(page, null); - } public static void Navigate(string uri, object context) { @@ -86,10 +85,8 @@ public static void Navigate(string uri, object context) Navigate(page, context); } - public static void Navigate(string uri) - { + public static void Navigate(string uri) => Navigate(uri, null); - } public static void Back() { @@ -97,9 +94,7 @@ public static void Back() Instance._service.GoBack(); } - public static void UseResolver(IPageResolver resolver) - { + public static void UseResolver(IPageResolver resolver) => Instance._resolver = resolver; - } } } \ No newline at end of file diff --git a/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateConfirmationViewModel.cs b/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateConfirmationViewModel.cs index b30b6e1..b28c332 100644 --- a/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateConfirmationViewModel.cs +++ b/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateConfirmationViewModel.cs @@ -57,6 +57,8 @@ private async void Send() try { + Navigation.Navigate(uri: Navigation.DelegatingAlias); + var signResult = await Tx .SignDelegationOperationAsync(keyStorage, WalletAddress, default); diff --git a/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs b/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs index 6ebeb2c..882cb78 100644 --- a/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs +++ b/Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs @@ -87,7 +87,8 @@ public BakerViewModel BakerViewModel _bakerViewModel = value; OnPropertyChanged(nameof(BakerViewModel)); - Address = _bakerViewModel?.Address; + if (_bakerViewModel != null) + Address = _bakerViewModel.Address; } } @@ -171,7 +172,18 @@ public bool UseDefaultFee public string Address { get => _address; - set { _address = value; OnPropertyChanged(nameof(Address)); } + set + { + _address = value; + OnPropertyChanged(nameof(Address)); + + var baker = FromBakersList.FirstOrDefault(b => b.Address == _address); + + if (baker == null) + BakerViewModel = null; + else if (baker != BakerViewModel) + BakerViewModel = baker; + } } private string _warning; @@ -187,59 +199,82 @@ public string Warning DialogViewer?.HideDelegateDialog(); })); + private bool _delegationCheck; + public bool DelegationCheck + { + get => _delegationCheck; + set { _delegationCheck = value; OnPropertyChanged(nameof(DelegationCheck)); } + } + private ICommand _nextCommand; public ICommand NextCommand => _nextCommand ?? (_nextCommand = new Command(async () => { - if (string.IsNullOrEmpty(Address)) { - Warning = Resources.SvEmptyAddressError; + if (DelegationCheck) return; - } - if (!_tezos.IsValidAddress(Address)) { - Warning = Resources.SvInvalidAddressError; - return; - } + DelegationCheck = true; - if (Fee < 0) { - Warning = Resources.SvCommissionLessThanZeroError; - return; - } + try + { - /* - if (xTezos.GetFeeAmount(Fee, FeePrice) > CurrencyViewModel.AvailableAmount) { - Warning = Resources.SvAvailableFundsError; - return; - }*/ + if (string.IsNullOrEmpty(Address)) + { + Warning = Resources.SvEmptyAddressError; + return; + } - var result = await SendDelegation(); + if (!_tezos.IsValidAddress(Address)) + { + Warning = Resources.SvInvalidAddressError; + return; + } - if (result.HasError) - Warning = result.Error.Description; - else - { - var confirmationViewModel = new DelegateConfirmationViewModel(DialogViewer, _onDelegate) + if (Fee < 0) { - Currency = _tezos, - WalletAddress = WalletAddress, - UseDefaultFee = UseDefaultFee, - Tx = _tx, - From = WalletAddress.Address, - To = Address, - BaseCurrencyCode = BaseCurrencyCode, - BaseCurrencyFormat = BaseCurrencyFormat, - Fee = Fee, - FeeInBase = FeeInBase, - CurrencyCode = _tezos.FeeCode, - CurrencyFormat = _tezos.FeeFormat - }; - - Navigation.Navigate( - uri: Navigation.DelegateConfirmationAlias, - context: confirmationViewModel); + Warning = Resources.SvCommissionLessThanZeroError; + return; + } + + /* + if (xTezos.GetFeeAmount(Fee, FeePrice) > CurrencyViewModel.AvailableAmount) { + Warning = Resources.SvAvailableFundsError; + return; + }*/ + + var result = await GetDelegate(); + + if (result.HasError) + Warning = result.Error.Description; + else + { + var confirmationViewModel = new DelegateConfirmationViewModel(DialogViewer, _onDelegate) + { + Currency = _tezos, + WalletAddress = WalletAddress, + UseDefaultFee = UseDefaultFee, + Tx = _tx, + From = WalletAddress.Address, + To = Address, + BaseCurrencyCode = BaseCurrencyCode, + BaseCurrencyFormat = BaseCurrencyFormat, + Fee = Fee, + FeeInBase = FeeInBase, + CurrencyCode = _tezos.FeeCode, + CurrencyFormat = _tezos.FeeFormat + }; + + Navigation.Navigate( + uri: Navigation.DelegateConfirmationAlias, + context: confirmationViewModel); + } + } + finally + { + DelegationCheck = false; } })); - private Action _onDelegate; + private readonly Action _onDelegate; public DelegateViewModel() { @@ -318,7 +353,7 @@ private async Task PrepareWallet(CancellationToken cancellationToken = default) WalletAddress = FromAddressList.FirstOrDefault().WalletAddress; } - private async Task> SendDelegation(CancellationToken cancellationToken = default) + private async Task> GetDelegate(CancellationToken cancellationToken = default) { if(_walletAddress == null) return new Result(new Error(Errors.InvalidWallets, "You don't have non-empty accounts")); diff --git a/Atomex.Client.Wpf/Views/DelegatingPage.xaml b/Atomex.Client.Wpf/Views/DelegatingPage.xaml new file mode 100644 index 0000000..acd96b6 --- /dev/null +++ b/Atomex.Client.Wpf/Views/DelegatingPage.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/Atomex.Client.Wpf/Views/DelegatingPage.xaml.cs b/Atomex.Client.Wpf/Views/DelegatingPage.xaml.cs new file mode 100644 index 0000000..c36b8b3 --- /dev/null +++ b/Atomex.Client.Wpf/Views/DelegatingPage.xaml.cs @@ -0,0 +1,12 @@ +using System.Windows.Controls; + +namespace Atomex.Client.Wpf.Views +{ + public partial class DelegatingPage : Page + { + public DelegatingPage() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Atomex.Client.Wpf/Views/FrameView.xaml.cs b/Atomex.Client.Wpf/Views/FrameView.xaml.cs index 5b5291e..1b4f4ad 100644 --- a/Atomex.Client.Wpf/Views/FrameView.xaml.cs +++ b/Atomex.Client.Wpf/Views/FrameView.xaml.cs @@ -24,6 +24,7 @@ private void OnLoaded( resolver.AddResolver(Navigation.ConversionConfirmationAlias, () => new ConversionConfirmationPage()); resolver.AddResolver(Navigation.SendingAlias, () => new SendingPage()); resolver.AddResolver(Navigation.DelegateAlias, () => new DelegatePage()); + resolver.AddResolver(Navigation.DelegatingAlias, () => new DelegatingPage()); Navigation.UseResolver(resolver); Navigation.Service = Frame.NavigationService; diff --git a/Atomex.Client.Wpf/Views/SendViews/DelegatePage.xaml b/Atomex.Client.Wpf/Views/SendViews/DelegatePage.xaml index 8d2afbb..7d7ee1f 100644 --- a/Atomex.Client.Wpf/Views/SendViews/DelegatePage.xaml +++ b/Atomex.Client.Wpf/Views/SendViews/DelegatePage.xaml @@ -18,183 +18,194 @@ d:DataContext="{d:DesignInstance Type=viewModels:DelegateViewModel, IsDesignTimeCreatable=True}"> - - + + + - + + - - + + + + - + FontSize="15" + Margin="40 20 40 15" + TextWrapping="Wrap" + HorizontalAlignment="Center"/> - + - + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - + - - - + + + + - + + + + + \ No newline at end of file diff --git a/Atomex.Client.Wpf/Views/SendViews/SendPage.xaml b/Atomex.Client.Wpf/Views/SendViews/SendPage.xaml index e3097fe..1c363cf 100644 --- a/Atomex.Client.Wpf/Views/SendViews/SendPage.xaml +++ b/Atomex.Client.Wpf/Views/SendViews/SendPage.xaml @@ -21,202 +21,203 @@ - + + - - + + + + - + FontSize="15" + Margin="40 20 40 15" + TextWrapping="Wrap" + HorizontalAlignment="Center"/> - + - + + + + + + - - - - - - + + + + - - - - - - - - - - - - + + + + + + + - - - - - + + + + + - - - - + + + + - - - - - - + + + + + + - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - + - - - + + + + - + \ No newline at end of file