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

Commit

Permalink
update client to v1.0.18, improve receive view
Browse files Browse the repository at this point in the history
  • Loading branch information
matsakiv committed Dec 10, 2019
1 parent 3a20931 commit 2b20262
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 54 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.17" ?>
<?define Version = "1.0.18" ?>
<?define UpgradeCode = "DB7FCF8D-E0C6-4C99-A6B1-3FB6D703F97E" ?>
<?define ExeName = "Atomex.Client.Wpf.exe" ?>

Expand Down
1 change: 1 addition & 0 deletions Atomex.Client.Wpf/Atomex.Client.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
<Compile Include="ViewModels\SendViewModels\SendConfirmationViewModel.cs" />
<Compile Include="ViewModels\SendViewModels\DelegateViewModel.cs" />
<Compile Include="ViewModels\SendViewModels\SendViewModel.cs" />
<Compile Include="ViewModels\SendViewModels\WalletAddressViewModel.cs" />
<Compile Include="ViewModels\SettingsViewModel.cs" />
<Compile Include="ViewModels\SwapViewModel.cs" />
<Compile Include="ViewModels\SwapViewModelFactory.cs" />
Expand Down
30 changes: 10 additions & 20 deletions Atomex.Client.Wpf/ViewModels/MessageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@ public MessageViewModel(
_nextAction = nextAction;
}

public static MessageViewModel Error(string text)
{
return Error(text, goBackPages: 1);
}
public static MessageViewModel Error(string text) =>
Error(text, goBackPages: 1);

public static MessageViewModel Error(string text, int goBackPages)
{
return new MessageViewModel(
public static MessageViewModel Error(string text, int goBackPages) =>
new MessageViewModel(
title: Resources.SvError,
text: text,
backTitle: Resources.SvBack,
Expand All @@ -98,22 +95,18 @@ public static MessageViewModel Error(string text, int goBackPages)
Navigation.Back();
},
nextAction: null);
}

public static MessageViewModel Success(string text, Action nextAction)
{
return new MessageViewModel(
public static MessageViewModel Success(string text, Action nextAction) =>
new MessageViewModel(
title: Resources.SvSuccess,
text: text,
backTitle: null,
nextTitle: Resources.SvOk,
backAction: null,
nextAction: nextAction);
}

public static MessageViewModel Message(string title, string text, int goBackPages)
{
return new MessageViewModel(
public static MessageViewModel Message(string title, string text, int goBackPages) =>
new MessageViewModel(
title: title,
text: text,
backTitle: Resources.SvBack,
Expand All @@ -124,11 +117,9 @@ public static MessageViewModel Message(string title, string text, int goBackPage
Navigation.Back();
},
nextAction: null);
}

public static MessageViewModel Success(string text, string baseUrl, string id, Action nextAction)
{
return new MessageViewModel(
public static MessageViewModel Success(string text, string baseUrl, string id, Action nextAction) =>
new MessageViewModel(
title: Resources.SvSuccess,
text: text,
baseUrl: baseUrl,
Expand All @@ -137,7 +128,6 @@ public static MessageViewModel Success(string text, string baseUrl, string id, A
nextTitle: Resources.SvOk,
backAction: null,
nextAction: nextAction);
}

private ICommand _openTxInExplorerCommand;
public ICommand OpenTxInExplorerCommand => _openTxInExplorerCommand ?? (_openTxInExplorerCommand = new RelayCommand<string>((id) =>
Expand Down
95 changes: 83 additions & 12 deletions Atomex.Client.Wpf/ViewModels/ReceiveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
using Atomex.Core.Entities;
using Atomex.Client.Wpf.Common;
using Atomex.Client.Wpf.ViewModels.Abstract;
using Atomex.Client.Wpf.ViewModels.SendViewModels;
using Atomex.Common;
using QRCoder;
using System;
using System.Windows.Input;
using Serilog;

namespace Atomex.Client.Wpf.ViewModels
{
public class ReceiveViewModel : BaseViewModel
{
private const int PixelsPerModule = 20;

private IAtomexApp App { get; }

private List<CurrencyViewModel> _fromCurrencies;
public List<CurrencyViewModel> FromCurrencies
{
Expand All @@ -31,30 +37,64 @@ public Currency Currency
{
_currency = value;
OnPropertyChanged(nameof(Currency));

#if DEBUG
if (!Env.IsInDesignerMode())
{
#endif
Address = App.AtomexApp.Account
var activeAddresses = App.Account
.GetUnspentAddressesAsync(_currency)
.WaitForResult();

var freeAddress = App.Account
.GetFreeExternalAddressAsync(_currency)
.WaitForResult()
.Address;
.WaitForResult();

FromAddressList = activeAddresses
.Select(wa => new WalletAddressViewModel(wa))
.ToList()
.AddEx(new WalletAddressViewModel(freeAddress, isFreeAddress: true));
#if DEBUG
}
#endif
}
}

private List<WalletAddressViewModel> _fromAddressList;
public List<WalletAddressViewModel> FromAddressList
{
get => _fromAddressList;
private set
{
_fromAddressList = value;
OnPropertyChanged(nameof(FromAddressList));

SelectedAddress = GetDefaultAddress();
}
}

private string _address;
public string Address
private WalletAddress _selectedAddress;
public WalletAddress SelectedAddress
{
get => _address;
get => _selectedAddress;
set
{
_address = value;
OnPropertyChanged(nameof(Address));
_selectedAddress = value;
OnPropertyChanged(nameof(SelectedAddress));

if (_selectedAddress != null)
CreateQrCodeAsync().FireAndForget();

CreateQrCodeAsync().FireAndForget();
Warning = string.Empty;
}
}

private string _warning;
public string Warning
{
get => _warning;
set { _warning = value; OnPropertyChanged(nameof(Warning)); }
}

public BitmapSource QrCode { get; private set; }

public ReceiveViewModel()
Expand All @@ -72,6 +112,8 @@ public ReceiveViewModel(IAtomexApp app)

public ReceiveViewModel(IAtomexApp app, Currency currency)
{
App = app ?? throw new ArgumentNullException(nameof(app));

FromCurrencies = app.Account.Currencies
.Where(c => c.IsTransactionsAvailable)
.Select(CurrencyViewModelCreator.CreateViewModel)
Expand All @@ -87,7 +129,7 @@ private async Task CreateQrCodeAsync()
await Task.Factory.StartNew(() =>
{
using (var qrGenerator = new QRCodeGenerator())
using (var qrData = qrGenerator.CreateQrCode(Address, QRCodeGenerator.ECCLevel.Q))
using (var qrData = qrGenerator.CreateQrCode(_selectedAddress.Address, QRCodeGenerator.ECCLevel.Q))
using (var qrCode = new QRCode(qrData))
qrCodeBitmap = qrCode.GetGraphic(PixelsPerModule);
});
Expand All @@ -104,14 +146,43 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
}
}

private WalletAddress GetDefaultAddress()
{
if (Currency is Tezos || Currency is Ethereum)
{
var activeAddressViewModel = FromAddressList
.FirstOrDefault(vm => vm.WalletAddress.HasActivity && vm.WalletAddress.AvailableBalance() > 0);

if (activeAddressViewModel != null)
return activeAddressViewModel.WalletAddress;
}

return FromAddressList.First(vm => vm.IsFreeAddress).WalletAddress;
}

private ICommand _copyCommand;
public ICommand CopyCommand => _copyCommand ?? (_copyCommand = new RelayCommand<string>((s) =>
{
try
{
Clipboard.SetText(SelectedAddress.Address);

Warning = "Address successfully copied to clipboard.";
}
catch (Exception e)
{
Log.Error(e, "Copy to clipboard error");
}
}));

private void DesignerMode()
{
FromCurrencies = DesignTime.Currencies
.Select(c => CurrencyViewModelCreator.CreateViewModel(c, subscribeToUpdates: false))
.ToList();

Currency = FromCurrencies.First().Currency;
Address = "mzztP8VVJYxV93EUiiYrJUbL55MLx7KLoM";
// Address = "mzztP8VVJYxV93EUiiYrJUbL55MLx7KLoM";
}
}
}
11 changes: 0 additions & 11 deletions Atomex.Client.Wpf/ViewModels/SendViewModels/DelegateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@

namespace Atomex.Client.Wpf.ViewModels.SendViewModels
{
public class WalletAddressViewModel
{
public WalletAddress WalletAddress { get; set; }

public string Address => WalletAddress.Address;
public decimal AvailableBalance => WalletAddress.AvailableBalance();

public WalletAddressViewModel(WalletAddress walletAddress) =>
WalletAddress = walletAddress;
}

public class DelegateViewModel : BaseViewModel
{
private IAtomexApp App { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Atomex.Core.Entities;

namespace Atomex.Client.Wpf.ViewModels.SendViewModels
{
public class WalletAddressViewModel
{
public WalletAddress WalletAddress { get; }
public string Address => WalletAddress.Address;
public decimal AvailableBalance => WalletAddress.AvailableBalance();
public string CurrencyFormat => WalletAddress.Currency.Format;
public bool IsFreeAddress { get; }

public WalletAddressViewModel(WalletAddress walletAddress, bool isFreeAddress = false)
{
WalletAddress = walletAddress;
IsFreeAddress = isFreeAddress;
}
}
}
Loading

0 comments on commit 2b20262

Please sign in to comment.