|
| 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