Skip to content

Commit a8529ef

Browse files
authored
Only show relevant faucets (#1642)
* [faucet] only show faucets we have reputation for, or for the currently selected community. * [faucet] better variable naming * [faucet] better doc
1 parent 73b0efe commit a8529ef

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/lib/page/profile/account/account_manage_page.dart

+25-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ class _AccountManagePageState extends State<AccountManagePage> {
5252
}
5353

5454
Future<void> _init() async {
55-
faucets = await webApi.encointer.getAllFaucetsWithAccount();
55+
final allFaucets = await webApi.encointer.getAllFaucetsWithAccount();
56+
57+
// show faucets we have reputation for and faucets for `chosenCid`.
58+
final relevantCids = _appStore.encointer.account!.reputations.values.map((e) => e.communityIdentifier).toSet()
59+
..add(_appStore.encointer.chosenCid!);
60+
61+
faucets = Map.fromEntries(allFaucets.entries.where((e) {
62+
final whitelist = e.value.whitelist;
63+
if (whitelist == null) {
64+
// if the whitelist is null, all communities may access it.
65+
return true;
66+
} else {
67+
return containsAny(whitelist, relevantCids.toList());
68+
}
69+
}));
5670
setState(() {});
5771
}
5872

@@ -391,3 +405,13 @@ class CommunityIcon extends StatelessWidget {
391405
);
392406
}
393407
}
408+
409+
/// Checks if any entry in list one is contained in another list.
410+
bool containsAny(List<dynamic> list1, List<dynamic> list2) {
411+
for (final entry in list1) {
412+
if (list2.contains(entry)) {
413+
return true;
414+
}
415+
}
416+
return false;
417+
}

0 commit comments

Comments
 (0)