Zano asset logo (#2010)

* Add Logo to Zano Asset * Add Logo to Zano Assets * fetch zano tokens asset from meta info

Omar Hatem committed Feb 19, 2025 at 00:31 UTC 1db3ff32d7a00629d0e56301f740640d10134cca
1 file changed +33 -19
cw_core/lib/zano_asset.dart
+33 -19
@@ -1,3 +1,5 @@
1 +import 'dart:convert';
2 +
3 import 'package:cw_core/crypto_currency.dart';
4 import 'package:cw_core/hive_type_ids.dart';
5 import 'package:hive/hive.dart';
@@ -18,6 +20,7 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
20 bool _enabled;
21 @HiveField(5)
22 final String? iconPath;
23 +
24 // @HiveField(6)
25 // final String? tag;
26 @HiveField(6)
@@ -32,6 +35,8 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
35 final BigInt totalMaxSupply;
36 @HiveField(11)
37 final bool isInGlobalWhitelist;
38 + @HiveField(12, defaultValue: null)
39 + final Map<String, dynamic>? info;
40
41 bool get enabled => _enabled;
42
@@ -50,7 +55,8 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
55 this.hiddenSupply = false,
56 required this.totalMaxSupply,
57 this.isInGlobalWhitelist = false,
53 - }) : _enabled = enabled,
58 + this.info,
59 + }) : _enabled = enabled,
60 super(
61 name: fullName,
62 title: ticker.toUpperCase(),
@@ -60,46 +66,54 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin {
66 decimals: decimalPoint,
67 );
68
63 - ZanoAsset.copyWith(ZanoAsset other, {String? icon, String? assetId, bool enabled = true})
69 + ZanoAsset.copyWith(ZanoAsset other, {String? assetId, bool enabled = true})
70 : this.fullName = other.fullName,
71 this.ticker = other.ticker,
72 this.assetId = assetId ?? other.assetId,
73 this.decimalPoint = other.decimalPoint,
74 this._enabled = enabled && other.enabled,
69 - this.iconPath = icon,
75 + this.iconPath = other.iconPath,
76 this.currentSupply = other.currentSupply,
77 this.hiddenSupply = other.hiddenSupply,
78 this.metaInfo = other.metaInfo,
79 this.owner = other.owner,
80 this.totalMaxSupply = other.totalMaxSupply,
81 this.isInGlobalWhitelist = other.isInGlobalWhitelist,
82 + this.info = other.info,
83 super(
84 name: other.name,
85 title: other.ticker.toUpperCase(),
86 fullName: other.name,
87 tag: 'ZANO',
81 - iconPath: icon,
88 + iconPath: other.iconPath,
89 decimals: other.decimalPoint,
90 enabled: enabled,
91 );
92
86 - factory ZanoAsset.fromJson(Map<String, dynamic> json, {bool isInGlobalWhitelist = false}) => ZanoAsset(
87 - assetId: json['asset_id'] as String? ?? '',
88 - currentSupply: bigIntFromDynamic(json['current_supply']),
89 - decimalPoint: json['decimal_point'] as int? ?? 12,
90 - fullName: json['full_name'] as String? ?? '',
91 - hiddenSupply: json['hidden_supply'] as bool? ?? false,
92 - metaInfo: json['meta_info'] as String? ?? '',
93 - owner: json['owner'] as String? ?? '',
94 - ticker: json['ticker'] as String? ?? '',
95 - totalMaxSupply: bigIntFromDynamic(json['total_max_supply']),
96 - isInGlobalWhitelist: isInGlobalWhitelist,
97 - );
98 -
93 + factory ZanoAsset.fromJson(Map<String, dynamic> json, {bool isInGlobalWhitelist = false}) {
94 + Map<String, dynamic>? info;
95 + try {
96 + info = jsonDecode((json['meta_info'] as String?) ?? '{}') as Map<String, dynamic>?;
97 + } catch (_) {}
98
99 + return ZanoAsset(
100 + assetId: json['asset_id'] as String? ?? '',
101 + currentSupply: bigIntFromDynamic(json['current_supply']),
102 + decimalPoint: json['decimal_point'] as int? ?? 12,
103 + fullName: json['full_name'] as String? ?? '',
104 + hiddenSupply: json['hidden_supply'] as bool? ?? false,
105 + metaInfo: json['meta_info'] as String? ?? '',
106 + owner: json['owner'] as String? ?? '',
107 + ticker: json['ticker'] as String? ?? '',
108 + iconPath: info?['logo_url'] as String? ?? '',
109 + totalMaxSupply: bigIntFromDynamic(json['total_max_supply']),
110 + isInGlobalWhitelist: isInGlobalWhitelist,
111 + info: info,
112 + );
113 + }
114
115 static const typeId = ZANO_ASSET_TYPE_ID;
102 - static const zanoAssetsBoxName = 'zanoAssetsBox';
116 + static const zanoAssetsBoxName = 'zanoAssetsBox';
117 static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000';
118 }
119
@@ -114,4 +128,4 @@ BigInt bigIntFromDynamic(dynamic d) {
128 throw 'cannot cast value of type ${d.runtimeType} to BigInt';
129 //return BigInt.zero;
130 }
117 -}
\ No newline at end of file
131 +}