Skip to content

Commit

Permalink
Merge pull request #4 from archethic-foundation/3-get-verified-tokens…
Browse files Browse the repository at this point in the history
…-from-blockchain

✨ Get Verified tokens from blockchain
  • Loading branch information
redDwarf03 authored Mar 20, 2024
2 parents 66b2f95 + 1c0f86a commit 5d32eca
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 126 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changelog
=========
#### Version 0.0.5
* Get Verified tokens from blockchain

#### Version 0.0.4
* Responsive: Add tools

Expand Down
2 changes: 1 addition & 1 deletion lib/src/application/ucids_tokens.g.dart

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

38 changes: 34 additions & 4 deletions lib/src/application/verified_tokens.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import 'dart:developer';

import 'package:archethic_dapp_framework_flutter/src/domain/models/verified_tokens.dart';
import 'package:archethic_dapp_framework_flutter/src/infrastructure/verified_tokens.repository.dart';
import 'package:archethic_dapp_framework_flutter/src/util/endpoint_util.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'verified_tokens.g.dart';

@Riverpod(keepAlive: true)
class _VerifiedTokensNotifier
extends Notifier<({String network, List<String> verifiedTokensList})> {
@override
({String network, List<String> verifiedTokensList}) build() {
return (network: '', verifiedTokensList: <String>[]);
}

Future<void> init() async {
await _getValue();
}

Future<void> _getValue() async {
final network = EndpointUtil.getEnvironnement();
final verifiedTokensFromNetwork = await ref
.watch(_verifiedTokensRepositoryProvider)
.getVerifiedTokensFromNetwork(network);
log('Verified tokens list ($network) $verifiedTokensFromNetwork');
state = (network: network, verifiedTokensList: verifiedTokensFromNetwork);
}
}

@Riverpod(keepAlive: true)
VerifiedTokensRepositoryImpl _verifiedTokensRepository(
_VerifiedTokensRepositoryRef ref,
Expand All @@ -22,10 +47,11 @@ Future<VerifiedTokens> _getVerifiedTokens(
@Riverpod(keepAlive: true)
Future<List<String>> _getVerifiedTokensFromNetwork(
_GetVerifiedTokensFromNetworkRef ref,
String network,
) async {
final verifiedTokensFromNetwork = await ref
.watch(_verifiedTokensRepositoryProvider)
.getVerifiedTokensFromNetwork();
.read(_verifiedTokensRepositoryProvider)
.getVerifiedTokensFromNetwork(network);
return verifiedTokensFromNetwork;
}

Expand All @@ -34,12 +60,16 @@ Future<bool> _isVerifiedToken(
_IsVerifiedTokenRef ref,
String address,
) async {
return ref.watch(_verifiedTokensRepositoryProvider).isVerifiedToken(address);
final verifiedTokens = ref.watch(_verifiedTokensNotifierProvider);
return ref
.read(_verifiedTokensRepositoryProvider)
.isVerifiedToken(address, verifiedTokens.verifiedTokensList);
}

abstract class VerifiedTokensProviders {
static final getVerifiedTokens = _getVerifiedTokensProvider;
static const isVerifiedToken = _isVerifiedTokenProvider;
static final getVerifiedTokensFromNetwork =
static const getVerifiedTokensFromNetwork =
_getVerifiedTokensFromNetworkProvider;
static final verifiedTokens = _verifiedTokensNotifierProvider;
}
173 changes: 156 additions & 17 deletions lib/src/application/verified_tokens.g.dart

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

2 changes: 0 additions & 2 deletions lib/src/domain/models/verified_tokens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ part 'verified_tokens.g.dart';
@freezed
class VerifiedTokens with _$VerifiedTokens {
const factory VerifiedTokens({
required List<String> mainnet,
required List<String> testnet,
required List<String> devnet,
}) = _VerifiedTokens;

Expand Down
Loading

0 comments on commit 5d32eca

Please sign in to comment.