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

Commit

Permalink
fix delegation views
Browse files Browse the repository at this point in the history
  • Loading branch information
matsakiv committed Dec 9, 2019
1 parent 430dbc6 commit 3a20931
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 402 deletions.
2 changes: 1 addition & 1 deletion Atomex.Client.Wpf.Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?define Name = "Atomex Client" ?>
<?define Manufacturer = "Atomex.me" ?>
<?define Description = "Multicurrency HD wallet with built-in hybrid exchange based on atomic swap." ?>
<?define Version = "1.0.16" ?>
<?define Version = "1.0.17" ?>
<?define UpgradeCode = "DB7FCF8D-E0C6-4C99-A6B1-3FB6D703F97E" ?>
<?define ExeName = "Atomex.Client.Wpf.exe" ?>

Expand Down
7 changes: 7 additions & 0 deletions Atomex.Client.Wpf/Atomex.Client.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@
<Compile Include="Views\ConversionConfirmationPage.xaml.cs">
<DependentUpon>ConversionConfirmationPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\DelegatingPage.xaml.cs">
<DependentUpon>DelegatingPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SendViews\DelegateConfirmationPage.xaml.cs">
<DependentUpon>DelegateConfirmationPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -541,6 +544,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\DelegatingPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SendViews\DelegateConfirmationPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
13 changes: 4 additions & 9 deletions Atomex.Client.Wpf/Common/Navigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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)
{
Expand All @@ -86,20 +85,16 @@ 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()
{
if (Instance._service.CanGoBack)
Instance._service.GoBack();
}

public static void UseResolver(IPageResolver resolver)
{
public static void UseResolver(IPageResolver resolver) =>
Instance._resolver = resolver;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private async void Send()

try
{
Navigation.Navigate(uri: Navigation.DelegatingAlias);

var signResult = await Tx
.SignDelegationOperationAsync(keyStorage, WalletAddress, default);

Expand Down
121 changes: 78 additions & 43 deletions Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public BakerViewModel BakerViewModel
_bakerViewModel = value;
OnPropertyChanged(nameof(BakerViewModel));

Address = _bakerViewModel?.Address;
if (_bakerViewModel != null)
Address = _bakerViewModel.Address;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down Expand Up @@ -318,7 +353,7 @@ private async Task PrepareWallet(CancellationToken cancellationToken = default)
WalletAddress = FromAddressList.FirstOrDefault().WalletAddress;
}

private async Task<Result<string>> SendDelegation(CancellationToken cancellationToken = default)
private async Task<Result<string>> GetDelegate(CancellationToken cancellationToken = default)
{
if(_walletAddress == null)
return new Result<string>(new Error(Errors.InvalidWallets, "You don't have non-empty accounts"));
Expand Down
31 changes: 31 additions & 0 deletions Atomex.Client.Wpf/Views/DelegatingPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Page x:Class="Atomex.Client.Wpf.Views.DelegatingPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
d:DesignHeight="200"
d:DesignWidth="560">

<StackPanel Orientation="Vertical">
<Border Margin="0 10 0 10"
Height="33"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Background="{StaticResource ChildViewHeaderBackgroundBrush}">
<TextBlock Text="Delegating..."
Foreground="{StaticResource ChildViewHeaderForegroundBrush}"
FontFamily="{StaticResource RobotoLight}"
FontSize="25"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>

<Grid>
<mah:ProgressRing Width="50"
Height="50"
Margin="0 40 0 40"/>
</Grid>
</StackPanel>
</Page>
12 changes: 12 additions & 0 deletions Atomex.Client.Wpf/Views/DelegatingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows.Controls;

namespace Atomex.Client.Wpf.Views
{
public partial class DelegatingPage : Page
{
public DelegatingPage()
{
InitializeComponent();
}
}
}
1 change: 1 addition & 0 deletions Atomex.Client.Wpf/Views/FrameView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3a20931

Please sign in to comment.