2022-12-13 12:21:16 +00:00
|
|
|
import { Dispatch, FunctionComponent, SetStateAction, useEffect } from "react";
|
2022-12-18 12:01:34 +00:00
|
|
|
import { ChainItemType, DisabledChainItemType } from "../../types";
|
2022-12-09 11:59:52 +00:00
|
|
|
import color from "../../styles/color";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import { ChainItem } from "./chain-item";
|
|
|
|
|
|
|
|
interface Props {
|
2022-12-12 13:45:24 +00:00
|
|
|
chainList: ChainItemType[];
|
2022-12-18 12:01:34 +00:00
|
|
|
disabledChainList: DisabledChainItemType[];
|
2022-12-13 12:21:16 +00:00
|
|
|
checkedItems: Set<unknown>;
|
|
|
|
setCheckedItems: Dispatch<SetStateAction<Set<unknown>>>;
|
2022-12-09 11:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ChainList: FunctionComponent<Props> = (props) => {
|
2022-12-17 13:10:38 +00:00
|
|
|
const { chainList, disabledChainList, checkedItems, setCheckedItems } = props;
|
2022-12-12 13:45:24 +00:00
|
|
|
|
|
|
|
const checkedItemHandler = (chainItem: ChainItemType, isChecked: boolean) => {
|
|
|
|
const tempSet = new Set(checkedItems);
|
|
|
|
|
|
|
|
if (isChecked) {
|
|
|
|
tempSet.add(chainItem);
|
|
|
|
} else if (!isChecked && checkedItems.has(chainItem)) {
|
|
|
|
tempSet.delete(chainItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
setCheckedItems(tempSet);
|
|
|
|
};
|
|
|
|
|
2022-12-09 11:59:52 +00:00
|
|
|
return (
|
2022-12-15 15:43:18 +00:00
|
|
|
<ChainContainer color={color.grey["900"]}>
|
2022-12-12 13:45:24 +00:00
|
|
|
{chainList.map((chainItem) => (
|
|
|
|
<ChainItem
|
2022-12-18 12:09:34 +00:00
|
|
|
key={chainItem.chainId}
|
2022-12-12 13:45:24 +00:00
|
|
|
chainItem={chainItem}
|
|
|
|
checkedItemHandler={checkedItemHandler}
|
2022-12-13 12:21:16 +00:00
|
|
|
checkedItems={checkedItems}
|
2022-12-12 13:45:24 +00:00
|
|
|
/>
|
2022-12-09 11:59:52 +00:00
|
|
|
))}
|
2022-12-15 10:06:44 +00:00
|
|
|
{disabledChainList.map((chainItem) => (
|
|
|
|
<ChainItem
|
2022-12-18 12:09:34 +00:00
|
|
|
key={chainItem.chainId}
|
2022-12-15 10:06:44 +00:00
|
|
|
chainItem={chainItem}
|
|
|
|
checkedItemHandler={checkedItemHandler}
|
|
|
|
checkedItems={checkedItems}
|
|
|
|
/>
|
|
|
|
))}
|
2022-12-09 11:59:52 +00:00
|
|
|
</ChainContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ChainContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
width: 100%;
|
2022-12-15 15:43:18 +00:00
|
|
|
//max-height: 33rem;
|
2022-12-18 15:49:45 +00:00
|
|
|
overflow-y: scroll;
|
2022-12-09 11:59:52 +00:00
|
|
|
|
2022-12-15 15:43:18 +00:00
|
|
|
flex: 1;
|
|
|
|
|
2022-12-09 11:59:52 +00:00
|
|
|
background-color: ${(props) => props.color};
|
|
|
|
`;
|