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

Commit

Permalink
Fix Tezos token contracts with empty alias name, fix balance checker
Browse files Browse the repository at this point in the history
  • Loading branch information
matsakiv committed Sep 4, 2021
1 parent a89bab8 commit 296d315
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Atomex.Client.Core
1 change: 1 addition & 0 deletions Atomex.Client.Wpf/ViewModels/ConversionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
{
var swapViewModels = swaps
.Select(s => SwapViewModelFactory.CreateSwapViewModel(s, Currencies))
.Where(s => s != null)
.ToList()
.SortList((s1, s2) => s2.Time.ToUniversalTime()
.CompareTo(s1.Time.ToUniversalTime()));
Expand Down
75 changes: 43 additions & 32 deletions Atomex.Client.Wpf/ViewModels/SwapViewModelFactory.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
using System;
using System.Windows.Media;

using Atomex.Abstract;
using Atomex.Client.Wpf.ViewModels.CurrencyViewModels;
using Atomex.Common;
using Atomex.Core;
using Serilog;

namespace Atomex.Client.Wpf.ViewModels
{
public static class SwapViewModelFactory
{
public static SwapViewModel CreateSwapViewModel(Swap swap, ICurrencies currencies)
{
var soldCurrency = currencies.GetByName(swap.SoldCurrency);
var purchasedCurrency = currencies.GetByName(swap.PurchasedCurrency);
try
{
var soldCurrency = currencies.GetByName(swap.SoldCurrency);
var purchasedCurrency = currencies.GetByName(swap.PurchasedCurrency);

var fromCurrencyViewModel = CurrencyViewModelCreator.CreateViewModel(
currencyConfig: soldCurrency,
subscribeToUpdates: false);

var fromCurrencyViewModel = CurrencyViewModelCreator.CreateViewModel(
currencyConfig: soldCurrency,
subscribeToUpdates: false);
var toCurrencyViewModel = CurrencyViewModelCreator.CreateViewModel(
currencyConfig: purchasedCurrency,
subscribeToUpdates:false);

var toCurrencyViewModel = CurrencyViewModelCreator.CreateViewModel(
currencyConfig: purchasedCurrency,
subscribeToUpdates:false);
var fromAmount = AmountHelper.QtyToAmount(swap.Side, swap.Qty, swap.Price, soldCurrency.DigitsMultiplier);
var toAmount = AmountHelper.QtyToAmount(swap.Side.Opposite(), swap.Qty, swap.Price, purchasedCurrency.DigitsMultiplier);

var fromAmount = AmountHelper.QtyToAmount(swap.Side, swap.Qty, swap.Price, soldCurrency.DigitsMultiplier);
var toAmount = AmountHelper.QtyToAmount(swap.Side.Opposite(), swap.Qty, swap.Price, purchasedCurrency.DigitsMultiplier);
var quoteCurrency = swap.Symbol.QuoteCurrency() == swap.SoldCurrency
? soldCurrency
: purchasedCurrency;

var quoteCurrency = swap.Symbol.QuoteCurrency() == swap.SoldCurrency
? soldCurrency
: purchasedCurrency;
return new SwapViewModel
{
Id = swap.Id.ToString(),
CompactState = CompactStateBySwap(swap),
Mode = ModeBySwap(swap),
Time = swap.TimeStamp,

return new SwapViewModel
FromBrush = new SolidColorBrush(fromCurrencyViewModel.AmountColor),
FromAmount = fromAmount,
FromAmountFormat = fromCurrencyViewModel.CurrencyFormat,
FromCurrencyCode = fromCurrencyViewModel.CurrencyCode,

ToBrush = new SolidColorBrush(toCurrencyViewModel.AmountColor),
ToAmount = toAmount,
ToAmountFormat = toCurrencyViewModel.CurrencyFormat,
ToCurrencyCode = toCurrencyViewModel.CurrencyCode,

Price = swap.Price,
PriceFormat = $"F{quoteCurrency.Digits}"
};
}
catch (Exception e)
{
Id = swap.Id.ToString(),
CompactState = CompactStateBySwap(swap),
Mode = ModeBySwap(swap),
Time = swap.TimeStamp,

FromBrush = new SolidColorBrush(fromCurrencyViewModel.AmountColor),
FromAmount = fromAmount,
FromAmountFormat = fromCurrencyViewModel.CurrencyFormat,
FromCurrencyCode = fromCurrencyViewModel.CurrencyCode,

ToBrush = new SolidColorBrush(toCurrencyViewModel.AmountColor),
ToAmount = toAmount,
ToAmountFormat = toCurrencyViewModel.CurrencyFormat,
ToCurrencyCode = toCurrencyViewModel.CurrencyCode,

Price = swap.Price,
PriceFormat = $"F{quoteCurrency.Digits}"
};
Log.Error(e, $"Error while create SwapViewModel for {swap.Symbol} swap with id {swap.Id}");

return null;
}
}

private static SwapMode ModeBySwap(Swap swap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public string Name
}
}

public bool HasName => !string.IsNullOrEmpty(_name);

private async Task TryGetAliasAsync()
{
try
Expand Down Expand Up @@ -274,6 +276,7 @@ await Application
.InvokeAsync(() =>
{
OnPropertyChanged(nameof(Name));
OnPropertyChanged(nameof(HasName));
});
}
catch (Exception e)
Expand Down Expand Up @@ -303,6 +306,7 @@ public TezosTokenContractViewModel TokenContract
OnPropertyChanged(nameof(HasTokenContract));
OnPropertyChanged(nameof(IsFa12));
OnPropertyChanged(nameof(IsFa2));
OnPropertyChanged(nameof(HasName));
OnPropertyChanged(nameof(TokenContractAddress));
OnPropertyChanged(nameof(TokenContractName));
OnPropertyChanged(nameof(TokenContractIconUrl));
Expand All @@ -315,6 +319,7 @@ public TezosTokenContractViewModel TokenContract
public bool HasTokenContract => TokenContract != null;
public bool IsFa12 => TokenContract?.IsFa12 ?? false;
public bool IsFa2 => TokenContract?.IsFa2 ?? false;
public bool HasName => TokenContract?.HasName ?? false;
public string TokenContractAddress => TokenContract?.Contract?.Address ?? "";
public string TokenContractName => TokenContract?.Name ?? "";
public string TokenContractIconUrl => TokenContract?.IconUrl;
Expand Down Expand Up @@ -732,12 +737,13 @@ protected void DesignerMode()
Network = "mainent",
Name = "hic et nunc NFTs",
Description = "NFT token for digital assets.",
Interfaces = new List<string> { "TZIP-12" }
Interfaces = new List<string> { "TZIP-12" },
ContractTags = new List<string> { "fa2" }
}
}
};

_tokenContract = null;// TokensContracts.First();
_tokenContract = TokensContracts.First();

var bcdApi = new BcdApi(new BcdApiSettings
{
Expand Down
41 changes: 36 additions & 5 deletions Atomex.Client.Wpf/Views/WalletViews/TezosTokensWalletView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,22 @@
FontSize="10"
FontFamily="{StaticResource DefaultLightFontFamily}"
VerticalAlignment="Center"
Grid.Column="1"
Grid.Row="2"/>
Grid.Column="1">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding HasName}" Value="True">
<Setter Property="Grid.Row" Value="2"/>
<Setter Property="Grid.RowSpan" Value="1"/>
</DataTrigger>
<DataTrigger Binding="{Binding HasName}" Value="False">
<Setter Property="Grid.Row" Value="1"/>
<Setter Property="Grid.RowSpan" Value="2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
Expand Down Expand Up @@ -138,6 +152,7 @@
Foreground="{DynamicResource BalanceBackgroundBrush}"
FontFamily="{DynamicResource DefaultFontFamily}"
FontSize="30"
Margin="0 0 0 2"
VerticalAlignment="Bottom"
Grid.Row="1"
Grid.Column="3"
Expand Down Expand Up @@ -172,10 +187,26 @@
Foreground="LightGray"
FontFamily="{DynamicResource DefaultFontFamily}"
FontSize="12"
Grid.Row="2"
Grid.Column="3"
Style="{StaticResource BaseTextBlockStyle}"
Visibility="{Binding HasTokenContract, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"/>
Visibility="{Binding HasTokenContract, Converter={StaticResource BoolToVisibilityCollapsedConverter}}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Grid.Row" Value="2"/>
<Setter Property="Grid.RowSpan" Value="1"/>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsFa2}" Value="True"/>
<Condition Binding="{Binding HasName}" Value="False"/>
</MultiDataTrigger.Conditions>
<Setter Property="Grid.Row" Value="1"/>
<Setter Property="Grid.RowSpan" Value="2"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>

<StackPanel HorizontalAlignment="Center"
Orientation="Horizontal"
Expand Down

0 comments on commit 296d315

Please sign in to comment.