From 1db3ff32d7a00629d0e56301f740640d10134cca Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Wed, 19 Feb 2025 00:31:25 +0200 Subject: [PATCH] Zano asset logo (#2010) * Add Logo to Zano Asset * Add Logo to Zano Assets * fetch zano tokens asset from meta info --- cw_core/lib/zano_asset.dart | 52 +++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/cw_core/lib/zano_asset.dart b/cw_core/lib/zano_asset.dart index edafb4de5..0332f5972 100644 --- a/cw_core/lib/zano_asset.dart +++ b/cw_core/lib/zano_asset.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/hive_type_ids.dart'; import 'package:hive/hive.dart'; @@ -18,6 +20,7 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin { bool _enabled; @HiveField(5) final String? iconPath; + // @HiveField(6) // final String? tag; @HiveField(6) @@ -32,6 +35,8 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin { final BigInt totalMaxSupply; @HiveField(11) final bool isInGlobalWhitelist; + @HiveField(12, defaultValue: null) + final Map? info; bool get enabled => _enabled; @@ -50,7 +55,8 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin { this.hiddenSupply = false, required this.totalMaxSupply, this.isInGlobalWhitelist = false, - }) : _enabled = enabled, + this.info, + }) : _enabled = enabled, super( name: fullName, title: ticker.toUpperCase(), @@ -60,46 +66,54 @@ class ZanoAsset extends CryptoCurrency with HiveObjectMixin { decimals: decimalPoint, ); - ZanoAsset.copyWith(ZanoAsset other, {String? icon, String? assetId, bool enabled = true}) + ZanoAsset.copyWith(ZanoAsset other, {String? assetId, bool enabled = true}) : this.fullName = other.fullName, this.ticker = other.ticker, this.assetId = assetId ?? other.assetId, this.decimalPoint = other.decimalPoint, this._enabled = enabled && other.enabled, - this.iconPath = icon, + this.iconPath = other.iconPath, this.currentSupply = other.currentSupply, this.hiddenSupply = other.hiddenSupply, this.metaInfo = other.metaInfo, this.owner = other.owner, this.totalMaxSupply = other.totalMaxSupply, this.isInGlobalWhitelist = other.isInGlobalWhitelist, + this.info = other.info, super( name: other.name, title: other.ticker.toUpperCase(), fullName: other.name, tag: 'ZANO', - iconPath: icon, + iconPath: other.iconPath, decimals: other.decimalPoint, enabled: enabled, ); - factory ZanoAsset.fromJson(Map json, {bool isInGlobalWhitelist = false}) => ZanoAsset( - assetId: json['asset_id'] as String? ?? '', - currentSupply: bigIntFromDynamic(json['current_supply']), - decimalPoint: json['decimal_point'] as int? ?? 12, - fullName: json['full_name'] as String? ?? '', - hiddenSupply: json['hidden_supply'] as bool? ?? false, - metaInfo: json['meta_info'] as String? ?? '', - owner: json['owner'] as String? ?? '', - ticker: json['ticker'] as String? ?? '', - totalMaxSupply: bigIntFromDynamic(json['total_max_supply']), - isInGlobalWhitelist: isInGlobalWhitelist, - ); - + factory ZanoAsset.fromJson(Map json, {bool isInGlobalWhitelist = false}) { + Map? info; + try { + info = jsonDecode((json['meta_info'] as String?) ?? '{}') as Map?; + } catch (_) {} + return ZanoAsset( + assetId: json['asset_id'] as String? ?? '', + currentSupply: bigIntFromDynamic(json['current_supply']), + decimalPoint: json['decimal_point'] as int? ?? 12, + fullName: json['full_name'] as String? ?? '', + hiddenSupply: json['hidden_supply'] as bool? ?? false, + metaInfo: json['meta_info'] as String? ?? '', + owner: json['owner'] as String? ?? '', + ticker: json['ticker'] as String? ?? '', + iconPath: info?['logo_url'] as String? ?? '', + totalMaxSupply: bigIntFromDynamic(json['total_max_supply']), + isInGlobalWhitelist: isInGlobalWhitelist, + info: info, + ); + } static const typeId = ZANO_ASSET_TYPE_ID; - static const zanoAssetsBoxName = 'zanoAssetsBox'; + static const zanoAssetsBoxName = 'zanoAssetsBox'; static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000'; } @@ -114,4 +128,4 @@ BigInt bigIntFromDynamic(dynamic d) { throw 'cannot cast value of type ${d.runtimeType} to BigInt'; //return BigInt.zero; } -} \ No newline at end of file +}