diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e1441..a0ca37f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Changelog ========= + +#### Version 1.2.13 +* Add Bitcoin in ucids_tokens config file +* #### Version 1.2.12 * Update dependencies diff --git a/lib/src/application/coin_price.dart b/lib/src/application/coin_price.dart index 7d41978..82dca14 100644 --- a/lib/src/application/coin_price.dart +++ b/lib/src/application/coin_price.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:archethic_dapp_framework_flutter/src/application/ucids_tokens.dart'; import 'package:archethic_dapp_framework_flutter/src/domain/models/crypto_price.dart'; +import 'package:archethic_dapp_framework_flutter/src/domain/models/ucid.dart'; import 'package:http/http.dart' as http; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -30,15 +31,8 @@ class _CoinPriceNotifier extends Notifier { } Future fetchPrices() async { - // UCIDs - // 3890 : MATIC - // 1027 : Ethereum - // 1839 : BNB - // 3408 : USDC - // 20920 : Monerium EURe - const url = - 'https://fas.archethic.net/api/v1/quotes/latest?ucids=1027,3890,1839,3408,20920'; + 'https://fas.archethic.net/api/v1/quotes/latest?ucids=1027,3890,1839,3408,20920,1'; final headers = { 'Content-type': 'application/json', 'Accept': 'application/json', @@ -69,11 +63,12 @@ class _CoinPriceNotifier extends Notifier { Map _extractPriceMethods(String responseBody) { final jsonData = json.decode(responseBody) as Map; return { - 'matic': jsonData['3890'], - 'ethereum': jsonData['1027'], - 'bnb': jsonData['1839'], - 'usdc': jsonData['3408'], - 'eure': jsonData['20920'], + 'bitcoin': jsonData[UCID.bitcoin.toString()], + 'matic': jsonData[UCID.matic.toString()], + 'ethereum': jsonData[UCID.ethereum.toString()], + 'bnb': jsonData[UCID.bnb.toString()], + 'usdc': jsonData[UCID.usdc.toString()], + 'eure': jsonData[UCID.eure.toString()], }; } } @@ -91,15 +86,17 @@ double _coinPriceFromAddress( final ucid = ucidsList[address.toUpperCase()] ?? 0; if (ucid != 0) { switch (ucid) { - case 1027: + case UCID.bitcoin: + return coinPrice.bitcoin; + case UCID.ethereum: return coinPrice.ethereum; - case 1839: + case UCID.bnb: return coinPrice.bnb; - case 3890: + case UCID.matic: return coinPrice.matic; - case 3408: + case UCID.usdc: return coinPrice.usdc; - case 20920: + case UCID.eure: return coinPrice.eure; default: return 0; diff --git a/lib/src/application/coin_price.g.dart b/lib/src/application/coin_price.g.dart index 57bd379..fdb407f 100644 --- a/lib/src/application/coin_price.g.dart +++ b/lib/src/application/coin_price.g.dart @@ -7,7 +7,7 @@ part of 'coin_price.dart'; // ************************************************************************** String _$coinPriceFromAddressHash() => - r'd4cf14e2e2e1fd34deef8c581223ffa4061133fc'; + r'f70fc08512773ba431ad574ba14b2dfa8028c3c7'; /// Copied from Dart SDK class _SystemHash { @@ -156,7 +156,7 @@ class _CoinPriceFromAddressProviderElement String get address => (origin as _CoinPriceFromAddressProvider).address; } -String _$coinPriceNotifierHash() => r'f94183cf325bd219b2a840ed16c28e692618119d'; +String _$coinPriceNotifierHash() => r'7d65d3f7305007fd65b98eda0b012ad0ccd380a0'; /// See also [_CoinPriceNotifier]. @ProviderFor(_CoinPriceNotifier) diff --git a/lib/src/domain/models/crypto_price.dart b/lib/src/domain/models/crypto_price.dart index d5b822b..c62e4eb 100644 --- a/lib/src/domain/models/crypto_price.dart +++ b/lib/src/domain/models/crypto_price.dart @@ -7,12 +7,12 @@ part 'crypto_price.g.dart'; class CryptoPrice with _$CryptoPrice { factory CryptoPrice({ int? timestamp, - // Used UCIDs - @Default(0.0) double matic, // 3890 - @Default(0.0) double ethereum, // 1027 - @Default(0.0) double bnb, // 1839 - @Default(0.0) double usdc, // 3408 - @Default(0.0) double eure, // 20920 + @Default(0.0) double bitcoin, + @Default(0.0) double matic, + @Default(0.0) double ethereum, + @Default(0.0) double bnb, + @Default(0.0) double usdc, + @Default(0.0) double eure, }) = _CryptoPrice; factory CryptoPrice.fromJson(Map json) => diff --git a/lib/src/domain/models/crypto_price.freezed.dart b/lib/src/domain/models/crypto_price.freezed.dart index ef29d12..e677891 100644 --- a/lib/src/domain/models/crypto_price.freezed.dart +++ b/lib/src/domain/models/crypto_price.freezed.dart @@ -21,6 +21,7 @@ CryptoPrice _$CryptoPriceFromJson(Map json) { /// @nodoc mixin _$CryptoPrice { int? get timestamp => throw _privateConstructorUsedError; // Used UCIDs + double get bitcoin => throw _privateConstructorUsedError; // 1 double get matic => throw _privateConstructorUsedError; // 3890 double get ethereum => throw _privateConstructorUsedError; // 1027 double get bnb => throw _privateConstructorUsedError; // 1839 @@ -41,6 +42,7 @@ abstract class $CryptoPriceCopyWith<$Res> { @useResult $Res call( {int? timestamp, + double bitcoin, double matic, double ethereum, double bnb, @@ -62,6 +64,7 @@ class _$CryptoPriceCopyWithImpl<$Res, $Val extends CryptoPrice> @override $Res call({ Object? timestamp = freezed, + Object? bitcoin = null, Object? matic = null, Object? ethereum = null, Object? bnb = null, @@ -73,6 +76,10 @@ class _$CryptoPriceCopyWithImpl<$Res, $Val extends CryptoPrice> ? _value.timestamp : timestamp // ignore: cast_nullable_to_non_nullable as int?, + bitcoin: null == bitcoin + ? _value.bitcoin + : bitcoin // ignore: cast_nullable_to_non_nullable + as double, matic: null == matic ? _value.matic : matic // ignore: cast_nullable_to_non_nullable @@ -107,6 +114,7 @@ abstract class _$$CryptoPriceImplCopyWith<$Res> @useResult $Res call( {int? timestamp, + double bitcoin, double matic, double ethereum, double bnb, @@ -126,6 +134,7 @@ class __$$CryptoPriceImplCopyWithImpl<$Res> @override $Res call({ Object? timestamp = freezed, + Object? bitcoin = null, Object? matic = null, Object? ethereum = null, Object? bnb = null, @@ -137,6 +146,10 @@ class __$$CryptoPriceImplCopyWithImpl<$Res> ? _value.timestamp : timestamp // ignore: cast_nullable_to_non_nullable as int?, + bitcoin: null == bitcoin + ? _value.bitcoin + : bitcoin // ignore: cast_nullable_to_non_nullable + as double, matic: null == matic ? _value.matic : matic // ignore: cast_nullable_to_non_nullable @@ -166,6 +179,7 @@ class __$$CryptoPriceImplCopyWithImpl<$Res> class _$CryptoPriceImpl implements _CryptoPrice { _$CryptoPriceImpl( {this.timestamp, + this.bitcoin = 0.0, this.matic = 0.0, this.ethereum = 0.0, this.bnb = 0.0, @@ -178,6 +192,10 @@ class _$CryptoPriceImpl implements _CryptoPrice { @override final int? timestamp; // Used UCIDs + @override + @JsonKey() + final double bitcoin; +// 1 @override @JsonKey() final double matic; @@ -200,7 +218,7 @@ class _$CryptoPriceImpl implements _CryptoPrice { @override String toString() { - return 'CryptoPrice(timestamp: $timestamp, matic: $matic, ethereum: $ethereum, bnb: $bnb, usdc: $usdc, eure: $eure)'; + return 'CryptoPrice(timestamp: $timestamp, bitcoin: $bitcoin, matic: $matic, ethereum: $ethereum, bnb: $bnb, usdc: $usdc, eure: $eure)'; } @override @@ -210,6 +228,7 @@ class _$CryptoPriceImpl implements _CryptoPrice { other is _$CryptoPriceImpl && (identical(other.timestamp, timestamp) || other.timestamp == timestamp) && + (identical(other.bitcoin, bitcoin) || other.bitcoin == bitcoin) && (identical(other.matic, matic) || other.matic == matic) && (identical(other.ethereum, ethereum) || other.ethereum == ethereum) && @@ -220,8 +239,8 @@ class _$CryptoPriceImpl implements _CryptoPrice { @JsonKey(ignore: true) @override - int get hashCode => - Object.hash(runtimeType, timestamp, matic, ethereum, bnb, usdc, eure); + int get hashCode => Object.hash( + runtimeType, timestamp, bitcoin, matic, ethereum, bnb, usdc, eure); @JsonKey(ignore: true) @override @@ -240,6 +259,7 @@ class _$CryptoPriceImpl implements _CryptoPrice { abstract class _CryptoPrice implements CryptoPrice { factory _CryptoPrice( {final int? timestamp, + final double bitcoin, final double matic, final double ethereum, final double bnb, @@ -252,6 +272,8 @@ abstract class _CryptoPrice implements CryptoPrice { @override int? get timestamp; @override // Used UCIDs + double get bitcoin; + @override // 1 double get matic; @override // 3890 double get ethereum; diff --git a/lib/src/domain/models/crypto_price.g.dart b/lib/src/domain/models/crypto_price.g.dart index 71fd9f7..5531d9e 100644 --- a/lib/src/domain/models/crypto_price.g.dart +++ b/lib/src/domain/models/crypto_price.g.dart @@ -9,6 +9,7 @@ part of 'crypto_price.dart'; _$CryptoPriceImpl _$$CryptoPriceImplFromJson(Map json) => _$CryptoPriceImpl( timestamp: (json['timestamp'] as num?)?.toInt(), + bitcoin: (json['bitcoin'] as num?)?.toDouble() ?? 0.0, matic: (json['matic'] as num?)?.toDouble() ?? 0.0, ethereum: (json['ethereum'] as num?)?.toDouble() ?? 0.0, bnb: (json['bnb'] as num?)?.toDouble() ?? 0.0, @@ -19,6 +20,7 @@ _$CryptoPriceImpl _$$CryptoPriceImplFromJson(Map json) => Map _$$CryptoPriceImplToJson(_$CryptoPriceImpl instance) => { 'timestamp': instance.timestamp, + 'bitcoin': instance.bitcoin, 'matic': instance.matic, 'ethereum': instance.ethereum, 'bnb': instance.bnb, diff --git a/lib/src/domain/models/ucid.dart b/lib/src/domain/models/ucid.dart new file mode 100644 index 0000000..8457ff2 --- /dev/null +++ b/lib/src/domain/models/ucid.dart @@ -0,0 +1,8 @@ +abstract class UCID { + static const bitcoin = 1; + static const matic = 3890; + static const ethereum = 1027; + static const bnb = 1839; + static const usdc = 3408; + static const eure = 20920; +} diff --git a/lib/src/domain/repositories/tokens/ucids_tokens.json b/lib/src/domain/repositories/tokens/ucids_tokens.json index 69517ea..416ebeb 100644 --- a/lib/src/domain/repositories/tokens/ucids_tokens.json +++ b/lib/src/domain/repositories/tokens/ucids_tokens.json @@ -1,7 +1,8 @@ { "mainnet": { "0000457EACA7FBAA96DB4A8D506A0B69684F546166FBF3C55391B1461907EFA58EAF": 1027, - "00005751A05BA007E7E2518DEA171DBBD67B0527C637232F923830C39BFF9E8F159A": 20920 + "00005751A05BA007E7E2518DEA171DBBD67B0527C637232F923830C39BFF9E8F159A": 20920, + "00002CEC79D588D5CDD24331968BEF0A9CFE8B1B03B8AEFC4454726DEF79AA10C125": 1 }, "testnet": { "00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1": 3890, diff --git a/pubspec.yaml b/pubspec.yaml index 2236214..1a801ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: archethic_dapp_framework_flutter description: An internal framework for archethic flutter development homepage: https://github.com/archethic-foundation/archethic-dapp-framework-flutter -version: 1.2.12 +version: 1.2.13 environment: sdk: ">=3.3.0 <4.0.0"