Skip to content

Commit d90cefc

Browse files
feat(frontend): Enabled networks preview icons (#5402)
# Motivation According to new Figma designs of the settings page, we need this preview icons component to preview the icons of enabled networks. # Changes Added new component # Tests +2 ![image](https://github.com/user-attachments/assets/d0517990-71d6-4f99-bf5e-09693f23aaa4) +1 ![image](https://github.com/user-attachments/assets/d4c269e0-235e-43cf-aace-2491ecb3e5f0) no additional ![image](https://github.com/user-attachments/assets/f998d41f-d289-4c02-b5fb-2e7724bb0520) Less than configured number of icons to show ![image](https://github.com/user-attachments/assets/a9d12522-59fc-4820-aba9-101c727403bb) --------- Co-authored-by: Antonio Ventilii <[email protected]>
1 parent e08e225 commit d90cefc

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script lang="ts">
2+
import { SUPPORTED_NETWORKS } from '$env/networks/networks.env';
3+
import NetworkLogo from '$lib/components/networks/NetworkLogo.svelte';
4+
import { logoSizes } from '$lib/constants/components.constants';
5+
import { userNetworks } from '$lib/derived/user-networks.derived';
6+
import type { Network, NetworkId } from '$lib/types/network';
7+
import type { UserNetworks } from '$lib/types/user-networks';
8+
9+
const numberOfIcons = 4;
10+
11+
const getEnabledList = (networks: UserNetworks): Network[] =>
12+
Object.getOwnPropertySymbols(networks ?? {}).reduce<Network[]>((enabledList, symbol) => {
13+
const isEnabled = networks[symbol as NetworkId]?.enabled ?? false;
14+
15+
if (isEnabled) {
16+
const network = SUPPORTED_NETWORKS.find((sn) => sn.id.toString() === symbol.toString());
17+
if (network) {
18+
enabledList.push(network);
19+
}
20+
}
21+
22+
return enabledList;
23+
}, []);
24+
25+
let enabledList: Network[];
26+
$: enabledList = getEnabledList($userNetworks);
27+
28+
let previewList: Network[];
29+
$: previewList = enabledList.slice(0, numberOfIcons);
30+
</script>
31+
32+
<div class="mr-2 mt-1 flex flex-row">
33+
{#each previewList as network (network.id)}
34+
<div class="-ml-1 flex">
35+
<NetworkLogo size="xxs" {network} blackAndWhite />
36+
</div>
37+
{/each}
38+
{#if enabledList.length > numberOfIcons}
39+
<div
40+
class="-ml-1 flex items-center justify-center overflow-hidden rounded-full bg-primary text-center text-xs ring-1 ring-primary transition-opacity duration-150"
41+
style={`width: ${logoSizes.xxs}; height: ${logoSizes.xxs}`}
42+
>
43+
+{enabledList.length - numberOfIcons}
44+
</div>
45+
{/if}
46+
</div>

0 commit comments

Comments
 (0)