From 7b5b1070585ee2d3a01590521acea355e61738cb Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Mon, 23 Dec 2024 14:18:11 +0100 Subject: [PATCH] fix monero.com builds --- cw_core/lib/zano_asset.dart | 117 ++++++++++++++++++++++++++++ cw_zano/lib/api/model/balance.dart | 1 + cw_zano/lib/api/model/transfer.dart | 1 + cw_zano/lib/model/zano_asset.dart | 105 ------------------------- cw_zano/lib/zano_wallet.dart | 1 + cw_zano/lib/zano_wallet_api.dart | 1 + lib/zano/cw_zano.dart | 2 +- tool/configure.dart | 2 +- 8 files changed, 123 insertions(+), 107 deletions(-) create mode 100644 cw_core/lib/zano_asset.dart diff --git a/cw_core/lib/zano_asset.dart b/cw_core/lib/zano_asset.dart new file mode 100644 index 000000000..edafb4de5 --- /dev/null +++ b/cw_core/lib/zano_asset.dart @@ -0,0 +1,117 @@ +import 'package:cw_core/crypto_currency.dart'; +import 'package:cw_core/hive_type_ids.dart'; +import 'package:hive/hive.dart'; + +part 'zano_asset.g.dart'; + +@HiveType(typeId: ZanoAsset.typeId) +class ZanoAsset extends CryptoCurrency with HiveObjectMixin { + @HiveField(0) + final String fullName; + @HiveField(1) + final String ticker; + @HiveField(2) + final String assetId; + @HiveField(3) + final int decimalPoint; + @HiveField(4, defaultValue: true) + bool _enabled; + @HiveField(5) + final String? iconPath; + // @HiveField(6) + // final String? tag; + @HiveField(6) + final String owner; + @HiveField(7) + final String metaInfo; + @HiveField(8) + final BigInt currentSupply; + @HiveField(9) + final bool hiddenSupply; + @HiveField(10) + final BigInt totalMaxSupply; + @HiveField(11) + final bool isInGlobalWhitelist; + + bool get enabled => _enabled; + + set enabled(bool value) => _enabled = value; + + ZanoAsset({ + this.fullName = '', + this.ticker = '', + required this.assetId, + this.decimalPoint = 12, + bool enabled = true, + this.iconPath, + this.owner = defaultOwner, + this.metaInfo = '', + required this.currentSupply, + this.hiddenSupply = false, + required this.totalMaxSupply, + this.isInGlobalWhitelist = false, + }) : _enabled = enabled, + super( + name: fullName, + title: ticker.toUpperCase(), + fullName: fullName, + tag: 'ZANO', + iconPath: iconPath, + decimals: decimalPoint, + ); + + ZanoAsset.copyWith(ZanoAsset other, {String? icon, 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.currentSupply = other.currentSupply, + this.hiddenSupply = other.hiddenSupply, + this.metaInfo = other.metaInfo, + this.owner = other.owner, + this.totalMaxSupply = other.totalMaxSupply, + this.isInGlobalWhitelist = other.isInGlobalWhitelist, + super( + name: other.name, + title: other.ticker.toUpperCase(), + fullName: other.name, + tag: 'ZANO', + iconPath: icon, + 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, + ); + + + + static const typeId = ZANO_ASSET_TYPE_ID; + static const zanoAssetsBoxName = 'zanoAssetsBox'; + static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000'; +} + +BigInt bigIntFromDynamic(dynamic d) { + if (d is int) { + return BigInt.from(d); + } else if (d is BigInt) { + return d; + } else if (d == null) { + return BigInt.zero; + } else { + throw 'cannot cast value of type ${d.runtimeType} to BigInt'; + //return BigInt.zero; + } +} \ No newline at end of file diff --git a/cw_zano/lib/api/model/balance.dart b/cw_zano/lib/api/model/balance.dart index 8ea48d2a4..b796338fb 100644 --- a/cw_zano/lib/api/model/balance.dart +++ b/cw_zano/lib/api/model/balance.dart @@ -1,3 +1,4 @@ +import 'package:cw_core/zano_asset.dart'; import 'package:cw_zano/model/zano_asset.dart'; import 'package:cw_zano/zano_formatter.dart'; diff --git a/cw_zano/lib/api/model/transfer.dart b/cw_zano/lib/api/model/transfer.dart index 460afcfef..1d46ca8b3 100644 --- a/cw_zano/lib/api/model/transfer.dart +++ b/cw_zano/lib/api/model/transfer.dart @@ -1,3 +1,4 @@ +import 'package:cw_core/zano_asset.dart'; import 'package:cw_zano/api/model/employed_entries.dart'; import 'package:cw_zano/api/model/subtransfer.dart'; import 'package:collection/collection.dart'; diff --git a/cw_zano/lib/model/zano_asset.dart b/cw_zano/lib/model/zano_asset.dart index 58f53738e..e69de29bb 100644 --- a/cw_zano/lib/model/zano_asset.dart +++ b/cw_zano/lib/model/zano_asset.dart @@ -1,105 +0,0 @@ -import 'package:cw_core/crypto_currency.dart'; -import 'package:cw_core/hive_type_ids.dart'; -import 'package:cw_zano/zano_formatter.dart'; -import 'package:hive/hive.dart'; - -part 'zano_asset.g.dart'; - -@HiveType(typeId: ZanoAsset.typeId) -class ZanoAsset extends CryptoCurrency with HiveObjectMixin { - @HiveField(0) - final String fullName; - @HiveField(1) - final String ticker; - @HiveField(2) - final String assetId; - @HiveField(3) - final int decimalPoint; - @HiveField(4, defaultValue: true) - bool _enabled; - @HiveField(5) - final String? iconPath; - // @HiveField(6) - // final String? tag; - @HiveField(6) - final String owner; - @HiveField(7) - final String metaInfo; - @HiveField(8) - final BigInt currentSupply; - @HiveField(9) - final bool hiddenSupply; - @HiveField(10) - final BigInt totalMaxSupply; - @HiveField(11) - final bool isInGlobalWhitelist; - - bool get enabled => _enabled; - - set enabled(bool value) => _enabled = value; - - ZanoAsset({ - this.fullName = '', - this.ticker = '', - required this.assetId, - this.decimalPoint = ZanoFormatter.defaultDecimalPoint, - bool enabled = true, - this.iconPath, - this.owner = defaultOwner, - this.metaInfo = '', - required this.currentSupply, - this.hiddenSupply = false, - required this.totalMaxSupply, - this.isInGlobalWhitelist = false, - }) : _enabled = enabled, - super( - name: fullName, - title: ticker.toUpperCase(), - fullName: fullName, - tag: 'ZANO', - iconPath: iconPath, - decimals: decimalPoint, - ); - - ZanoAsset.copyWith(ZanoAsset other, {String? icon, 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.currentSupply = other.currentSupply, - this.hiddenSupply = other.hiddenSupply, - this.metaInfo = other.metaInfo, - this.owner = other.owner, - this.totalMaxSupply = other.totalMaxSupply, - this.isInGlobalWhitelist = other.isInGlobalWhitelist, - super( - name: other.name, - title: other.ticker.toUpperCase(), - fullName: other.name, - tag: 'ZANO', - iconPath: icon, - decimals: other.decimalPoint, - enabled: enabled, - ); - - factory ZanoAsset.fromJson(Map json, {bool isInGlobalWhitelist = false}) => ZanoAsset( - assetId: json['asset_id'] as String? ?? '', - currentSupply: ZanoFormatter.bigIntFromDynamic(json['current_supply']), - decimalPoint: json['decimal_point'] as int? ?? ZanoFormatter.defaultDecimalPoint, - 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: ZanoFormatter.bigIntFromDynamic(json['total_max_supply']), - isInGlobalWhitelist: isInGlobalWhitelist, - ); - - - - static const typeId = ZANO_ASSET_TYPE_ID; - static const zanoAssetsBoxName = 'zanoAssetsBox'; - static const defaultOwner = '0000000000000000000000000000000000000000000000000000000000000000'; -} diff --git a/cw_zano/lib/zano_wallet.dart b/cw_zano/lib/zano_wallet.dart index c1abe4083..368d53e91 100644 --- a/cw_zano/lib/zano_wallet.dart +++ b/cw_zano/lib/zano_wallet.dart @@ -12,6 +12,7 @@ import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; +import 'package:cw_core/zano_asset.dart'; import 'package:cw_zano/api/model/create_wallet_result.dart'; import 'package:cw_zano/api/model/destination.dart'; import 'package:cw_zano/api/model/get_recent_txs_and_info_result.dart'; diff --git a/cw_zano/lib/zano_wallet_api.dart b/cw_zano/lib/zano_wallet_api.dart index e2e202600..b7f8629e1 100644 --- a/cw_zano/lib/zano_wallet_api.dart +++ b/cw_zano/lib/zano_wallet_api.dart @@ -5,6 +5,7 @@ import 'dart:isolate'; import 'package:cw_core/pathForWallet.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/utils/print_verbose.dart'; +import 'package:cw_core/zano_asset.dart'; import 'package:cw_zano/api/consts.dart'; import 'package:cw_zano/api/model/asset_id_params.dart'; import 'package:cw_zano/api/model/create_wallet_result.dart'; diff --git a/lib/zano/cw_zano.dart b/lib/zano/cw_zano.dart index 114cbac86..8bdf30e87 100644 --- a/lib/zano/cw_zano.dart +++ b/lib/zano/cw_zano.dart @@ -133,7 +133,7 @@ class CWZano extends Zano { return CryptoCurrency.zano; } wallet as ZanoWallet; - final asset = wallet.zanoAssets.values.firstWhereOrNull((element) => element.ticker == transaction.tokenSymbol); + final asset = wallet.zanoAssets.values.firstWhereOrNull((element) => element?.ticker == transaction.tokenSymbol); return asset ?? CryptoCurrency.zano; } diff --git a/tool/configure.dart b/tool/configure.dart index 94367e61e..3c684f6bb 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -1419,11 +1419,11 @@ import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_service.dart'; +import 'package:cw_core/zano_asset.dart'; import 'package:hive/hive.dart'; """; const zanoCWHeaders = """ import 'package:cw_zano/mnemonics/english.dart'; -import 'package:cw_zano/model/zano_asset.dart'; import 'package:cw_zano/model/zano_transaction_credentials.dart'; import 'package:cw_zano/model/zano_transaction_info.dart'; import 'package:cw_zano/zano_formatter.dart';