Skip to content

Commit

Permalink
fix: seed vault notification stream, account filter for parsed seeds (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhbrunetto authored Mar 2, 2023
1 parent 907c690 commit 733c588
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions packages/solana_seed_vault/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ import 'package:solana_seed_vault/src/seed_vault.dart';
import 'package:solana_seed_vault/src/wallet_contract_v1.dart';

extension SeedVaultHelperExt on SeedVault {
Future<List<Seed>> getParsedAuthorizedSeeds() async {
Future<List<Seed>> getParsedAuthorizedSeeds({
AccountFilter accountFilter = const AccountFilter(),
}) async {
final result = await getAuthorizedSeeds();

return result.map((it) => it.cursorToSeed(this)).let(Future.wait);
return result
.map((it) => it.cursorToSeed(this, accountFilter))
.let(Future.wait);
}

Future<Seed> getParsedAuthorizedSeed(AuthToken authToken) =>
Future<Seed> getParsedAuthorizedSeed(
AuthToken authToken, {
AccountFilter accountFilter = const AccountFilter(),
}) =>
getAuthorizedSeed(authToken: authToken)
.letAsync((it) => it.cursorToSeed(this));
.letAsync((it) => it.cursorToSeed(this, accountFilter));

Future<List<Account>> getParsedAccounts(
AuthToken authToken, {
Expand All @@ -46,13 +53,13 @@ extension SeedVaultHelperExt on SeedVault {
}

extension CursorToModelExt on CursorData {
Future<Seed> cursorToSeed(SeedVault seedVault) async {
Future<Seed> cursorToSeed(SeedVault seedVault, AccountFilter filter) async {
final authToken = this[WalletContractV1.authorizedSeedsAuthToken] as int;
final name = this[WalletContractV1.authorizedSeedsSeedName] as String;
final purpose = this[WalletContractV1.authorizedSeedsAuthPurpose] as int;
final accounts = await seedVault.getParsedAccounts(
authToken,
filter: const AccountFilter.byIsUserWallet(true),
filter: filter,
);

return Seed(
Expand Down
2 changes: 1 addition & 1 deletion packages/solana_seed_vault/lib/src/seed_vault.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SeedVault implements SeedVaultFlutterApi {
@visibleForTesting
static set instance(SeedVault vault) => _instance = vault;

final _eventStream = StreamController<SeedVaultNotification>();
final _eventStream = StreamController<SeedVaultNotification>.broadcast();

@override
void onChangeNotified(List<String?> uris, int flags) {
Expand Down

0 comments on commit 733c588

Please sign in to comment.