Skip to content

Commit

Permalink
fix: 🐛 Fix Tokens data refresh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chralu committed Aug 22, 2024
1 parent b9050af commit 66b542f
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 289 deletions.
14 changes: 5 additions & 9 deletions lib/src/application/ae_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'ae_token.g.dart';

@riverpod
double _estimateTokenInFiat(
Future<double> _estimateTokenInFiat(
_EstimateTokenInFiatRef ref,
AEToken token,
) {
var fiatValue = 0.0;
) async {
if (token.symbol == 'UCO') {
final archethicOracleUCO =
ref.watch(aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO);

fiatValue = archethicOracleUCO.usd;
return archethicOracleUCO.usd;
} else {
final price = ref.watch(
aedappfm.CoinPriceProviders.coinPriceFromAddress(token.address!),
return await ref.watch(
aedappfm.CoinPriceProviders.coinPrice(address: token.address!).future,
);

fiatValue = price;
}
return fiatValue;
}

abstract class AETokensProviders {
Expand Down
15 changes: 8 additions & 7 deletions lib/src/application/ae_token.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions lib/src/application/coin_price.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:async';

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/infrastructure/coin_price.repository.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'coin_price.g.dart';

@Riverpod(keepAlive: true)
class _CoinPriceNotifier extends Notifier<CryptoPrice> {
class _CoinPricesNotifier extends Notifier<CryptoPrice> {
Timer? _timer;

@override
Expand Down Expand Up @@ -39,22 +37,27 @@ CoinPriceRepositoryImpl _coinPriceRepository(
CoinPriceRepositoryImpl();

@riverpod
double _coinPriceFromAddress(
_CoinPriceFromAddressRef ref,
String address,
) {
final coinPrice = ref.read(
CoinPriceProviders.coinPrice,
Future<double> _coinPrice(
_CoinPriceRef ref, {
required String address,
String? network,
}) async {
final coinPrice = ref.watch(
CoinPriceProviders.coinPrices,
);
final ucid = await ref.watch(
UcidsTokensProviders.ucid(
address: address.toUpperCase(),
network: network,
).future,
);
final ucidsList = ref.read(UcidsTokensProviders.ucidsTokens);
final ucid = ucidsList[address.toUpperCase()] ?? 0;

return ref
.read(_coinPriceRepositoryProvider)
.getPriceFromUcid(ucid, coinPrice);
}

abstract class CoinPriceProviders {
static final coinPrice = _coinPriceNotifierProvider;
static const coinPriceFromAddress = _coinPriceFromAddressProvider;
static final coinPrices = _coinPricesNotifierProvider;
static const coinPrice = _coinPriceProvider;
}
129 changes: 73 additions & 56 deletions lib/src/application/coin_price.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 66b542f

Please sign in to comment.