From c6cd6d9fb73ae02b2a3ab6fe58b68de8452e4a29 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Sun, 4 Aug 2024 16:44:14 +0200 Subject: [PATCH 1/4] feat: :sparkles: Add Bitcoin in ucids_tokens config file --- CHANGELOG.md | 1 + lib/src/application/coin_price.dart | 6 +++- lib/src/application/coin_price.g.dart | 4 +-- lib/src/domain/models/crypto_price.dart | 1 + .../domain/models/crypto_price.freezed.dart | 28 +++++++++++++++++-- lib/src/domain/models/crypto_price.g.dart | 2 ++ .../repositories/tokens/ucids_tokens.json | 6 ++-- 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e1441..41bce7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ Changelog ========= + #### Version 1.2.12 * Update dependencies diff --git a/lib/src/application/coin_price.dart b/lib/src/application/coin_price.dart index 7d41978..01e3b41 100644 --- a/lib/src/application/coin_price.dart +++ b/lib/src/application/coin_price.dart @@ -31,6 +31,7 @@ class _CoinPriceNotifier extends Notifier { Future fetchPrices() async { // UCIDs + // 1 : BTC // 3890 : MATIC // 1027 : Ethereum // 1839 : BNB @@ -38,7 +39,7 @@ class _CoinPriceNotifier extends Notifier { // 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,6 +70,7 @@ class _CoinPriceNotifier extends Notifier { Map _extractPriceMethods(String responseBody) { final jsonData = json.decode(responseBody) as Map; return { + 'bitcoin': jsonData['1'], 'matic': jsonData['3890'], 'ethereum': jsonData['1027'], 'bnb': jsonData['1839'], @@ -91,6 +93,8 @@ double _coinPriceFromAddress( final ucid = ucidsList[address.toUpperCase()] ?? 0; if (ucid != 0) { switch (ucid) { + case 1: + return coinPrice.bitcoin; case 1027: return coinPrice.ethereum; case 1839: 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..057bb99 100644 --- a/lib/src/domain/models/crypto_price.dart +++ b/lib/src/domain/models/crypto_price.dart @@ -8,6 +8,7 @@ class CryptoPrice with _$CryptoPrice { factory CryptoPrice({ int? timestamp, // Used UCIDs + @Default(0.0) double bitcoin, // 1 @Default(0.0) double matic, // 3890 @Default(0.0) double ethereum, // 1027 @Default(0.0) double bnb, // 1839 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/repositories/tokens/ucids_tokens.json b/lib/src/domain/repositories/tokens/ucids_tokens.json index 69517ea..a13ad72 100644 --- a/lib/src/domain/repositories/tokens/ucids_tokens.json +++ b/lib/src/domain/repositories/tokens/ucids_tokens.json @@ -1,13 +1,15 @@ { "mainnet": { "0000457EACA7FBAA96DB4A8D506A0B69684F546166FBF3C55391B1461907EFA58EAF": 1027, - "00005751A05BA007E7E2518DEA171DBBD67B0527C637232F923830C39BFF9E8F159A": 20920 + "00005751A05BA007E7E2518DEA171DBBD67B0527C637232F923830C39BFF9E8F159A": 20920, + "": 1 }, "testnet": { "00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1": 3890, "00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4": 1027, "0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827": 1839, - "00001ED63AC2850CEA282D3D0CA5047418BC2720CB49D15B611D2845611F605716A1": 20920 + "00001ED63AC2850CEA282D3D0CA5047418BC2720CB49D15B611D2845611F605716A1": 20920, + "": 1 }, "devnet": { "00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1": 3890, From a78b57f08f40d4ce07836b583f7db0a81bd1aa5f Mon Sep 17 00:00:00 2001 From: Chralu Date: Mon, 5 Aug 2024 14:17:29 +0200 Subject: [PATCH 2/4] refactor: Use constants for UCIDs. --- lib/src/application/coin_price.dart | 33 ++++++++++--------------- lib/src/domain/models/crypto_price.dart | 13 +++++----- lib/src/domain/models/ucid.dart | 8 ++++++ 3 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 lib/src/domain/models/ucid.dart diff --git a/lib/src/application/coin_price.dart b/lib/src/application/coin_price.dart index 01e3b41..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,14 +31,6 @@ class _CoinPriceNotifier extends Notifier { } Future fetchPrices() async { - // UCIDs - // 1 : BTC - // 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,1'; final headers = { @@ -70,12 +63,12 @@ class _CoinPriceNotifier extends Notifier { Map _extractPriceMethods(String responseBody) { final jsonData = json.decode(responseBody) as Map; return { - 'bitcoin': jsonData['1'], - '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()], }; } } @@ -93,17 +86,17 @@ double _coinPriceFromAddress( final ucid = ucidsList[address.toUpperCase()] ?? 0; if (ucid != 0) { switch (ucid) { - case 1: + case UCID.bitcoin: return coinPrice.bitcoin; - case 1027: + 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/domain/models/crypto_price.dart b/lib/src/domain/models/crypto_price.dart index 057bb99..c62e4eb 100644 --- a/lib/src/domain/models/crypto_price.dart +++ b/lib/src/domain/models/crypto_price.dart @@ -7,13 +7,12 @@ part 'crypto_price.g.dart'; class CryptoPrice with _$CryptoPrice { factory CryptoPrice({ int? timestamp, - // Used UCIDs - @Default(0.0) double bitcoin, // 1 - @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/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; +} From 681165d28ee4dd90c4cd253772c8195aec1744a6 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Wed, 14 Aug 2024 13:21:11 +0200 Subject: [PATCH 3/4] Add BTC token address --- lib/src/domain/repositories/tokens/ucids_tokens.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/domain/repositories/tokens/ucids_tokens.json b/lib/src/domain/repositories/tokens/ucids_tokens.json index a13ad72..416ebeb 100644 --- a/lib/src/domain/repositories/tokens/ucids_tokens.json +++ b/lib/src/domain/repositories/tokens/ucids_tokens.json @@ -2,14 +2,13 @@ "mainnet": { "0000457EACA7FBAA96DB4A8D506A0B69684F546166FBF3C55391B1461907EFA58EAF": 1027, "00005751A05BA007E7E2518DEA171DBBD67B0527C637232F923830C39BFF9E8F159A": 20920, - "": 1 + "00002CEC79D588D5CDD24331968BEF0A9CFE8B1B03B8AEFC4454726DEF79AA10C125": 1 }, "testnet": { "00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1": 3890, "00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4": 1027, "0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827": 1839, - "00001ED63AC2850CEA282D3D0CA5047418BC2720CB49D15B611D2845611F605716A1": 20920, - "": 1 + "00001ED63AC2850CEA282D3D0CA5047418BC2720CB49D15B611D2845611F605716A1": 20920 }, "devnet": { "00001A4AB7AD0CE2B494C965C66FF2962692A5FE5ECB71B345ABB53BAD88A83A01F1": 3890, From 8c6e8d3eb5b215a4cd2c08c23159bb84d28c608f Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Wed, 14 Aug 2024 13:23:27 +0200 Subject: [PATCH 4/4] chore: :bookmark: 1.2.13 --- CHANGELOG.md | 3 +++ pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41bce7f..a0ca37f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Changelog ========= +#### Version 1.2.13 +* Add Bitcoin in ucids_tokens config file +* #### Version 1.2.12 * Update dependencies 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"