Skip to content

Commit

Permalink
Merge pull request #17 from ismaelestalayo/develop
Browse files Browse the repository at this point in the history
v6.0.4
  • Loading branch information
ismaelestalayo committed Sep 8, 2021
2 parents e7626fa + aa86f40 commit 2940fc7
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 126 deletions.
8 changes: 8 additions & 0 deletions UWP.Shared/Constants/Changelogs.cs
Expand Up @@ -8,6 +8,14 @@ namespace UWP.Core.Constants {
public class Changelogs {

public static readonly Dictionary<string, List<string>> LatestChangelogs = new Dictionary<string, List<string>>(){
{
"6.0.4",
new List<string>() {
"General: fixed casting error on startup",
"Coins: SHIB and other alt-coins' empty graphs fixed",
"Portfolio: fixed rounding errors",
}
},
{
"6.0.3",
new List<string>(){
Expand Down
2 changes: 1 addition & 1 deletion UWP.Shared/Helpers/IconsHelper.cs
Expand Up @@ -7,7 +7,7 @@ public class IconsHelper {
/// Get a coin's icon (either from local Asset or from internet)
/// </summary>
/// Old endpoint: chasing-coins.com
public static string GetIcon(string coin) {
public static string GetIcon(string coin = "NULL") {
string filename = "Assets/Icons/icon" + coin + ".png";

if (!File.Exists(filename)) {
Expand Down
20 changes: 2 additions & 18 deletions UWP/Helpers/NumberHelper.cs → UWP.Shared/Helpers/NumberHelper.cs
@@ -1,23 +1,7 @@
using System;

namespace UWP.Helpers {
class NumberHelper {
public static string AddUnitPrefix(double num) {
if (num > 999999999) {
return num.ToString("0,,,.##B", App.UserCulture);
}
else if (num > 999999) {
return num.ToString("0,,.##M", App.UserCulture);
}
else if (num > 999) {
return num.ToString("0,.##K", App.UserCulture);
}
else {
num = Math.Round(num, 3);
return num.ToString(App.UserCulture);
}
}

namespace UWP.Shared.Helpers {
public class NumberHelper {
/// <summary>
/// Round a double with a decimal precision that depends on its value
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions UWP.Shared/Helpers/PortfolioHelper.cs
Expand Up @@ -51,12 +51,12 @@ public class PortfolioHelper {
purchase.Crypto, purchase.Currency);

var curr = purchase.Current;
purchase.Worth = Math.Round(curr * purchase.CryptoQty, 2);
purchase.Worth = NumberHelper.Rounder(curr * purchase.CryptoQty);

/// If the user has also filled the invested quantity, we can calculate everything else
if (purchase.InvestedQty >= 0) {
double priceBought = (1 / purchase.CryptoQty) * purchase.InvestedQty;
priceBought = Math.Round(priceBought, 4);
double priceBought = purchase.InvestedQty / purchase.CryptoQty;
priceBought = NumberHelper.Rounder(priceBought);

var diff = Math.Round((curr - priceBought) * purchase.CryptoQty, 4);

Expand Down
4 changes: 2 additions & 2 deletions UWP.Shared/Models/GlobalStats.cs
@@ -1,7 +1,7 @@
namespace UWP.Models {
public class GlobalStats {
public string TotalMarketCap { get; set; } = "0";
public string TotalVolume { get; set; } = "0";
public double TotalMarketCap { get; set; } = 0;
public double TotalVolume { get; set; } = 0;
public double BtcDominance { get; set; } = 0;
public string CurrencySymbol { get; set; }
}
Expand Down
13 changes: 7 additions & 6 deletions UWP.Shared/Services/ICryptoCompare.cs
Expand Up @@ -24,10 +24,10 @@ public interface ICryptoCompare {
[Get("/data/price?fsym={crypto}&tsyms={currency}")]
Task<string> GetPrice(string crypto, string currency);

[Get("/data/histo{time}?e=CCCAGG&fsym={crypto}&tsym={currency}&limit={limit}")]
[Get("/data/v2/histo{time}?e=CCCAGG&fsym={crypto}&tsym={currency}&limit={limit}")]
Task<object> GetHistoric(string time, string crypto, string currency, int limit, int aggregate = 1);

[Get("/data/histo{time}?e=CCCAGG&fsym={crypto}&tsym={currency}&allData=true")]
[Get("/data/v2/histo{time}?e=CCCAGG&fsym={crypto}&tsym={currency}&allData=true")]
Task<object> GetHistoricAll(string time, string crypto, string currency);

[Get("/data/top/exchanges?fsym={crypto}&tsym={currency}&limit={limit}")]
Expand Down Expand Up @@ -88,13 +88,14 @@ public static class CryptoCompareExtensions {
var response = JsonSerializer.Deserialize<object>(resp.ToString());

var okey = ((JsonElement)response).GetProperty("Response").ToString();
var timeTo = ((JsonElement)response).GetProperty("TimeTo").ToString();
var timeFrom = ((JsonElement)response).GetProperty("TimeFrom").ToString();
var data = ((JsonElement)response).GetProperty("Data");

var timeTo = data.GetProperty("TimeTo").ToString();
var timeFrom = data.GetProperty("TimeFrom").ToString();
if (!okey.Equals("Success", StringComparison.InvariantCultureIgnoreCase) || timeTo == timeFrom)
throw new Exception();

var data = ((JsonElement)response).GetProperty("Data").ToString();
var historic = JsonSerializer.Deserialize<List<HistoricPrice>>(data);
var historic = JsonSerializer.Deserialize<List<HistoricPrice>>(data.GetProperty("Data").ToString());

// Add calculation of dates and average values
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
Expand Down
11 changes: 8 additions & 3 deletions UWP.Shared/Services/LocalSettings.cs
@@ -1,4 +1,5 @@
using UWP.Core.Constants;
using System;
using UWP.Core.Constants;
using Windows.Storage;

namespace UWP.Services {
Expand All @@ -9,8 +10,12 @@ namespace UWP.Services {
public class LocalSettings {

public T Get<T>(string settingKey) {
object result = ApplicationData.Current.LocalSettings.Values[settingKey];
return result == null ? (T)UserSettings.Defaults[settingKey] : (T)result;
try {
object result = ApplicationData.Current.LocalSettings.Values[settingKey];
return result == null ? (T)UserSettings.Defaults[settingKey] : (T)result;
} catch (Exception ex) {
return (T)UserSettings.Defaults[settingKey];
}
}

public void Set<T>(string settingKey, T value) {
Expand Down
1 change: 1 addition & 0 deletions UWP.Shared/UWP.Shared.csproj
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Helpers\AlertsHelper.cs" />
<Compile Include="Helpers\IconsHelper.cs" />
<Compile Include="Helpers\LocalStorageHelper.cs" />
<Compile Include="Helpers\NumberHelper.cs" />
<Compile Include="Helpers\PortfolioHelper.cs" />
<Compile Include="Interfaces\Interfaces.cs" />
<Compile Include="Models\ChartModel.cs" />
Expand Down
7 changes: 3 additions & 4 deletions UWP/APIs/CoinGecko.cs
Expand Up @@ -3,13 +3,12 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading.Tasks;
using UWP.Helpers;
using UWP.Models;
using UWP.Services;
using UWP.Shared.Helpers;

namespace UWP.APIs {
class CoinGecko {
Expand All @@ -34,8 +33,8 @@ class CoinGecko {
);

stats.BtcDominance = Math.Round(btcDominance, 2);
stats.TotalVolume = NumberHelper.AddUnitPrefix(totalVolume);
stats.TotalMarketCap = NumberHelper.AddUnitPrefix(totalMarketCap);
stats.TotalVolume = totalVolume;
stats.TotalMarketCap = totalMarketCap;
stats.CurrencySymbol = App.currencySymbol;
return stats;

Expand Down
20 changes: 17 additions & 3 deletions UWP/Converters/NumberConverters.cs
@@ -1,5 +1,5 @@
using System;
using UWP.Helpers;
using UWP.Shared.Helpers;
using Windows.UI.Xaml.Data;

namespace UWP.Converters {
Expand Down Expand Up @@ -27,8 +27,22 @@ public object ConvertBack(object val, Type targetType, object param, string lang
}

public class NumberUnitSuffixer : IValueConverter {
public object Convert(object val, Type targetType, object param, string lang)
=> NumberHelper.AddUnitPrefix((double)val);
public object Convert(object val, Type targetType, object param, string lang) {
var num = (double)val;
if (num > 999999999) {
return num.ToString("0,,,.##B", App.UserCulture);
}
else if (num > 999999) {
return num.ToString("0,,.##M", App.UserCulture);
}
else if (num > 999) {
return num.ToString("0,.##K", App.UserCulture);
}
else {
num = Math.Round(num, 3);
return num.ToString(App.UserCulture);
}
}
public object ConvertBack(object val, Type targetType, object param, string lang)
=> throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion UWP/Package.appxmanifest
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5">
<Identity Name="54989IsmaelEstalayoMena.CoinBaseUnofficial" Publisher="CN=CE0D17DE-AC9B-4B2D-AE14-FFACDE33BF50" Version="6.0.3.0" />
<Identity Name="54989IsmaelEstalayoMena.CoinBaseUnofficial" Publisher="CN=CE0D17DE-AC9B-4B2D-AE14-FFACDE33BF50" Version="6.0.4.0" />
<mp:PhoneIdentity PhoneProductId="9555542a-b2a3-4742-83ff-1a9b2ec43102" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>CryptoTracker</DisplayName>
Expand Down
4 changes: 2 additions & 2 deletions UWP/Properties/AssemblyInfo.cs
Expand Up @@ -24,6 +24,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.3.0")]
[assembly: AssemblyFileVersion("6.0.3.0")]
[assembly: AssemblyVersion("6.0.4.0")]
[assembly: AssemblyFileVersion("6.0.4.0")]
[assembly: ComVisible(false)]
1 change: 0 additions & 1 deletion UWP/UWP.csproj
Expand Up @@ -123,7 +123,6 @@
<Compile Include="Dialogs\PortfolioEntryDialog.xaml.cs">
<DependentUpon>PortfolioEntryDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\NumberHelper.cs" />
<Compile Include="Helpers\GraphHelper.cs" />
<Compile Include="UserControls\CoinAutoSuggestBox.xaml.cs">
<DependentUpon>CoinAutoSuggestBox.xaml</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion UWP/UserControls/PortfolioList.xaml
Expand Up @@ -95,7 +95,7 @@
<StackPanel Grid.Column="1" Margin="7 0">
<TextBlock d:Text="Crypto" Text="{x:Bind CryptoName}" FontWeight="Bold" Margin="0 0 0 -3"/>
<TextBlock d:Text="0.12 XXX">
<Run Text="{x:Bind CryptoQty}"/>
<Run Text="{x:Bind CryptoQty, Converter={StaticResource NumberFormatter}}"/>
<Run Text="{x:Bind Crypto}"/>
</TextBlock>
</StackPanel>
Expand Down
6 changes: 6 additions & 0 deletions UWP/ViewModels/PortfolioViewModel.cs
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Toolkit.Mvvm.Messaging;
using System;
using System.Collections.ObjectModel;
using UWP.Helpers;
using UWP.Models;

namespace UWP.ViewModels {
Expand Down Expand Up @@ -71,6 +72,11 @@ public class PortfolioViewModel : ObservableRecipient {
get => totalDelta;
set => SetProperty(ref totalDelta, value);
}
private double roi = 0;
public double ROI {
get => roi;
set => SetProperty(ref roi, value);
}


private string allPurchasesCurrencySym = "";
Expand Down
4 changes: 2 additions & 2 deletions UWP/Views/Coins.xaml
Expand Up @@ -95,11 +95,11 @@
d:Text="50.00"/><Run Text="%"/>
</TextBlock>
<TextBlock Grid.Column="1" d:Text="340B€">
<Run Text="{x:Bind vm.GlobalStats.TotalVolume}"/><!--
<Run Text="{x:Bind vm.GlobalStats.TotalVolume, Converter={StaticResource NumberUnit}}"/><!--
--><Run Text="{x:Bind vm.GlobalStats.CurrencySymbol}"/>
</TextBlock>
<TextBlock Grid.Column="2" d:Text="1700B€">
<Run Text="{x:Bind vm.GlobalStats.TotalMarketCap}"/><!--
<Run Text="{x:Bind vm.GlobalStats.TotalMarketCap, Converter={StaticResource NumberUnit}}"/><!--
--><Run Text="{x:Bind vm.GlobalStats.CurrencySymbol}"/>
</TextBlock>
</Grid>
Expand Down

0 comments on commit 2940fc7

Please sign in to comment.