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

Commit

Permalink
Removed AssetState property from FirstClassAssetItem class (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
justingaffney committed Dec 23, 2017
1 parent 4c0fb44 commit 64491a4
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 137 deletions.
29 changes: 11 additions & 18 deletions Neo.Gui.Base/Controllers/WalletController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public bool CanViewCertificate(FirstClassAssetItem assetItem)
{
if (assetItem == null) return false;

var queryResult = this.GetCertificateQueryResult(assetItem.State.Owner);
var queryResult = this.GetCertificateQueryResult(assetItem.AssetOwner);

if (queryResult == null) return false;

Expand All @@ -396,7 +396,7 @@ public bool CanViewCertificate(FirstClassAssetItem assetItem)

public string ViewCertificate(FirstClassAssetItem assetItem)
{
return this.certificateService.GetCachedCertificatePath(assetItem.State.Owner);
return this.certificateService.GetCachedCertificatePath(assetItem.AssetOwner);
}

public Fixed8 CalculateBonus()
Expand Down Expand Up @@ -626,11 +626,11 @@ public string ToAddress(UInt160 scriptHash)

public void DeleteFirstClassAsset(FirstClassAssetItem assetItem)
{
var value = this.GetAvailable(assetItem.State.AssetId);
var value = this.GetAvailable(assetItem.AssetId);

var transactionOutput = new TransactionOutput
{
AssetId = assetItem.State.AssetId,
AssetId = assetItem.AssetId,
Value = value,
ScriptHash = this.RecycleScriptHash
};
Expand Down Expand Up @@ -985,7 +985,7 @@ private void UpdateFirstClassAssetBalances()

foreach (var asset in this.currentWalletInfo.GetFirstClassAssets())
{
if (assetDictionary.ContainsKey(asset.State.AssetId)) continue;
if (assetDictionary.ContainsKey(asset.AssetId)) continue;

this.currentWalletInfo.RemoveAsset(asset);
}
Expand Down Expand Up @@ -1022,13 +1022,11 @@ private void UpdateFirstClassAssetBalances()
break;
}

var assetItem = new FirstClassAssetItem
var assetItem = new FirstClassAssetItem(asset.Asset.AssetId, asset.Asset.Owner, asset.Asset.AssetType)
{
Name = assetName,
Type = asset.Asset.AssetType.ToString(),
Issuer = $"{Strings.UnknownIssuer}[{asset.Asset.Owner}]",
Value = valueText,
State = asset.Asset
Value = valueText
};

this.currentWalletInfo.AddAsset(assetItem);
Expand Down Expand Up @@ -1086,13 +1084,10 @@ private void UpdateNEP5TokenBalances(TimeSpan timeSinceLastBlock)
}
else
{
var assetItem = new NEP5AssetItem
var assetItem = new NEP5AssetItem(nep5ScriptHash)
{
Name = name,
Type = "NEP-5",
Issuer = $"ScriptHash:{nep5ScriptHash}",
Value = valueText,
ScriptHash = nep5ScriptHash
Value = valueText
};

this.currentWalletInfo.AddAsset(assetItem);
Expand Down Expand Up @@ -1121,11 +1116,9 @@ private void CheckFirstClassAssetIssuerCertificates()
foreach (var asset in this.currentWalletInfo.GetFirstClassAssets()
.Where(item => !item.IssuerCertificateChecked))
{
if (asset.State?.Owner == null) continue;
if (asset.AssetOwner == null) continue;

var assetOwner = asset.State.Owner;

var queryResult = this.GetCertificateQueryResult(assetOwner);
var queryResult = this.GetCertificateQueryResult(asset.AssetOwner);

if (queryResult == null) continue;

Expand Down
18 changes: 3 additions & 15 deletions Neo.Gui.Base/Data/AssetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Neo.Gui.Base.Data
{
public class AssetItem : BindableClass
public abstract class AssetItem : BindableClass
{
private string name;
private string type;
private string value;
private string issuer;

Expand All @@ -22,19 +21,6 @@ public string Name
}
}

public string Type
{
get => this.type;
set
{
if (this.type == value) return;

this.type = value;

NotifyPropertyChanged();
}
}

public string Value
{
get => this.value;
Expand All @@ -60,5 +46,7 @@ public string Issuer
NotifyPropertyChanged();
}
}

public abstract string Type { get; }
}
}
39 changes: 29 additions & 10 deletions Neo.Gui.Base/Data/FirstClassAssetItem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
using Neo.Core;
using Neo.Cryptography.ECC;

using Neo.Gui.Base.Certificates;

using Neo.Gui.Globalization.Resources;

namespace Neo.Gui.Base.Data
{
public class FirstClassAssetItem : AssetItem
{
public FirstClassAssetItem(UInt256 assetId, ECPoint assetOwner, AssetType assetType)
{
this.AssetId = assetId;
this.AssetOwner = assetOwner;
this.AssetType = assetType;
}

public bool IssuerCertificateChecked { get; private set; }

public bool IsSystemAsset => this.State != null &&
(this.State.AssetType == AssetType.GoverningToken ||
this.State.AssetType == AssetType.UtilityToken);
public bool IsSystemAsset =>
this.AssetType == AssetType.GoverningToken ||
this.AssetType == AssetType.UtilityToken;

public override string Type => this.AssetType.ToString();

public UInt256 AssetId { get; }

public ECPoint AssetOwner { get; }

public AssetState State { get; set; }
public AssetType AssetType { get; }

public void SetIssuerCertificateQueryResult(CertificateQueryResult queryResult)
{
Expand All @@ -22,25 +38,28 @@ public void SetIssuerCertificateQueryResult(CertificateQueryResult queryResult)
{
switch (queryResult.Type)
{
case CertificateQueryResultType.Querying:
case CertificateQueryResultType.QueryFailed:
break;
case CertificateQueryResultType.System:
//subitem.ForeColor = Color.Green;
this.Issuer = Strings.SystemIssuer;
break;
case CertificateQueryResultType.Invalid:
//subitem.ForeColor = Color.Red;
this.Issuer = $"[{Strings.InvalidCertificate}][{this.State.Owner}]";
this.Issuer = $"[{Strings.InvalidCertificate}][{this.AssetOwner}]";
break;
case CertificateQueryResultType.Expired:
//subitem.ForeColor = Color.Yellow;
this.Issuer = $"[{Strings.ExpiredCertificate}]{queryResult.Certificate.Subject}[{this.State.Owner}]";
this.Issuer = $"[{Strings.ExpiredCertificate}]{queryResult.Certificate.Subject}[{this.AssetOwner}]";
break;
case CertificateQueryResultType.Good:
//subitem.ForeColor = Color.Black;
this.Issuer = $"{queryResult.Certificate.Subject}[{this.State.Owner}]";
this.Issuer = $"{queryResult.Certificate.Subject}[{this.AssetOwner}]";
break;

case CertificateQueryResultType.Querying:
case CertificateQueryResultType.QueryFailed:
this.Issuer = $"{Strings.UnknownIssuer}[{this.AssetOwner}]";
break;

}

switch (queryResult.Type)
Expand Down
11 changes: 10 additions & 1 deletion Neo.Gui.Base/Data/NEP5AssetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
{
public class NEP5AssetItem : AssetItem
{
public UInt160 ScriptHash { get; set; }
public NEP5AssetItem(UInt160 scriptHash)
{
this.ScriptHash = scriptHash;
}

public new string Issuer => $"ScriptHash:{this.ScriptHash}";

public override string Type => "NEP-5";

public UInt160 ScriptHash { get; }
}
}
2 changes: 1 addition & 1 deletion Neo.Gui.Base/Data/WalletInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public FirstClassAssetItem GetFirstClassAsset(UInt256 assetId)
if (assetId == null) return null;

return this.assets.FirstOrDefault(asset => asset is FirstClassAssetItem &&
assetId.Equals(((FirstClassAssetItem) asset).State?.AssetId)) as FirstClassAssetItem;
assetId.Equals(((FirstClassAssetItem) asset).AssetId)) as FirstClassAssetItem;
}

public NEP5AssetItem GetNEP5Asset(UInt160 scriptHash)
Expand Down
84 changes: 0 additions & 84 deletions Neo.Gui.ViewModels.Tests/Builders/AssetItemBuilder.cs

This file was deleted.

70 changes: 70 additions & 0 deletions Neo.Gui.ViewModels.Tests/Builders/FirstClassAssetItemBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Neo.Core;
using Neo.Cryptography.ECC;

using Neo.Gui.Base.Data;

namespace Neo.Gui.ViewModels.Tests.Builders
{
// TODO Add NEP5AssetItemBuilder class
public class FirstClassAssetItemBuilder
{
private string internalName = "Name";
private string internalValue = "Value";
private string internalIssuer = "Issuer";
private UInt256 internalAssetId = UInt256.Parse("0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF");
private ECPoint internalAssetOwner = new ECPoint();
private AssetType internalAssetType = AssetType.Token;

public FirstClassAssetItemBuilder WithName(string name)
{
this.internalName = name;
return this;
}

public FirstClassAssetItemBuilder WithValue(string value)
{
this.internalValue = value;
return this;
}

public FirstClassAssetItemBuilder WithIssuer(string issuer)
{
this.internalIssuer = issuer;
return this;
}

public FirstClassAssetItemBuilder WithGoverningToken()
{
this.internalAssetType = AssetType.GoverningToken;
return this;
}

public FirstClassAssetItemBuilder WithUtilityToken()
{
this.internalAssetType = AssetType.UtilityToken;
return this;
}

public FirstClassAssetItemBuilder WithCustomToken()
{
this.internalAssetOwner = new ECPoint();
return this;
}

public FirstClassAssetItemBuilder WithAssetId(UInt256 assetId)
{
this.internalAssetId = assetId;
return this;
}

public AssetItem Build()
{
return new FirstClassAssetItem(this.internalAssetId, this.internalAssetOwner, this.internalAssetType)
{
Name = this.internalName,
Value = this.internalValue,
Issuer = this.internalIssuer
};
}
}
}
Loading

0 comments on commit 64491a4

Please sign in to comment.